Qwen3-1.7B-Distillation-Coding
a Qwen3-based coding agent
2 min readupdated
This is a distilled version of Qwen3-1.7B trained from a larger Qwen3-8B teacher model using the TRL library and the OpenEnv environment. It acts as an autonomous coding agent, solving tasks from the MBPP benchmark with the run_python tool inside an interactive session. The agent writes code step by step, runs it, analyzes errors, and fixes them directly in the interpreter before submitting a final solution. It is aimed at developers and researchers exploring on-policy agent distillation and tool use in LLMs.
Key features
- On-policy distillation: trains the student model on the teacher's token distribution across the student's own generated episodes.
- Interpreter integration: the built-in
run_pythontool preserves session state across calls. - Higher accuracy: passes 51.4% of test cases on MBPP, up from the base model's 43.6%.
- Efficiency: pairs a compact 1.7B parameter footprint with stronger coding task performance.
What you can do
- Automate code writing: run the model to generate and iteratively debug small Python functions.
- Test agentic workflows: use the TRL repository to reproduce on-policy distillation on your own tasks.
- Integrate into pipelines: pair the model with OpenEnv to safely execute generated code in a sandbox.
Example
from transformers import AutoModelForCausalLM, AutoTokenizer
def run_python(code: str) -> str:
"""Run Python code in the session and return its output."""
model_id = "sergiopaniego/Qwen3-1.7B-Distillation-Coding"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, dtype="auto", device_map="auto")
prompt = "Write a Python function to find the minimum of two numbers."
inputs = tokenizer.apply_chat_template(
[{"role": "user", "content": prompt}],
tools=[run_python],
enable_thinking=False,
add_generation_prompt=True,
return_tensors="pt",
return_dict=True,
).to(model.device)
output = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.7, top_p=0.8, top_k=20)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1] :]))Read more
DetailsBenchmarks: 51.4% pass rate on MBPP (compared to 43.6% for the base Qwen3-1.7B model and 68.2% for the Qwen3-8B teacher).
Training: 100 steps on the MBPP dataset using 1x A100 80GB hardware, taking around 80 minutes.
Limitations: trained exclusively on short, MBPP-style Python tasks and is not a general-purpose assistant.










Comments