DylanL8 commited on
Commit
b9907e3
·
1 Parent(s): 7e51981

Improve model card with detailed usage, training, and limits

Browse files
Files changed (1) hide show
  1. README.md +165 -103
README.md CHANGED
@@ -16,60 +16,159 @@ tags:
16
  - k-12
17
  - code-generation
18
  - animation
 
19
  datasets:
20
  - custom
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  ---
22
 
23
- # Qwen3-0.6B LoRA for p5.js Physics Animations
24
 
25
- A LoRA adapter for [Qwen/Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B) fine-tuned to generate interactive [p5.js](https://p5js.org/) animations that teach K-12 students physics and science concepts.
26
 
27
- Given a natural language prompt like *"Show me how gravity affects falling objects"*, the model outputs complete, runnable p5.js code with animations, labels, and interactivity.
28
 
29
- ## Key Results
30
 
31
- | Metric | Value |
32
- |---|---|
33
- | Training examples | 1,036 |
34
- | Unique topics | 124 |
35
- | Training time | 2.9 min (4x A100-80GB) |
36
- | Train loss | 0.909 → 0.495 |
37
- | Eval loss | 0.616 |
38
- | Token accuracy | 85.6% |
39
- | Trainable params | 40.4M / 792M (5.1%) |
40
 
41
- ## How to Use
42
 
43
- ### With PEFT + Transformers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  ```python
 
46
  from peft import PeftModel
47
  from transformers import AutoModelForCausalLM, AutoTokenizer
48
- import torch
49
 
50
- base_model = AutoModelForCausalLM.from_pretrained(
51
- "Qwen/Qwen3-0.6B",
 
 
 
 
52
  torch_dtype=torch.bfloat16,
53
  device_map="auto",
 
54
  )
55
- model = PeftModel.from_pretrained(base_model, "mr-dee/qwen3-p5js-physics-lora")
56
- tokenizer = AutoTokenizer.from_pretrained("mr-dee/qwen3-p5js-physics-lora")
57
-
58
- prompt = """<|im_start|>system
59
- You are a p5.js animation expert for K-12 physics education. Generate complete, working p5.js code that creates educational animations.
60
- <|im_end|>
61
- <|im_start|>user
62
- Create a p5.js animation showing projectile motion with adjustable launch angle
63
- <|im_end|>
64
- <|im_start|>assistant
65
- """
66
-
 
 
 
 
 
67
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
68
- outputs = model.generate(**inputs, max_new_tokens=2048, temperature=0.7, top_p=0.9)
 
 
 
 
 
69
  print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
70
  ```
71
 
72
- ### With vLLM (recommended for serving)
73
 
74
  ```bash
75
  vllm serve Qwen/Qwen3-0.6B \
@@ -79,93 +178,56 @@ vllm serve Qwen/Qwen3-0.6B \
79
  --max-model-len 2048
80
  ```
81
 
82
- Then query via the OpenAI-compatible API:
83
 
84
  ```bash
85
- curl http://localhost:8000/v1/chat/completions \
86
  -H "Content-Type: application/json" \
87
  -d '{
88
  "model": "p5js",
89
  "messages": [
90
- {"role": "system", "content": "You are a p5.js animation expert for K-12 physics education."},
91
- {"role": "user", "content": "Create an animation showing wave interference patterns"}
92
  ],
93
- "max_tokens": 2048,
94
- "temperature": 0.7
95
  }'
