Fine-tuning
CAD-LLM
A study and proof of concept: natural-language design intent goes in, a compact bracketed CAD language comes out, and FreeCAD checks that it actually builds.
The idea
Instead of asking a model to write long Python or STEP files, we give it a small, dense vocabulary of CAD tokens. Short sequences let the model pay attention to structure. A Python driver then turns the token stream into FreeCAD calls.
[CAD_START] [RECT] [W] [MM_50] [H] [MM_40] [EXTRUDE] [MM_10] [CAD_END]
A 50 × 40 mm rectangular plate, extruded 10 mm.
Locked decisions
- Output
- A custom CAD language, validated by executing it in FreeCAD.
- Dimensions
- Discrete millimetre tokens from 5 to 100 mm in 5 mm steps. No raw digits.
- First family
- Family A: a rectangular plate with a single extrude; thickness 5, 10, 15 or 20 mm.
- Approach
- Vocabulary extension and supervised fine-tuning. No retrieval (RAG).
How it is trained
- Data. A synthetic generator covers the full Family A lattice (20 × 20 × 4 = 1,600 shapes) with 12 English paraphrases each, 19,200 prompt and completion pairs, valid by construction.
- Model. Qwen2.5-Coder-7B-Instruct by default, from the 7B–8B Instruct class.
- QLoRA. The base model is frozen and quantised to 4-bit; LoRA adapters sit on the attention projections, and the embeddings and output head are trained fully so the new CAD tokens can be learned.
- SFT. Hugging Face
transformers,peftandtrl's SFTTrainer, with the prompt masked so the loss is on the CAD tokens. - $0 compute first. CPU dry-runs on a laptop, then a free Kaggle T4 × 2 preset for the QLoRA run.
How it is measured
The key metric is execution success: does the output parse, and does it build a solid in FreeCAD? A curated 40-row held-out set uses wording that never appears in the training data. The evaluation code never loads a model; predictions are dumped separately and then scored.
TODO: content from Sam — held-out results after training. No results are published here until they are measured.