Text Generation
Transformers
Safetensors
qwen3
ml-intern
Generated from Trainer
trl
hf_jobs
sft
conversational
python
drawing
svg
matplotlib
text-generation-inference
Instructions to use Malajusa/qwen3-1.7b-python-drawing with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Malajusa/qwen3-1.7b-python-drawing with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Malajusa/qwen3-1.7b-python-drawing") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Malajusa/qwen3-1.7b-python-drawing") model = AutoModelForCausalLM.from_pretrained("Malajusa/qwen3-1.7b-python-drawing", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Malajusa/qwen3-1.7b-python-drawing with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Malajusa/qwen3-1.7b-python-drawing" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Malajusa/qwen3-1.7b-python-drawing", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Malajusa/qwen3-1.7b-python-drawing
- SGLang
How to use Malajusa/qwen3-1.7b-python-drawing 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 "Malajusa/qwen3-1.7b-python-drawing" \ --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": "Malajusa/qwen3-1.7b-python-drawing", "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 "Malajusa/qwen3-1.7b-python-drawing" \ --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": "Malajusa/qwen3-1.7b-python-drawing", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Malajusa/qwen3-1.7b-python-drawing with Docker Model Runner:
docker model run hf.co/Malajusa/qwen3-1.7b-python-drawing
File size: 5,801 Bytes
ad4a0b7 a2934af ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e ad4a0b7 6585f6e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | ---
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.
|