File size: 10,931 Bytes
bbc5fa5 0c3d85d bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 0c3d85d bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 0c3d85d bbc5fa5 6ffb5b8 bbc5fa5 6ffb5b8 bbc5fa5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
---
license: mit
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
tags:
- text-to-cad
- cad
- 3d-modeling
- parametric
- lora
- qwen2
language:
- en
library_name: transformers
pipeline_tag: text-generation
---
# cad0
**cad0** is a fine-tuned language model for text-to-CAD generation. Given a natural
language description of a mechanical part, it generates [Compact
IR](https://github.com/ecto/vcad) β a token-efficient domain-specific
language for parametric 3D geometry.
## Demo
Try it: [**cad0-demo on HuggingFace
Spaces**](https://huggingface.co/spaces/campedersen/cad0-demo)
For browser/offline use:
[**cad0-mini**](https://huggingface.co/campedersen/cad0-mini) (0.5B, ONNX quantized)
## What It Does
```
Input: "50x30mm mounting plate with 4 corner holes"
Output: C 50 30 5
Y 2.5 10
T 1 5 5 0
D 0 2
...
```
The Compact IR output can be parsed and evaluated by the [vcad
kernel](https://github.com/ecto/vcad) to produce editable parametric
geometry.
## Supported Part Types
| Family | Examples |
|--------|----------|
| Bracket | L-brackets, Z-brackets, mounting plates |
| Standoff | Cylindrical spacers, threaded standoffs |
| Enclosure | Boxes, vented enclosures, rounded shells |
| Gear | Spur gears, hubs |
| Flange | Bolt circles, blind flanges |
| Clip | Snap clips, spring clips |
## Usage
### With Transformers + PEFT
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-Coder-7B-Instruct",
torch_dtype="auto",
device_map="auto"
)
model = PeftModel.from_pretrained(base_model, "campedersen/cad0")
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct")
prompt = "50x30mm mounting plate with 4 corner holes"
messages = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(messages, tokenize=False,
add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.1,
do_sample=True)
ir = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:],
skip_special_tokens=True)
print(ir)
```
### API Endpoint
```
curl -X POST https://ecto--cad0-training-inference-infer.modal.run \
-H "Content-Type: application/json" \
-d '{"prompt": "L-bracket with mounting holes", "temperature": 0.1}'
```
## Compact IR Reference
```
ββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β Op β Syntax β Description β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Cube β C x y z β Box with dimensions x, y, z (mm) β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Cylinder β Y r h β Cylinder with radius r, height h β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Sphere β S r β Sphere with radius r β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Cone β K r1 r2 h β Cone/frustum β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Translate β T n x y z β Move node n by offset β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Rotate β R n rx ry rz β Rotate node n (degrees) β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Scale β X n sx sy sz β Scale node n β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Union β U a b β Boolean union β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Difference β D a b β Boolean subtraction β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Intersection β I a b β Boolean intersection β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Shell β SH n t β Hollow out with wall thickness t β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Fillet β F n r β Round edges with radius r β
ββββββββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββββββββ€
β Chamfer β CH n d β Bevel edges with distance d β
ββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββββββββββββββββββββββ
```
Nodes are 0-indexed; each line creates a new node.
## Training
```
βββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β Parameter β Value β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Base model β Qwen2.5-Coder-7B-Instruct β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Method β QLoRA (4-bit NF4) β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β LoRA rank β 64 β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β LoRA alpha β 128 β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Training examples β 530,531 β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Epochs β 1 β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Batch size β 64 (effective) β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Learning rate β 2e-4 (cosine) β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Hardware β 1x NVIDIA H100 80GB β
βββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Training time β 9h 15m β
βββββββββββββββββββββ΄ββββββββββββββββββββββββββββ
```
## Evaluation
```
ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β Metric β Value β
ββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Final eval loss β 0.324 β
ββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β In-distribution accuracy β 75% β
ββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββ€
β Out-of-distribution β Limited (see Limitations) β
ββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββ
```
## Limitations
- Training bias: May add features (holes, fillets) to simple primitives β training
data weighted toward complex manufactured parts
- Dimension ambiguity: Occasionally confuses radius vs diameter for cylinders
- Limited primitives: No native hexagon support; hex shapes require boolean
workarounds
- OOD generalization: Struggles with part types not in training distribution
## Related
- https://github.com/ecto/vcad β Open-source parametric CAD with custom BRep
kernel
- https://vcad.io β Web app with cad0 integration
- https://huggingface.co/campedersen/cad0-mini β 0.5B distilled model for browser
inference
## Citation
@misc{cad0,
author = {Cam Pedersen},
title = {cad0: Text-to-CAD Language Model},
year = {2026},
publisher = {HuggingFace},
url = {https://huggingface.co/campedersen/cad0}
}
## License
MIT
|