96
  ```
97
 
98
- ## Training Details
99
-
100
- ### Dataset
101
-
102
- 1,036 synthetic instruction-code pairs generated using parallel Claude agents across 124 K-12 science topics:
103
-
104
- - **Physics**: gravity, Newton's laws, projectile motion, pendulums, momentum, friction, centripetal force
105
- - **Waves & Optics**: wave interference, double slit experiment, reflection, refraction, Doppler effect
106
- - **Electricity & Magnetism**: circuit diagrams, electromagnetic induction, Faraday's law
107
- - **Astronomy**: orbital mechanics, Kepler's laws, stellar lifecycle, tidal forces
108
- - **Chemistry**: atomic structure, gas laws, chemical bonding, phase transitions
109
- - **Biology**: photosynthesis, cell division, DNA replication, ecosystem dynamics
110
- - **Earth Science**: plate tectonics, volcano lifecycle, water cycle, rock cycle
111
-
112
- Each example contains a natural language instruction and complete p5.js code using a 600x400 canvas with `setup()`/`draw()`, text labels, and smooth animations.
113
 
114
- ### LoRA Configuration
115
 
116
- | Parameter | Value |
117
- |---|---|
118
- | Rank (r) | 64 |
119
- | Alpha | 128 |
120
- | Dropout | 0.05 |
121
- | Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
122
- | Trainable parameters | 40.4M (5.1% of 792M) |
123
 
124
- ### Hyperparameters
125
 
126
- | Parameter | Value |
127
- |---|---|
128
- | Epochs | 3 |
129
- | Effective batch size | 32 (4/device x 2 grad_accum x 4 GPUs) |
130
- | Learning rate | 2e-4 |
131
- | LR scheduler | Cosine with 5% warmup |
132
- | Optimizer | AdamW (weight decay 0.01) |
133
- | Max sequence length | 2048 |
134
- | Precision | bf16 |
135
- | Gradient checkpointing | Enabled |
136
 
137
- ### Training Loss Progression
138
-
139
- | Step | Loss | Accuracy |
140
- |---|---|---|
141
- | 10 | 0.909 | 77.0% |
142
- | 30 | 0.621 | 82.3% |
143
- | 50 | 0.549 | 84.0% |
144
- | 70 | 0.510 | 84.9% |
145
- | 93 | 0.495 | 85.6% |
146
-
147
- ## Hardware
148
-
149
- - **GPUs**: 4x NVIDIA A100-SXM4-80GB
150
- - **Training time**: 171.9 seconds (~2.9 minutes)
151
- - **Throughput**: 17.2 samples/sec, 0.54 steps/sec
152
- - **Adapter size**: 155 MB
153
-
154
- ## Source Code
155
-
156
- Full training pipeline, dataset generation scripts, and serving code: [github.com/dylanler/qwen3-p5js-physics](https://github.com/dylanler/qwen3-p5js-physics)
157
 
158
- ## Limitations
 
 
 
 
159
 
160
- - Optimized for p5.js code generation only; not a general-purpose code model
161
- - Best results with physics/science animation prompts matching the training distribution
162
- - Generated code may occasionally have minor bugs requiring manual fixes
163
- - Small base model (0.6B) limits complexity of generated animations compared to larger models
164
 
165
- ## Framework Versions
166
 
167
- - **PEFT**: 0.18.1
168
- - **Transformers**: 4.57.6
169
- - **TRL**: 0.27.2
170
- - **PyTorch**: 2.9.1
171
- - **Accelerate**: 1.12+
 
 
 
 
16
  - k-12
17
  - code-generation
18
  - animation
19
+ - synthetic-data
20
  datasets:
21
  - custom
22
+ model-index:
23
+ - name: qwen3-p5js-physics-lora
24
+ results:
25
+ - task:
26
+ type: text-generation
27
+ name: Causal Language Modeling
28
+ dataset:
29
+ type: custom
30
+ name: Internal synthetic p5.js science dataset
31
+ metrics:
32
+ - type: loss
33
+ name: Final logged train loss (step 90)
34
+ value: 0.4950
35
+ - type: loss
36
+ name: Train run average loss
37
+ value: 0.5917
38
+ - type: loss
39
+ name: Eval loss (step 50)
40
+ value: 0.6164
41
  ---
42
 
43
+ # qwen3-p5js-physics-lora
44
 
45
+ LoRA adapter for [Qwen/Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B), tuned for generating educational p5.js animations from natural-language prompts.
46
 
47
+ Primary objective: produce runnable, classroom-friendly JavaScript sketches (`setup()` + `draw()`) that explain K-12 science concepts visually.
48
 
49
+ ## Model Details
50
 
51
+ - Base model: `Qwen/Qwen3-0.6B`
52
+ - Fine-tuning method: LoRA + supervised fine-tuning (SFT)
53
+ - Domain: p5.js animation code generation for science education
54
+ - Intended language: English prompts and code comments
55
+ - Adapter repo: `mr-dee/qwen3-p5js-physics-lora`
56
+ - Source project: https://github.com/dylanler/qwen3-p5js-physics
 
 
 
57
 
58
+ ## Intended Use
59
 
60
+ Direct use:
61
+ - Generate p5.js teaching demos for topics like gravity, circuits, optics, astronomy, and earth science.
62
+ - Bootstrap lesson visuals that teachers/students can edit locally.
63
+
64
+ Downstream use:
65
+ - Interactive educational apps, coding workshops, and science visualization demos.
66
+
67
+ Out of scope:
68
+ - Safety-critical software.
69
+ - Scientific simulation requiring high-precision numerical correctness.
70
+ - Unreviewed classroom deployment without human validation.
71
+
72
+ ## Training Data
73
+
74
+ Dataset summary:
75
+ - 1,036 instruction/code examples.
76
+ - 124 unique K-12 science topics.
77
+ - Synthetic dataset generated via parallel agent workflows and validated into JSONL format.
78
+
79
+ Each example contains:
80
+ - `instruction`
81
+ - `topic`
82
+ - `grade_level`
83
+ - `p5js_code` (full runnable sketch)
84
+
85
+ Data style constraints emphasized:
86
+ - 600x400 canvas
87
+ - `setup()` and `draw()` structure
88
+ - labels/annotations for explanation
89
+ - interactive and animated behavior
90
+
91
+ ## Training Procedure
92
+
93
+ Hardware and runtime:
94
+ - 4x NVIDIA A100-SXM4-80GB
95
+ - ~171.9 seconds total training runtime
96
+ - multi-GPU training via `accelerate`
97
+
98
+ LoRA config:
99
+ - `r=64`
100
+ - `lora_alpha=128`
101
+ - `lora_dropout=0.05`
102
+ - target modules: `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`
103
+
104
+ Optimization config:
105
+ - epochs: 3
106
+ - per-device batch size: 4
107
+ - gradient accumulation: 2
108
+ - effective batch size: 32 (4 GPUs)
109
+ - learning rate: `2e-4`
110
+ - scheduler: cosine, warmup ratio 0.05
111
+ - weight decay: 0.01
112
+ - max sequence length: 2048
113
+ - precision: bf16
114
+ - optimizer: AdamW
115
+
116
+ ## Training/Eval Snapshot
117
+
118
+ - Train loss (logged): `0.9090 -> 0.4950` (step 10 to step 90)
119
+ - Train run average loss (`train_metrics.json`): `0.5917`
120
+ - Eval loss (step 50): `0.6164`
121
+ - Reported token accuracy during run: up to ~85.6%
122
+
123
+ These are training-time indicators, not full benchmark performance across external test sets.
124
+
125
+ ## Quick Start
126
+
127
+ ### Transformers + PEFT
128
 
129
  ```python
