Quick start
import torchfrom 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:
Table with columns: Setting, Value| 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.
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, per-sample generations and status, and sanity-check script. 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.