Instructions to use alan13367/Qwen3.5-4B-RustCoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use alan13367/Qwen3.5-4B-RustCoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="alan13367/Qwen3.5-4B-RustCoder") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("alan13367/Qwen3.5-4B-RustCoder") model = AutoModelForMultimodalLM.from_pretrained("alan13367/Qwen3.5-4B-RustCoder", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use alan13367/Qwen3.5-4B-RustCoder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "alan13367/Qwen3.5-4B-RustCoder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "alan13367/Qwen3.5-4B-RustCoder", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/alan13367/Qwen3.5-4B-RustCoder
- SGLang
How to use alan13367/Qwen3.5-4B-RustCoder 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 "alan13367/Qwen3.5-4B-RustCoder" \ --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": "alan13367/Qwen3.5-4B-RustCoder", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "alan13367/Qwen3.5-4B-RustCoder" \ --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": "alan13367/Qwen3.5-4B-RustCoder", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use alan13367/Qwen3.5-4B-RustCoder with Docker Model Runner:
docker model run hf.co/alan13367/Qwen3.5-4B-RustCoder
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 "alan13367/Qwen3.5-4B-RustCoder" \
--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": "alan13367/Qwen3.5-4B-RustCoder",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'Qwen3.5-4B-RustCoder
Qwen/Qwen3.5-4B fine-tuned to write Rust that compiles, passes tests and is clippy-clean. It keeps its thinking mode. These are bf16 safetensors in the original Qwen3.5 layout, for transformers and the tools that read Hugging Face checkpoints.
Other versions: Qwen3.5-4B-RustCoder-MLX-8bit for Apple Silicon (the checkpoint that was trained and evaluated; these weights are the same model, see About these weights), and Qwen3.5-4B-RustCoder-GGUF for llama.cpp.
Version 2 (2026-11-20). A weighted merge of two LoRA fine-tunes (see Training), +3.2 points over the first release. The first release is still available at revision fde9e38.
Every training answer was checked by a gate that builds the code, runs hidden tests and lints it. Answers that failed it were not used.
Results
Pass rate: the share of answers whose code passes the task's hidden tests. Each task was sampled 4 times in each of two evaluation runs, with thinking on and no system prompt. The test tiers were never trained on.
| Pass rate | Easy (29 tasks) | Hard (40) | Quality (29) | Dev (82) | All (180) |
|---|---|---|---|---|---|
| Qwen3.5-4B (8-bit) | 43.5% | 6.9% | 8.6% | 20.1% | 19.1% |
| Qwen3.5-4B-RustCoder v2 | 53.0% | 8.1% | 15.9% | 23.6% | 23.7% |
- Over the base: +4.6 points pooled over all 180 tasks (95% CI +1.8 to +7.4). 52 tasks improved and 25 got worse.
- Over the first release: +3.2 points (95% CI +1.0 to +5.3), measured the same way. The first release's card reported one evaluation run; every number on this card is the average of two.
- The tiers are small, so a single tier has a wide margin. Quality (+7.3, CI +1.3 to +14.2) is the clearest per-tier gain, easy (+9.5) is probably real, and hard (+1.2) did not move.
- Quality covers fixing bugs, refactoring, writing tests and new domains. A refactor counts only if it is also lint-clean. Dev is the tier used to pick checkpoints.
- At least 1 of 4 attempts passes on 86% of easy tasks and 21% of hard tasks.
With a compiler in the loop
It does much better when the compiler checks its answers before one is kept. Same tiers; the hidden tests only grade the answer that was kept:
| Setup | Easy | Hard | Quality | Dev | All |
|---|---|---|---|---|---|
| First answer (above) | 53.0% | 8.1% | 15.9% | 23.6% | 23.7% |
| 4 answers, keep one that builds and is clippy-clean, up to two retries with the compiler's errors | 81.2% | 22.4% | 33.1% | 34.0% | 38.9% |
| The same with 8 answers, ranked by unit tests the model writes itself | 84.5% | 26.2% | 36.0% | 39.0% | 43.0% |
For the last row, the model first writes a #[cfg(test)] module from the task description alone (without the hidden tests), and among the clean answers the one that passes the most of those tests is kept.
General ability, against the base (subsets of each benchmark):
| MMLU (200) | ARC-Challenge (150) | GSM8K (100) | HellaSwag (150) | |
|---|---|---|---|---|
| Qwen3.5-4B (8-bit) | 69.5% | 89.3% | 91.0% | 80.7% |
| Qwen3.5-4B-RustCoder v2 | 69.5% | 90.0% | 94.0% | 80.7% |
On general text, its token distribution stays close to the base: KL 0.024 nats/token and 94.3% top-1 agreement.
Usage
With transformers (a version with Qwen3.5 support):
from transformers import AutoModelForImageTextToText, AutoTokenizer
repo = "alan13367/Qwen3.5-4B-RustCoder"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForImageTextToText.from_pretrained(repo, dtype="auto", device_map="auto")
messages = [{"role": "user", "content": "Write in Rust: pub fn median(xs: &mut [i64]) -> Option<f64>"}]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, enable_thinking=True,
return_tensors="pt", return_dict=True).to(model.device)
out = model.generate(**inputs, max_new_tokens=4096, do_sample=True, temperature=0.6, top_p=0.95, top_k=20)
print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Recommended:
- Use no system prompt. Training and evaluation used none. A long style prompt sent the base model into runaway reasoning.
- Leave thinking on and cap the output at about 4096 tokens. Answers take about 1.2k (easy tasks) to 1.8k tokens (hard ones) on average. An attempt that runs to the cap is usually stuck in a reasoning loop, so resampling helps more than raising the cap.
- Use temperature 0.6, top-p 0.95 and top-k 20. These are the settings behind the numbers above.
- Check its code with the compiler when you can. Picking an answer that builds and is clippy-clean, and retrying with the error output, nearly doubles its pass rate (see With a compiler in the loop).
Training
Two LoRA fine-tunes of the 8-bit MLX model, merged by weight: 0.7 times the first fine-tune's weight update plus 0.3 times the second's. The merge is exact (the two low-rank updates are concatenated, rank 32 in all) and involves no further training. Both fine-tunes used LoRA rank 16, alpha 32, dropout 0.05, on the last 16 decoder layers, one epoch at learning rate 1e-4, batches of up to 4096 tokens, and the base's own answers to general, non-Rust prompts as replay.
- First fine-tune (the first release): 739 samples, 784k tokens. 238 of the base model's own passing attempts at the training tasks, 277 self-repairs (the model fixing its own failed attempt, given the compiler or test output as the next turn), 175 passing traces from DeepSeek V4.1 Flash kept only when they matched the 4B's own length and style, and 88 replay answers. Validation loss 0.411.
- Second fine-tune: 3,442 samples, 4.04M tokens, with 595 more generated training tasks weighted toward fixing, refactoring and test writing. About half are the model's own answers and repairs (874 and 881), half DeepSeek V4.1 Flash records on the tasks the 4B could not solve (812 answers, 815 repairs), with the teacher's reasoning weighted 0.3 in the loss so the model keeps its own way of reasoning. On its own it gained on easy and hard tasks and lost on dev; the 0.7 / 0.3 merge kept the gains without the loss.
- Two merge weights were tried (0.5 and 0.7) and the better one kept, judged on these test tiers, so the result includes a small selection.
- The loss covers only the final reply: in repair records, the failed attempt and the feedback are context, not training targets.
What the experiments behind this checkpoint showed:
- The model learns best from its own style. Reference solutions with model-written reasoning made it worse (easy 41% to 27%): it imitated their dense style and compiled less often.
- Unfiltered teacher traces also made it worse. Their long, second-guessing reasoning taught it to never leave thinking. Filtered to its own length and style, or with their reasoning down-weighted, they were safe.
- More rounds of the same stopped helping. Training again on its own answers, on twice the data, or on the compiler loop's fixed answers gave no further gain. RL (GRPO, 60 steps with the test gate as the reward) raised the training reward without improving held-out tasks.
About these weights
- Where they come from. The fine-tune was trained and merged on the 8-bit MLX model. These weights are that checkpoint dequantized to bf16, so they are exactly the evaluated model: every weight is its 8-bit value. They do not get back the precision the 8-bit quantization lost. Weights the fine-tune left alone differ from the original Qwen3.5-4B bf16 by about 0.75% (relative error), the size of the 8-bit quantization error; the fine-tuned layers (16 to 31) moved by 3 to 8%.
- Checks. Each tensor's name, shape and dtype matches Qwen/Qwen3.5-4B. Tensors that were never quantized (norms, conv1d,
A_log, the vision tower) match the original exactly. - Tokenizer and config. Both are Qwen/Qwen3.5-4B's. The tokenizer gives the same ids as the one used in training.
- No MTP head. The 8-bit checkpoint the fine-tune was built on has no multi-token-prediction head, so MTP speculative decoding (vLLM, SGLang) is not available.
Limitations
- It is a 4B model and Rust is hard for it. Many of its first answers still fail to compile, mostly with type, trait-bound and method errors in its own code (E0308, E0277, E0599), and harder multi-part tasks rarely pass (hard tier 8.1%). Use it with a compiler in the loop.
- It still over-thinks sometimes. Cap the output, and resample when an answer gets stuck.
- Only the text side was trained. The vision tower is the base's, unchanged and untested here.
- The evaluation sets are small (29 to 82 tasks per tier), so each per-tier number has a wide margin. Treat the gains as modest.
- It was trained and evaluated on standalone tasks: a function, a type or a small module checked by hidden tests, plus bug fixes, refactors and test-writing. It has not been measured on multi-file projects or long-context editing.
License
Apache 2.0, the license of the base model Qwen/Qwen3.5-4B.
- Downloads last month
- 66
Model tree for alan13367/Qwen3.5-4B-RustCoder
Base model
Qwen/Qwen3.5-4B-Base
Install from pip and serve model
# Install SGLang from pip: pip install sglang# Start the SGLang server: python3 -m sglang.launch_server \ --model-path "alan13367/Qwen3.5-4B-RustCoder" \ --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": "alan13367/Qwen3.5-4B-RustCoder", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'