Malajusa's picture
Document drawing model, training metrics, and held-out sanity results
6585f6e verified
|
Raw History Blame Contribute Delete
5.8 kB
---
base_model: Qwen/Qwen3-1.7B
datasets: Malajusa/qwen3-1.7b-python-drawing-sft
library_name: transformers
license: apache-2.0
pipeline_tag: text-generation
tags:
- ml-intern
- generated_from_trainer
- trl
- hf_jobs
- sft
- conversational
- python
- drawing
- svg
- matplotlib
- trackio:https://Malajusa-qwen3-python-drawing-sft-trackio.hf.space?project=qwen3-python-drawing-sft&runs=Malajusa-1795610881&sidebar=collapsed
---
<div style="display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:0 0 2em"><a href="https://hf.co/chat?mode=ml-intern"><img src="https://hf.co/datasets/huggingface/badges/resolve/main/built-with-ml-intern-lg.svg" alt="Built with ML Intern" style="margin:0"></a><a href="https://hf.co/chat?mode=ml-intern&prompt=Use%20Malajusa%2Fqwen3-1.7b-python-drawing%20to%20create%20a%20blue%20turtle%20spiral" style="display:inline-flex;align-items:center;gap:5px;padding:4px 12px;border:1.5px solid #eee;border-radius:16px;background:#f9fbfc;color:#c2410c;font-weight:600;font-size:14px;text-decoration:none">Try a drawing prompt ›</a><a href="https://hf.co/chat?mode=ml-intern&prompt=Evaluate%20Malajusa%2Fqwen3-1.7b-python-drawing%20on%20more%20held-out%20drawing%20prompts" style="display:inline-flex;align-items:center;gap:5px;padding:4px 12px;border:1.5px solid #eee;border-radius:16px;background:#f9fbfc;color:#c2410c;font-weight:600;font-size:14px;text-decoration:none">Evaluate more prompts ›</a></div>
# Qwen3-1.7B Python Drawing
Full-parameter supervised fine-tune of [Qwen/Qwen3-1.7B](https://huggingface.co/Qwen/Qwen3-1.7B) for Python drawing and SVG code. The model generates matplotlib charts, Turtle and PIL drawings, SVG markup, and plotting-code explanations or fixes.
- **Dataset:** [Malajusa/qwen3-1.7b-python-drawing-sft](https://huggingface.co/datasets/Malajusa/qwen3-1.7b-python-drawing-sft), 51,496 training rows and 300 held-out rows
- **Final eval loss:** **0.19746** on the fixed 32-row evaluation subset
- **Final eval mean token accuracy:** **0.94190** on the same subset
- **Training:** one epoch, 3,219 optimizer steps, approximately 1h54m on one A100 80 GB
- **Dashboard:** [Trackio run](https://Malajusa-qwen3-python-drawing-sft-trackio.hf.space?project=qwen3-python-drawing-sft&runs=Malajusa-1795610881&sidebar=collapsed)
## Quick start
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "Malajusa/qwen3-1.7b-python-drawing"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id, dtype="bfloat16", device_map="auto"
)
messages = [
{
"role": "system",
"content": (
"You are an expert Python drawing assistant. You write correct, runnable "
"Python code for matplotlib charts, Turtle and PIL drawings, and clean SVG "
"markup. When asked about plotting code you explain or fix it precisely. "
"Always produce complete, self-contained code."
),
},
{
"role": "user",
"content": "Write PIL code that draws eight blue bars of increasing height and saves bars.png",
},
]
text = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True, enable_thinking=False
)
inputs = tokenizer([text], return_tensors="pt").to(model.device)
with torch.inference_mode():
generated = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
answer = tokenizer.decode(
generated[0][inputs.input_ids.shape[1]:], skip_special_tokens=True
)
print(answer)
```
Review generated code before executing it. Long or intricate SVGs may require a larger generation budget than 1,024 tokens.
## Training procedure
The run used TRL's conversational prompt-completion SFT format with completion-only loss. All model parameters were trainable. Key settings:
| Setting | Value |
|---|---|
| Maximum sequence length | 2,048 tokens |
| Per-device batch size | 8 |
| Gradient accumulation | 2 |
| Effective batch size | 16 |
| Learning rate | 1e-5, cosine schedule |
| Warmup | 100 steps |
| Epochs | 1 |
| Precision | BF16 |
| Activation checkpointing | Disabled after A100 memory smoke test |
| Peak GPU memory | 66.85 GiB allocated / 76.24 GiB reserved |
The reproducible training script is [`train_sft_a100.py`](train_sft_a100.py).
### Framework versions
- TRL 1.18.2
- Transformers 5.24.1
- PyTorch 2.15.0
- Datasets 5.2.0
- Accelerate 1.16.0
- Trackio 0.45.1
## Held-out sanity check
Ten deterministic generations were sampled across chart code, SVG generation, SVG code, Turtle, and PIL tasks from the untouched 300-row held-out file. Nine stopped normally at an end-of-turn token. Eight produced nonblank renders.
- The synthetic heart, cloud, Turtle spiral/octagon, and PIL bar charts followed their requested parameters closely.
- A matplotlib PDF line plot rendered correctly.
- One flowchart was not rendered because its prompt-required external `data.json` fixture was not supplied to the rendering subprocess.
- One long title-card SVG reached the 1,024-token cap and was incomplete.
- A second complex SVG rendered, but omitted requested arrows and structural elements; a successful render is not evidence of full semantic correctness.
See the [contact sheet](sanity/contact_sheet.png), [per-sample generations and status](sanity/results.jsonl), and [sanity-check script](sanity/sanity_check_drawing.py). This is a small qualitative sanity check, not a comprehensive drawing-quality benchmark.
## Limitations
The model can produce incomplete, non-executing, or visually inaccurate code, especially for complex diagrams and long SVGs. External data files and plotting dependencies must be supplied by the caller. Evaluate on representative prompts and inspect rendered outputs before production use.