alan13367 commited on
Commit
55a93e3
·
verified ·
1 Parent(s): 225e85b

Version 2: round 10 M7 (0.7 x round 5 + 0.3 x round 10 LoRA), merged, MLX 8-bit

Browse files
Files changed (2) hide show
  1. README.md +43 -33
  2. model.safetensors +1 -1
README.md CHANGED
@@ -1,50 +1,64 @@
1
  ---
2
- base_model: alan13367/Qwen3.5-4B-RustCoder
3
- base_model_relation: quantized
4
  library_name: mlx
5
  license: apache-2.0
6
- pipeline_tag: text-generation
7
  language:
8
  - en
9
  tags:
10
- - mlx
11
  - qwen3.5
12
  - rust
13
  - code
14
  - lora
15
- - 8bit
16
  ---
17
 
18
  # Qwen3.5-4B-RustCoder-MLX-8bit
19
 
20
- [Qwen/Qwen3.5-4B](https://huggingface.co/Qwen/Qwen3.5-4B) fine-tuned to write Rust that compiles, passes tests and is clippy-clean. It keeps its thinking mode. This is the MLX checkpoint for Apple Silicon, 8-bit (group size 64), with the LoRA merged into the weights of [mlx-community/Qwen3.5-4B-MLX-8bit](https://huggingface.co/mlx-community/Qwen3.5-4B-MLX-8bit). It is the checkpoint that was trained and evaluated.
 
 
21
 
22
- For transformers and other non-MLX tools, use the bf16 safetensors version: [alan13367/Qwen3.5-4B-RustCoder](https://huggingface.co/alan13367/Qwen3.5-4B-RustCoder).
23
 
24
  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.
25
 
26
  ## Results
27
 
28
- Pass rate: the share of answers whose code passes the task's hidden tests. Each task was sampled 4 times, with thinking on and no system prompt. The test tiers were never trained on.
29
 
30
- | Pass rate | Easy (29 tasks) | Hard (40) | Quality (29) | Dev (82) |
31
- |---|---|---|---|---|
32
- | Qwen3.5-4B (8-bit) | 41.4% | 7.5% | 8.6% | 20.7% |
33
- | **Qwen3.5-4B-RustCoder** | **51.7%** | **8.8%** | **17.2%** | **22.9%** |
34
 
35
- - Pooled over all 180 tasks: +4.3 points over the base (95% CI +0.6 to +8.2) and +0.046 graded reward (CI +0.012 to +0.081).
36
- - The tiers are small. A single tier only detects a gain of about 9 points (hard, quality) or 14 points (easy), so only the pooled gain is established.
 
37
  - 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.
38
- - At least 1 of the 4 attempts passes on 82.8% of easy tasks and 22.5% of hard tasks.
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  General ability, against the base (subsets of each benchmark):
41
 
42
  | | MMLU (200) | ARC-Challenge (150) | GSM8K (100) | HellaSwag (150) |
43
  |---|---|---|---|---|
44
- | Qwen3.5-4B (8-bit) | 69.5% | 89.3% | 92.0% | 80.7% |
45
- | Qwen3.5-4B-RustCoder | 69.0% | 90.0% | 92.0% | 82.0% |
46
 
47
- On general text, its token distribution stays close to the base: KL 0.026 nats/token and 94.2% top-1 agreement.
48
 
49
  ## Usage
50
 
@@ -71,32 +85,28 @@ print(out.text)
71
  Recommended:
72
 
73
  - **Use no system prompt.** Training and evaluation used none. A long style prompt sent the base model into runaway reasoning.
74
- - **Leave thinking on and cap the output at about 4096 tokens.** Answers that finish take a median of about 1.2k tokens. An attempt that runs to the cap is usually stuck in a reasoning loop, so resampling helps more than raising the cap.
75
  - **Use temperature 0.6, top-p 0.95 and top-k 20.** These are the settings behind the numbers above.
 
76
 
77
  ## Training
78
 
79
- LoRA SFT, one epoch. Rank 16, alpha 32, dropout 0.05, on the last 16 decoder layers. Learning rate 1e-4, batches of up to 4096 tokens. In total 739 samples, 784k trained tokens, 402 steps. Validation loss was 0.411.
80
-
81
- The data is mostly the model's own work, filtered by the gate:
82
 
83
- | Source | Records | What it is |
84
- |---|---|---|
85
- | Own passing attempts | 238 | The base model's own attempts at the training tasks, kept only if they pass the hidden tests and the test lints |
86
- | Self-repairs | 277 | The base model fixing its own failed attempts, given the compiler or test output as the next user turn, kept only if the fix passes |
87
- | Teacher traces | 175 | Passing traces from DeepSeek V4.1 Flash. 159 of them repair the 4B's own failed attempts. Only traces within the 4B's own length and style were kept (completion of at most 2048 tokens, little second-guessing) |
88
- | Replay | 88 | The base model's own answers to general, non-Rust prompts, to keep its general ability |
89
 
90
  What the experiments behind this checkpoint showed:
91
 
92
- - **The model learns best from its own style.** Reference solutions with model-written reasoning made it worse (easy 41.4% → 26.7%). It imitated their dense style and compiled less often.
93
- - **Unfiltered teacher traces also made it worse** (easy 34.5%). Their long, second-guessing reasoning taught it to never leave thinking: 177 of 720 answers ran to the cap.
94
- - **Filtering the teacher traces fixed that.** This checkpoint has 36 of 720 answers that run to the cap, against 82 for the base.
95
- - **The loss covers only the final reply.** In repair records, the failed attempt and the feedback are context, not training targets.
96
 
97
  ## Limitations
98
 
99
- - It is a 4B model and Rust is hard for it. Many of its answers still fail to compile (about half did for the base model and the previous fine-tune), mostly with type, trait-bound and method errors in its own code (E0308, E0277, E0599). Harder multi-part tasks rarely pass (hard tier 8.8%). It does much better with a compiler in the loop: given the error output it fixes a share of its failures, and the best of 4 attempts passes far more often than a single one.
100
  - It still over-thinks sometimes. Cap the output, and resample when an answer gets stuck.
101
  - Only the text side was trained. The vision tower is the base's, unchanged and untested here.
102
  - 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.
 
1
  ---
2
+ base_model: Qwen/Qwen3.5-4B
3
+ base_model_relation: finetune
4
  library_name: mlx
5
  license: apache-2.0
6
+ pipeline_tag: image-text-to-text
7
  language:
8
  - en
9
  tags:
 
10
  - qwen3.5
11
  - rust
12
  - code
13
  - lora
14
+ - mlx
15
  ---
16
 
17
  # Qwen3.5-4B-RustCoder-MLX-8bit
18
 
19
+ [Qwen/Qwen3.5-4B](https://huggingface.co/Qwen/Qwen3.5-4B) fine-tuned to write Rust that compiles, passes tests and is clippy-clean. It keeps its thinking mode. This is the MLX 8-bit checkpoint for Apple Silicon, the one that was trained and evaluated.
20
+
21
+ Other versions: [Qwen3.5-4B-RustCoder](https://huggingface.co/alan13367/Qwen3.5-4B-RustCoder) (bf16 safetensors, for transformers and other non-MLX tools) and [Qwen3.5-4B-RustCoder-GGUF](https://huggingface.co/alan13367/Qwen3.5-4B-RustCoder-GGUF) (for llama.cpp).
22
 
23
+ **Version 2 (2026-11-20).** A weighted merge of two LoRA fine-tunes (see [Training](#training)), +3.2 points over the first release. The first release is still available at revision [`225e85b`](https://huggingface.co/alan13367/Qwen3.5-4B-RustCoder-MLX-8bit/tree/225e85b13d37eb9deeaa0cff8085ebd22d0d192f).
24
 
25
  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.
26
 
27
  ## Results
28
 
29
+ 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.
30
 
31
+ | Pass rate | Easy (29 tasks) | Hard (40) | Quality (29) | Dev (82) | All (180) |
32
+ |---|---|---|---|---|---|
33
+ | Qwen3.5-4B (8-bit) | 43.5% | 6.9% | 8.6% | 20.1% | 19.1% |
34
+ | **Qwen3.5-4B-RustCoder v2** | **53.0%** | **8.1%** | **15.9%** | **23.6%** | **23.7%** |
35
 
36
+ - 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.
37
+ - 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.
38
+ - 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.
39
  - 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.
40
+ - At least 1 of 4 attempts passes on 86% of easy tasks and 21% of hard tasks.
41
+
42
+ ### With a compiler in the loop
43
+
44
+ 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:
45
+
46
+ | Setup | Easy | Hard | Quality | Dev | All |
47
+ |---|---|---|---|---|---|
48
+ | First answer (above) | 53.0% | 8.1% | 15.9% | 23.6% | 23.7% |
49
+ | 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% |
50
+ | The same with 8 answers, ranked by unit tests the model writes itself | 84.5% | 26.2% | 36.0% | 39.0% | 43.0% |
51
+
52
+ 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.
53
 
54
  General ability, against the base (subsets of each benchmark):
55
 
56
  | | MMLU (200) | ARC-Challenge (150) | GSM8K (100) | HellaSwag (150) |
57
  |---|---|---|---|---|
58
+ | Qwen3.5-4B (8-bit) | 69.5% | 89.3% | 91.0% | 80.7% |
59
+ | Qwen3.5-4B-RustCoder v2 | 69.5% | 90.0% | 94.0% | 80.7% |
60
 
61
+ On general text, its token distribution stays close to the base: KL 0.024 nats/token and 94.3% top-1 agreement.
62
 
63
  ## Usage
64
 
 
85
  Recommended:
86
 
87
  - **Use no system prompt.** Training and evaluation used none. A long style prompt sent the base model into runaway reasoning.
88
+ - **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.
89
  - **Use temperature 0.6, top-p 0.95 and top-k 20.** These are the settings behind the numbers above.
90
+ - **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](#with-a-compiler-in-the-loop)).
91
 
92
  ## Training
93
 
94
+ 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.
 
 
95
 
96
+ - **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.
97
+ - **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.
98
+ - 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.
99
+ - The loss covers only the final reply: in repair records, the failed attempt and the feedback are context, not training targets.
 
 
100
 
101
  What the experiments behind this checkpoint showed:
102
 
103
+ - **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.
104
+ - **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.
105
+ - **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.
 
106
 
107
  ## Limitations
108
 
109
+ - 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.
110
  - It still over-thinks sometimes. Cap the output, and resample when an answer gets stuck.
111
  - Only the text side was trained. The vision tower is the base's, unchanged and untested here.
112
  - 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.
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4e50a2c397f5645adad286f7a921591278be005f7152694d0186c7c83a0e1a57
3
  size 5136696047
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33b10ad2227c21525aa14a9e8cbc63d0d55c946e179b972b44d82e0d209345c7
3
  size 5136696047