Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,3 +1,95 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen2.5-7B-Instruct
|
| 4 |
+
tags:
|
| 5 |
+
- text-to-cad
|
| 6 |
+
- code-generation
|
| 7 |
+
- cadquery
|
| 8 |
+
- 3d-modeling
|
| 9 |
+
- reinforcement-learning
|
| 10 |
+
language:
|
| 11 |
+
- en
|
| 12 |
+
pipeline_tag: text-generation
|
| 13 |
+
library_name: transformers
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# CAD-Coder
|
| 17 |
+
|
| 18 |
+
**CAD-Coder: Text-to-CAD Generation with Chain-of-Thought and Geometric Reward**
|
| 19 |
+
|
| 20 |
+
This is the reinforcement learning (GRPO) fine-tuned model for generating CadQuery code from natural language descriptions.
|
| 21 |
+
|
| 22 |
+
## Model Description
|
| 23 |
+
|
| 24 |
+
CAD-Coder reformulates text-to-CAD as the generation of CadQuery scripts—a Python-based, parametric CAD language. The model is trained with a two-stage pipeline:
|
| 25 |
+
|
| 26 |
+
1. **Supervised Fine-Tuning (SFT)**: Learning CadQuery syntax and text-to-code mapping
|
| 27 |
+
2. **Reinforcement Learning (GRPO)**: Optimizing geometric accuracy with CAD-specific rewards (Chamfer Distance + Format Reward)
|
| 28 |
+
|
| 29 |
+
### Key Features
|
| 30 |
+
|
| 31 |
+
- Generates executable CadQuery Python code from natural language
|
| 32 |
+
- Chain-of-Thought (CoT) reasoning for complex CAD structures
|
| 33 |
+
- Geometric reward optimization for accurate 3D model generation
|
| 34 |
+
- Supports diverse CAD operations beyond simple sketch-extrusion
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 40 |
+
|
| 41 |
+
model_name = "gudo7208/CAD-Coder"
|
| 42 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 43 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
|
| 44 |
+
|
| 45 |
+
# Example prompt
|
| 46 |
+
prompt = """Create a cylinder with radius 10mm and height 20mm, with a central hole of radius 5mm."""
|
| 47 |
+
|
| 48 |
+
messages = [
|
| 49 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 50 |
+
{"role": "user", "content": prompt}
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 54 |
+
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 55 |
+
|
| 56 |
+
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, top_p=0.8, top_k=20)
|
| 57 |
+
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 58 |
+
print(response)
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## Performance
|
| 62 |
+
|
| 63 |
+
| Method | Mean CD | Median CD | IR% |
|
| 64 |
+
|--------|---------|-----------|-----|
|
| 65 |
+
| Text2CAD | 29.29 | 0.37 | 3.75 |
|
| 66 |
+
| **CAD-Coder (Ours)** | **6.54** | **0.17** | **1.45** |
|
| 67 |
+
|
| 68 |
+
*CD metrics are ×10³. Lower is better.*
|
| 69 |
+
|
| 70 |
+
## Training Details
|
| 71 |
+
|
| 72 |
+
- **Base Model**: Qwen2.5-7B-Instruct
|
| 73 |
+
- **Training Data**: 110K text-CadQuery-3D model triplets + 1.5K CoT samples
|
| 74 |
+
- **Hardware**: 8× NVIDIA A800 80GB GPUs
|
| 75 |
+
- **Framework**: Hugging Face Transformers, DeepSpeed, Verl (GRPO)
|
| 76 |
+
|
| 77 |
+
## Citation
|
| 78 |
+
|
| 79 |
+
```bibtex
|
| 80 |
+
@article{guan2025cadcoder,
|
| 81 |
+
title={CAD-Coder: Text-to-CAD Generation with Chain-of-Thought and Geometric Reward},
|
| 82 |
+
author={Guan, Yandong and Wang, Xilin and Xing, Ximing and Zhang, Jing and Xu, Dong and Yu, Qian},
|
| 83 |
+
journal={arXiv preprint arXiv:2505.19713},
|
| 84 |
+
year={2025}
|
| 85 |
+
}
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## License
|
| 89 |
+
|
| 90 |
+
This model is released under the Apache 2.0 License, following the base model (Qwen2.5-7B-Instruct) license terms.
|
| 91 |
+
|
| 92 |
+
## Acknowledgements
|
| 93 |
+
|
| 94 |
+
- Base model: [Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct)
|
| 95 |
+
- Training data derived from [Text2CAD](https://github.com/sadilkhan/Text2CAD) dataset
|