Text Generation
Transformers
Safetensors
English
qwen2
text-to-cad
code-generation
cadquery
3d-modeling
reinforcement-learning
conversational
text-generation-inference
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", device_map="auto") 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 Settings
- 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
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -17,7 +17,7 @@ library_name: transformers
|
|
| 17 |
|
| 18 |
**CAD-Coder: Text-to-CAD Generation with Chain-of-Thought and Geometric Reward**
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
## Model Description
|
| 23 |
|
|
@@ -31,9 +31,21 @@ CAD-Coder reformulates text-to-CAD as the generation of CadQuery scripts—a Pyt
|
|
| 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 |
|
| 35 |
## Usage
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
```python
|
| 38 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 39 |
|
|
@@ -41,20 +53,16 @@ model_name = "gudo7208/CAD-Coder"
|
|
| 41 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 42 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
|
| 43 |
|
| 44 |
-
|
| 45 |
-
prompt = """Create a cylinder with radius 10mm and height 20mm, with a central hole of radius 5mm."""
|
| 46 |
-
|
| 47 |
-
messages = [
|
| 48 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
| 49 |
-
{"role": "user", "content": prompt}
|
| 50 |
-
]
|
| 51 |
|
| 52 |
-
text = tokenizer.apply_chat_template(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 57 |
-
print(response)
|
| 58 |
```
|
| 59 |
|
| 60 |
## Performance
|
|
@@ -90,8 +98,5 @@ This model is released under the Apache 2.0 License, following the base model (Q
|
|
| 90 |
|
| 91 |
## Acknowledgements
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
- [Qwen2.5](https://github.com/QwenLM/Qwen2.5) - Base model for CAD-Coder
|
| 96 |
-
- [Text2CAD](https://github.com/sadilkhan/Text2CAD) - Text-to-CAD dataset and benchmark
|
| 97 |
-
- [DeepCAD](https://github.com/ChrisWu1997/DeepCAD) - Pioneering work on deep generative models for CAD
|
|
|
|
| 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 |
|
|
|
|
| 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 |
+
For complete inference scripts, please visit our [GitHub repository](https://github.com/gudo7208/CAD-Coder).
|
| 39 |
+
|
| 40 |
+
### Installation
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
pip install transformers
|
| 44 |
+
pip install "numpy<2.0" cadquery==2.3.1 # Optional: for code execution
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### Quick Start
|
| 48 |
+
|
| 49 |
```python
|
| 50 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 51 |
|
|
|
|
| 53 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 54 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
|
| 55 |
|
| 56 |
+
prompt = "Create a cylinder with radius 10mm and height 20mm, with a central hole of radius 5mm."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
text = tokenizer.apply_chat_template(
|
| 59 |
+
[{"role": "user", "content": prompt}],
|
| 60 |
+
tokenize=False,
|
| 61 |
+
add_generation_prompt=True
|
| 62 |
+
)
|
| 63 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 64 |
+
outputs = model.generate(**inputs, max_new_tokens=2048)
|
| 65 |
+
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
|
|
|
|
|
|
| 66 |
```
|
| 67 |
|
| 68 |
## Performance
|
|
|
|
| 98 |
|
| 99 |
## Acknowledgements
|
| 100 |
|
| 101 |
+
- Base model: [Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct)
|
| 102 |
+
- Training data derived from [Text2CAD](https://github.com/sadilkhan/Text2CAD) dataset
|
|
|
|
|
|
|
|
|