numinousmuses commited on
Commit
f652a35
·
verified ·
1 Parent(s): 46dc086

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +126 -130
README.md CHANGED
@@ -1,184 +1,180 @@
1
- ---
2
- base_model: unsloth/gemma-3n-e4b-it-unsloth-bnb-4bit
3
- tags:
4
- - text-generation-inference
5
- - transformers
6
- - unsloth
7
- - gemma3n
8
- - trl
9
- license: apache-2.0
10
- language:
11
- - en
12
- ---
13
-
14
- # C3D-v0: Text-to-CadQuery Model
15
 
16
- A fine-tuned Gemma3N model that generates Python CadQuery scripts from natural-language descriptions. C3D-v0 enables you to go from “a simple gear with 12 teeth” to runnable CadQuery code in one prompt.
17
-
18
- ---
19
 
20
  ## Model Description
21
 
22
- C3D-v0 is built on top of the **unsloth/gemma-3n-E4B-it** base model and fine-tuned on the [Text-to-CadQuery dataset](https://github.com/Text-to-CadQuery/Text-to-CadQuery) using LoRA. It excels at translating high-level CAD intents into valid CadQuery Python scripts.
23
-
24
- * **Base model**: `unsloth/gemma-3n-E4B-it`
25
- * **Fine-tuning method**: LoRA via Unsloth + Hugging Face `SFTTrainer`
26
- * **Training data**: \~48 000 prompt–script pairs (50 % of Text-to-CadQuery train split)
27
- * **Chat template**: `"gemma-3"` instruction/completion style
28
- * **Context window**: up to 32 k tokens
29
 
30
- ---
31
 
32
- ## Usage
33
 
34
- ### Installation
 
 
 
 
35
 
36
- ```bash
37
- # If you’re using Hugging Face Transformers
38
- pip install transformers accelerate
39
 
40
- # If you want Ollama integration
41
- brew install ollama
42
- ollama pull numinousmuses/C3D-v0
43
- ```
44
 
45
- ### Inference (Transformers)
 
 
 
46
 
47
- ```python
48
- from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
 
 
 
 
49
 
50
- model_id = "numinousmuses/C3D-v0"
51
- tokenizer = AutoTokenizer.from_pretrained(model_id)
52
- model = AutoModelForCausalLM.from_pretrained(model_id)
53
 
54
- prompt = "Generate a simple cube in CadQuery."
55
 
56
- # Prepare input using the same chat template
57
- inputs = tokenizer(
58
- f"<start_of_turn>user\n{prompt}",
59
- return_tensors="pt"
60
- )
61
 
62
- # Streamed generation
63
- streamer = TextStreamer(tokenizer, skip_prompt=True)
64
- model.generate(
65
- **inputs,
66
- max_new_tokens=512,
67
- temperature=0.7,
68
- top_p=0.9,
69
- streamer=streamer
70
- )
71
  ```
72
 
73
- ### Inference (Pipeline)
74
 
75
- ```python
76
- from transformers import pipeline
 
77
 
78
- generator = pipeline(
79
- "text-generation",
80
- model="numinousmuses/C3D-v0",
81
- tokenizer="numinousmuses/C3D-v0",
82
- device=0 # set to GPU if available
83
- )
84
 
85
- cad_script = generator(
86
- "Generate a parametric bracket with two mounting holes.",
87
- max_new_tokens=400,
88
- temperature=0.8,
89
- top_p=0.95
90
- )[0]["generated_text"]
91
 
92
- print(cad_script)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  ```
94
 
95
- ### Inference (Ollama)
96
 
97
- ```bash
98
- # Start Ollama daemon if not running
99
- ollama serve &
100
 
101
- # Run a chat prompt
102
- ollama chat numinousmuses/C3D-v0 \
103
- --prompt "Generate a hollow cylinder with radius=5, height=10."
 
 
104
  ```
105
 
106
- ---
107
 
108
- ## Example
 
 
 
109
 
110
- ```bash
111
- $ c3d generate "a gear with 12 teeth, outer diameter 50mm, thickness 5mm"
112
- ```
113
 
114
- **Output snippet:**
115
 
 
116
  ```python
117
- from cadquery import Workplane
118
-
119
- # Parameters
120
- num_teeth = 12
121
- outer_dia = 50
122
- tooth_angle = 360 / num_teeth
123
- thickness = 5
124
 
 
125
  gear = (
126
- Workplane("XY")
127
- .circle(outer_dia / 2)
128
- .extrude(thickness)
129
- .faces(">Z")
130
- .workplane()
131
- .polarArray(0, 0, outer_dia / 2 - 2, num_teeth)
132
- .circle(2)
133
- .cutThruAll()
134
  )
135
- gear.val().exportStl("gear.stl")
136
- ```
137
 
138
- ---
139
-
140
- ## Training Details
141
-
142
- * **Trainer**: `trl.SFTTrainer` with 4 bit base + LoRA adapters
143
- * **Batch size**: 2 per device, gradient accumulation 4 (effective 8)
144
- * **Epochs**: 1 (due to resource limits)
145
- * **Learning rate**: 2 × 10⁻⁴ with linear scheduler and 5 warmup steps
146
- * **Checkpoints** saved every 1 000 steps; max 2 retained
147
- * **NaNGuard & TimeLimitCallback** to ensure stability & limit 11 h runtime
148
-
149
- ---
 
150
 
151
  ## Limitations
152
 
153
- * May occasionally produce scripts with minor syntax errors—verify before rendering.
154
- * Lacks vision input support (text-only).
155
- * Trained on a subset of examples; complex assemblies may require manual edits.
156
-
157
- ---
158
 
159
  ## Roadmap
160
 
161
- 1. **Full-dataset fine-tuning** (all \~99 000 examples).
162
- 2. **Multimodal support** (image 3D model).
163
- 3. **Iterative verify-and-refine loop** with automatic render feedback.
 
164
 
165
- ---
166
 
167
- ## Citation
 
 
 
168
 
169
- If you use C3D-v0 in your work, please cite:
170
 
171
  ```bibtex
172
- @misc{Okolo2025C3Dv0,
173
- title = {C3D-v0: Text-to-CadQuery AI Model},
174
- author = {Okolo, Joshua},
175
- year = {2025},
176
- howpublished = {\url{https://huggingface.co/numinousmuses/C3D-v0}},
177
  }
178
  ```
179
 
180
- ---
 
 
 
 
 
181
 
182
  ## License
183
 
184
  Apache 2.0
 
 
 
 
 
1
+ # C3D-v0: AI-Powered CAD Code Generation Model
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ **Fine-tuned Gemma 3n model for generating CADQuery Python code from natural language descriptions**
 
 
4
 
5
  ## Model Description
6
 
7
+ C3D-v0 is a specialized language model fine-tuned for generating 3D CAD models through Python code. Built on Google's Gemma 3n architecture, this model transforms natural language descriptions into executable CADQuery scripts that can be rendered as 3D models.
 
 
 
 
 
 
8
 
9
+ This model is part of the [C3D project](https://github.com/unxversal/c3d) - a complete text-to-CAD pipeline featuring an interactive CLI, 3D web viewer, and local AI inference.
10
 
11
+ ## Key Features
12
 
13
+ - 🎯 **Specialized for CAD**: Fine-tuned specifically on CAD generation tasks
14
+ - 🔧 **CADQuery Focus**: Generates clean, executable Python CADQuery code
15
+ - 🚀 **Local Inference**: Designed to run locally via Ollama
16
+ - 📐 **3D Understanding**: Trained on geometric and mechanical design concepts
17
+ - ⚡ **Optimized Performance**: GGUF quantized for efficient inference
18
 
19
+ ## Training Details
 
 
20
 
21
+ ### Base Model
22
+ - **Architecture**: Google Gemma 3n (4B parameters)
23
+ - **Base Model**: `unsloth/gemma-3n-E4B-it`
 
24
 
25
+ ### Dataset
26
+ - **Source**: [Text-to-CadQuery Dataset](https://github.com/Text-to-CadQuery/Text-to-CadQuery)
27
+ - **Training Size**: ~48,000 examples (50% of full dataset)
28
+ - **Validation**: Full validation set maintained
29
 
30
+ ### Training Configuration
31
+ - **Method**: LoRA (Low-Rank Adaptation) fine-tuning
32
+ - **Epochs**: 1 (due to resource constraints)
33
+ - **Batch Size**: 2 per device, 4 gradient accumulation steps
34
+ - **Learning Rate**: 2e-4
35
+ - **Platform**: Trained on Kaggle/Colab free tier
36
 
37
+ ## Usage
 
 
38
 
39
+ ### Via Ollama (Recommended)
40
 
41
+ ```bash
42
+ # Install the model
43
+ ollama pull joshuaokolo/C3Dv0
 
 
44
 
45
+ # Generate CAD code
46
+ ollama run joshuaokolo/C3Dv0 "Create a simple gear with 12 teeth"
 
 
 
 
 
 
 
47
  ```
48
 
49
+ ### Via C3D CLI (Full Experience)
50
 
51
+ ```bash
52
+ # Install C3D
53
+ npm install -g c3d
54
 
55
+ # Generate with interactive 3D viewer
56
+ c3d generate "a phone case for iPhone 15"
57
+ ```
 
 
 
58
 
59
+ ### Direct Model Usage
 
 
 
 
 
60
 
61
+ ```python
62
+ from transformers import AutoTokenizer, AutoModelForCausalLM
63
+ import torch
64
+
65
+ # Load model and tokenizer
66
+ model_name = "numinousmuses/C3D-v0"
67
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
68
+ model = AutoModelForCausalLM.from_pretrained(model_name)
69
+
70
+ # Generate CAD code
71
+ prompt = "Create a simple rectangular bracket"
72
+ inputs = tokenizer(prompt, return_tensors="pt")
73
+
74
+ with torch.no_grad():
75
+ outputs = model.generate(
76
+ **inputs,
77
+ max_new_tokens=512,
78
+ temperature=0.8,
79
+ top_p=0.9,
80
+ do_sample=True
81
+ )
82
+
83
+ generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
84
+ print(generated_code)
85
  ```
86
 
87
+ ## Prompt Format
88
 
89
+ The model works best with direct, descriptive prompts:
 
 
90
 
91
+ ```
92
+ "Create a simple gear with 12 teeth"
93
+ "Generate a phone case for iPhone 15"
94
+ "Make a rectangular bracket with mounting holes"
95
+ "Design a simple pulley with a 50mm diameter"
96
  ```
97
 
98
+ ## Model Performance
99
 
100
+ - **Context Length**: Up to 32k tokens (though trained at 16k)
101
+ - **Code Quality**: Generates syntactically correct CADQuery code
102
+ - **Geometric Understanding**: Handles basic to intermediate 3D shapes
103
+ - **Memory Usage**: ~10GB RAM for full context inference
104
 
105
+ ## Example Output
 
 
106
 
107
+ **Input**: "Create a simple gear with 12 teeth"
108
 
109
+ **Output**:
110
  ```python
111
+ import cadquery as cq
 
 
 
 
 
 
112
 
113
+ # Create a gear with 12 teeth
114
  gear = (
115
+ cq.Workplane("XY")
116
+ .circle(25) # Outer radius
117
+ .circle(20) # Inner radius for teeth
118
+ .extrude(5) # Thickness
 
 
 
 
119
  )
 
 
120
 
121
+ # Add teeth around the circumference
122
+ for i in range(12):
123
+ angle = i * 30 # 360/12 = 30 degrees
124
+ tooth = (
125
+ cq.Workplane("XY")
126
+ .transformed(rotate=(0, 0, angle))
127
+ .rect(3, 8)
128
+ .extrude(5)
129
+ )
130
+ gear = gear.union(tooth)
131
+
132
+ result = gear
133
+ ```
134
 
135
  ## Limitations
136
 
137
+ - **Training Scope**: Limited to 50% of dataset due to resource constraints
138
+ - **Complexity**: Best suited for simple to moderate complexity objects
139
+ - **Vision**: Text-only model (multimodal version planned)
140
+ - **Domain**: Focused on mechanical/geometric objects from training data
 
141
 
142
  ## Roadmap
143
 
144
+ - 🔄 **Full Dataset Training**: Complete training on entire dataset
145
+ - 👁️ **Multimodal Support**: Image-to-CAD generation capabilities
146
+ - 🎯 **Improved Prompting**: Enhanced prompt engineering for better results
147
+ - 📈 **Performance Optimization**: Additional fine-tuning iterations
148
 
149
+ ## Related Links
150
 
151
+ - **Main Project**: [C3D on GitHub](https://github.com/unxversal/c3d)
152
+ - **Ollama Model**: [joshuaokolo/C3Dv0](https://ollama.com/joshuaokolo/C3Dv0)
153
+ - **GGUF Version**: [C3D-v0-gguf](https://huggingface.co/numinousmuses/C3D-v0-gguf)
154
+ - **Dataset**: [Text-to-CadQuery](https://github.com/Text-to-CadQuery/Text-to-CadQuery)
155
 
156
+ ## Citation
157
 
158
  ```bibtex
159
+ @misc{c3d-v0-2024,
160
+ title={C3D-v0: AI-Powered CAD Code Generation},
161
+ author={Joshua Okolo},
162
+ year={2024},
163
+ url={https://github.com/unxversal/c3d}
164
  }
165
  ```
166
 
167
+ ## Acknowledgments
168
+
169
+ - **Google DeepMind**: For the Gemma 3n base model and competition opportunity
170
+ - **Unsloth**: For providing efficient fine-tuning infrastructure
171
+ - **Text-to-CadQuery Team**: For the comprehensive training dataset
172
+ - **Ollama**: For local inference capabilities
173
 
174
  ## License
175
 
176
  Apache 2.0
177
+
178
+ ---
179
+
180
+ **Contact**: Joshua Okolo | Mechanical Engineering + Computer Science @ Harvard | [Portfolio](https://bento.me/joshuaokolo)