130
+ import torch
131
  from peft import PeftModel
132
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
133
 
134
+ BASE = "Qwen/Qwen3-0.6B"
135
+ ADAPTER = "mr-dee/qwen3-p5js-physics-lora"
136
+
137
+ tokenizer = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
138
+ model = AutoModelForCausalLM.from_pretrained(
139
+ BASE,
140
  torch_dtype=torch.bfloat16,
141
  device_map="auto",
142
+ trust_remote_code=True,
143
  )
144
+ model = PeftModel.from_pretrained(model, ADAPTER)
145
+
146
+ messages = [
147
+ {
148
+ "role": "system",
149
+ "content": (
150
+ "You are a p5.js animation expert for K-12 physics education. "
151
+ "Return complete, runnable JavaScript."
152
+ ),
153
+ },
154
+ {
155
+ "role": "user",
156
+ "content": "Create an interactive p5.js sketch that teaches projectile motion.",
157
+ },
158
+ ]
159
+
160
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
161
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
162
+ outputs = model.generate(
163
+ **inputs,
164
+ max_new_tokens=1024,
165
+ temperature=0.4,
166
+ top_p=0.9,
167
+ )
168
  print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
169
  ```
170
 
171
+ ### vLLM Serving (LoRA)
172
 
173
  ```bash
174
  vllm serve Qwen/Qwen3-0.6B \
 
178
  --max-model-len 2048
179
  ```
180
 
181
+ Then query:
182
 
183
  ```bash
184
+ curl http://127.0.0.1:8000/v1/chat/completions \
185
  -H "Content-Type: application/json" \
186
  -d '{
187
  "model": "p5js",
188
  "messages": [
189
+ {"role":"system","content":"You are a p5.js animation expert for K-12 physics education."},
190
+ {"role":"user","content":"Create an animation showing wave interference with labeled nodes and antinodes."}
191
  ],
192
+ "max_tokens": 800,
193
+ "temperature": 0.4
194
  }'
195
  ```
196
 
197
+ Important:
198
+ - keep `prompt_tokens + max_tokens <= max_model_len`
199
+ - otherwise vLLM returns HTTP 400 validation errors
 
 
 
 
 
 
 
 
 
 
 
 
200
 
201
+ ## Limitations and Risks
202
 
203
+ - Output is not guaranteed bug-free JavaScript; review before use.
204
+ - Physical explanations may be simplified or occasionally incorrect.
205
+ - Performance drops for domains outside training distribution.
206
+ - Small base model can struggle with very long or highly complex simulations.
 
 
 
207
 
208
+ ## Responsible Use
209
 
210
+ - Use with human review in educational settings.
211
+ - Validate scientific correctness before presenting to students.
212
+ - Sandbox or lint generated code before running in production applications.
 
 
 
 
 
 
 
213
 
214
+ ## Framework Versions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
+ - PEFT: 0.18.1
217
+ - Transformers: 4.57.6
218
+ - TRL: 0.27.2
219
+ - PyTorch: 2.9.1
220
+ - Accelerate: 1.12+
221
 
222
+ ## Citation
 
 
 
223
 
224
+ If you use this adapter, cite:
225
 
226
+ ```bibtex
227
+ @misc{qwen3_p5js_physics_lora_2026,
228
+ title = {qwen3-p5js-physics-lora},
229
+ author = {mr-dee},
230
+ year = {2026},
231
+ url = {https://huggingface.co/mr-dee/qwen3-p5js-physics-lora}
232
+ }
233
+ ```