Instructions to use gudo7208/CAD-Coder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gudo7208/CAD-Coder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="gudo7208/CAD-Coder") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("gudo7208/CAD-Coder") model = AutoModelForCausalLM.from_pretrained("gudo7208/CAD-Coder") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use gudo7208/CAD-Coder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "gudo7208/CAD-Coder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gudo7208/CAD-Coder", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/gudo7208/CAD-Coder
- SGLang
How to use gudo7208/CAD-Coder with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "gudo7208/CAD-Coder" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gudo7208/CAD-Coder", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "gudo7208/CAD-Coder" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gudo7208/CAD-Coder", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use gudo7208/CAD-Coder with Docker Model Runner:
docker model run hf.co/gudo7208/CAD-Coder
CAD-Coder
CAD-Coder: Text-to-CAD Generation with Chain-of-Thought and Geometric Reward
Accepted at NeurIPS 2025 (Poster)
This is the reinforcement learning (GRPO) fine-tuned model for generating CadQuery code from natural language descriptions.
Model Description
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:
- Supervised Fine-Tuning (SFT): Learning CadQuery syntax and text-to-code mapping
- Reinforcement Learning (GRPO): Optimizing geometric accuracy with CAD-specific rewards (Chamfer Distance + Format Reward)
Key Features
- Generates executable CadQuery Python code from natural language
- Chain-of-Thought (CoT) reasoning for complex CAD structures
- Geometric reward optimization for accurate 3D model generation
- Supports diverse CAD operations beyond simple sketch-extrusion
Usage
For complete inference scripts, please visit our GitHub repository.
Installation
pip install transformers
pip install "numpy<2.0" cadquery==2.3.1 # Optional: for code execution
Quick Start
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "gudo7208/CAD-Coder"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
prompt = "Create a cylinder with radius 10mm and height 20mm, with a central hole of radius 5mm."
text = tokenizer.apply_chat_template(
[{"role": "user", "content": prompt}],
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer([text], return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=2048)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
Performance
| Method | Mean CD | Median CD | IR% |
|---|---|---|---|
| Text2CAD | 29.29 | 0.37 | 3.75 |
| CAD-Coder (Ours) | 6.54 | 0.17 | 1.45 |
CD metrics are ×10³. Lower is better.
Training Details
- Base Model: Qwen2.5-7B-Instruct
- Training Data: 110K text-CadQuery-3D model triplets + 1.5K CoT samples
- Hardware: 8× NVIDIA A800 80GB GPUs
- Framework: Hugging Face Transformers, DeepSpeed, Verl (GRPO)
Citation
@article{guan2025cadcoder,
title={CAD-Coder: Text-to-CAD Generation with Chain-of-Thought and Geometric Reward},
author={Guan, Yandong and Wang, Xilin and Xing, Ximing and Zhang, Jing and Xu, Dong and Yu, Qian},
journal={arXiv preprint arXiv:2505.19713},
year={2025}
}
License
This model is released under the Apache 2.0 License, following the base model (Qwen2.5-7B-Instruct) license terms.
Acknowledgements
- Base model: Qwen2.5-7B-Instruct
- Training data derived from Text2CAD dataset
- Downloads last month
- 613