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
Update README.md
Browse files
README.md
CHANGED
|
@@ -57,7 +57,7 @@ model_path = "gudo7208/CAD-Coder"
|
|
| 57 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 58 |
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
|
| 59 |
|
| 60 |
-
#
|
| 61 |
prompt = """Please create a CadQuery Python code to generate a model based on the following description. The reasoning process MUST BE enclosed within <think> </think> tags. The final CadQuery code MUST BE put in \\boxed{```python
|
| 62 |
code
|
| 63 |
```} with ONLY the executable code inside the box, nothing else.The final model is represented by r.
|
|
@@ -98,40 +98,6 @@ Think step by step, but only keep a minimum draft for each thinking step, with 5
|
|
| 98 |
description:
|
| 99 |
Start by creating a new coordinate system with Euler angles set to zero and a translation vector also set to zero. Next, draw a two-dimensional sketch on the first face. This sketch consists of a single loop made up of four lines. The first line starts at the origin (0.0, 0.0) and ends at (0.6, 0.0). The second line starts at (0.6, 0.0) and ends at (0.6, 0.375). The third line starts at (0.6, 0.375) and ends at (0.0, 0.375). Finally, the fourth line completes the loop by starting at (0.0, 0.375) and ending at the origin (0.0, 0.0). After drawing the sketch, apply a scale factor of 0.6 to the entire sketch. To transform the scaled two-dimensional sketch into a three-dimensional model, extrude the sketch 0.075 units along the normal direction. The final dimensions of the rectangular block are a length of 0.6 units, a width of 0.375 units, and a height of 0.075 units."""
|
| 100 |
|
| 101 |
-
|
| 102 |
-
def extract_code(response):
|
| 103 |
-
"""Extract Python code from response"""
|
| 104 |
-
# Try \boxed{```python ... ```}
|
| 105 |
-
match = re.search(r'\\boxed\{```python\n(.*?)```\}', response, re.DOTALL)
|
| 106 |
-
if match:
|
| 107 |
-
return match.group(1).strip()
|
| 108 |
-
# Try ```python ... ```
|
| 109 |
-
match = re.search(r'```python\n(.*?)```', response, re.DOTALL)
|
| 110 |
-
if match:
|
| 111 |
-
return match.group(1).strip()
|
| 112 |
-
return response
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
def execute_code(code, output_path="output.py"):
|
| 116 |
-
"""Save and execute CadQuery code"""
|
| 117 |
-
with open(output_path, "w", encoding="utf-8") as f:
|
| 118 |
-
f.write(code)
|
| 119 |
-
print(f"Code saved to {output_path}")
|
| 120 |
-
|
| 121 |
-
try:
|
| 122 |
-
exec_globals = {}
|
| 123 |
-
exec(code, exec_globals)
|
| 124 |
-
if 'r' in exec_globals:
|
| 125 |
-
print("Execution SUCCESS! Model 'r' created.")
|
| 126 |
-
return True, exec_globals['r']
|
| 127 |
-
else:
|
| 128 |
-
print("Execution completed but 'r' not found.")
|
| 129 |
-
return False, None
|
| 130 |
-
except Exception as e:
|
| 131 |
-
print(f"Execution FAILED: {e}")
|
| 132 |
-
return False, None
|
| 133 |
-
|
| 134 |
-
|
| 135 |
# Generate
|
| 136 |
text = tokenizer.apply_chat_template(
|
| 137 |
[{"role": "user", "content": prompt}],
|
|
@@ -141,23 +107,7 @@ text = tokenizer.apply_chat_template(
|
|
| 141 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 142 |
outputs = model.generate(**inputs, max_new_tokens=2048)
|
| 143 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 144 |
-
|
| 145 |
-
print("=" * 50)
|
| 146 |
-
print("Model Response:")
|
| 147 |
-
print("=" * 50)
|
| 148 |
print(response)
|
| 149 |
-
|
| 150 |
-
# Extract and execute
|
| 151 |
-
print("\n" + "=" * 50)
|
| 152 |
-
print("Extracted Code:")
|
| 153 |
-
print("=" * 50)
|
| 154 |
-
code = extract_code(response)
|
| 155 |
-
print(code)
|
| 156 |
-
|
| 157 |
-
print("\n" + "=" * 50)
|
| 158 |
-
print("Execution Result:")
|
| 159 |
-
print("=" * 50)
|
| 160 |
-
success, result = execute_code(code)
|
| 161 |
```
|
| 162 |
|
| 163 |
## Performance
|
|
|
|
| 57 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 58 |
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
|
| 59 |
|
| 60 |
+
# Test data (from the first record in cad_data_test_cot.json)
|
| 61 |
prompt = """Please create a CadQuery Python code to generate a model based on the following description. The reasoning process MUST BE enclosed within <think> </think> tags. The final CadQuery code MUST BE put in \\boxed{```python
|
| 62 |
code
|
| 63 |
```} with ONLY the executable code inside the box, nothing else.The final model is represented by r.
|
|
|
|
| 98 |
description:
|
| 99 |
Start by creating a new coordinate system with Euler angles set to zero and a translation vector also set to zero. Next, draw a two-dimensional sketch on the first face. This sketch consists of a single loop made up of four lines. The first line starts at the origin (0.0, 0.0) and ends at (0.6, 0.0). The second line starts at (0.6, 0.0) and ends at (0.6, 0.375). The third line starts at (0.6, 0.375) and ends at (0.0, 0.375). Finally, the fourth line completes the loop by starting at (0.0, 0.375) and ending at the origin (0.0, 0.0). After drawing the sketch, apply a scale factor of 0.6 to the entire sketch. To transform the scaled two-dimensional sketch into a three-dimensional model, extrude the sketch 0.075 units along the normal direction. The final dimensions of the rectangular block are a length of 0.6 units, a width of 0.375 units, and a height of 0.075 units."""
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
# Generate
|
| 102 |
text = tokenizer.apply_chat_template(
|
| 103 |
[{"role": "user", "content": prompt}],
|
|
|
|
| 107 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 108 |
outputs = model.generate(**inputs, max_new_tokens=2048)
|
| 109 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
print(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
```
|
| 112 |
|
| 113 |
## Performance
|