MiniCPM5-1B-WSP-NoLoop (v2)
A training-free, sparse weight edit of openbmb/MiniCPM5-1B that reduces degenerate repetition loops (the model re-emitting the same sentence or block until it runs out of tokens) without measurable loss on GSM8K, MMLU, ARC-Challenge or HellaSwag.
Part of the Weight-Space Programming (WSP) series: diagnose a behaviour defect, localize it in the weights, repair it with a minimal direct edit, verify on held-out data that nothing else broke.
| Version | Where | Edit | Loops | Math / knowledge |
|---|---|---|---|---|
v2 (this, main) |
main |
64 neurons mean-replaced | about 40% fewer hard loops | no measurable change |
| v1 | branch v1 |
same 64 neurons zeroed | about 70% fewer hard loops | GSM8K -8.8 pts, MMLU -2.5, ARC -2.8 |
Use v2 by default. Use v1 only for long-form generation where loops matter more than math or factual accuracy.
Base vs v1 vs v2 at a glance
| Metric | Base | v1 (zeroed) | v2 (mean-replaced) |
|---|---|---|---|
| Hard loops, 300 synthetic prompts | 42 / 35 | 8 | 20 |
| Hard loops, 200 real prompts | 17 / 18 | 6 | 12 |
| Hard loops, 100 think-mode prompts | 12 / 16 | 7 | 10 |
| Loop reduction, pooled | - | -70% | -39% |
| GSM8K (250) | 70.0% / 67.2% | 61.2% (p=0.002) | 68.4% (p=0.74) |
| MMLU (600) | 47.2% / 47.2% | 44.7% (p=0.03) | 46.7% (p=0.69) |
| ARC-Challenge (400) | 43.8% / 43.8% | 41.0% (p=0.05) | 44.0% (p=1.0) |
| HellaSwag acc_norm (10,042), all three in one run | 48.76% | 48.92% (p=0.30) | 48.79% (p=0.87) |
| Knowledge tuning set (1,230), all three in one run | 48.05% | 45.77% (p=0.0005) | 48.05% (p=1.0) |
v1 and v2 were first evaluated in separate sessions, so where Base shows two values the first is from the v1 run and the second from the v2 run; each p-value is a paired McNemar test against the base from the same run. The HellaSwag and knowledge-tuning rows compare all three models in a single run.
The edit
- What changed: 64 MLP neurons (0.058% of the model's 110,592 MLP neurons) in layers 4 to 22, mostly 7 to 14. Each neuron's column in
mlp.down_proj.weightis set to zero and its average contribution is added back as a constantdown_projbias. The neuron therefore always outputs its mean value instead of an input-dependent value. - Why mean replacement: v1 simply zeroed these neurons. That also removed their average output, which shifts the residual stream for every token and was the cause of v1's math and knowledge loss. On 1,230 tuning questions, zeroing gave 45.8% (base 48.1%, p=0.0005); mean replacement of the same neurons gave 48.1% (p=1.0).
- Format: standard
LlamaForCausalLMwithmlp_bias: trueinconfig.json. Allgate_proj/up_projbiases and thedown_projbiases of untouched layers are zero. Loads in Transformers as is. Runtimes that ignore MLP biases (check your GGUF converter) will not reproduce the edit. - No training, no fine-tuning data, no inference-time hooks.
- Reproducible:
neurons.jsonlists the 64 (layer, neuron) pairs and their mean activations.python apply_patch.py --out ./v2rebuilds this checkpoint from the base model bit for bit.
How it was built
- Diagnosis. Greedy decoding on long-form prompts shows sentence-level loops. The SFT checkpoint loops more than the final RL+OPD checkpoint, so the defect predates RL.
- Localization. Contrast sets from the model's own fluent outputs: a sentence written once vs. written again. Gradient x activation attribution over every MLP neuron finds neurons that drive re-emitting an already written sentence (details in the v1 notes below).
- Capability protection (new in v2). Separate selection, tuning and test splits:
- Selection: repetition contrasts from 40 prompts; the model's own correct GSM8K train solutions; MMLU validation and ARC-Challenge train questions; in-context copy tasks.
- Tuning: 120 loop-prone prompts, 200 GSM8K train problems, 1,230 MMLU validation and ARC validation questions.
- Final test (below): never used for any decision.
- Choice rule (fixed before testing): the most loop reduction with no GSM8K or knowledge drop on the tuning sets. Candidates were the v1 neurons and a newly ranked set of 32 to 128 neurons, all mean-replaced. The v1 neurons won (tuning: hard loops 11 to 6, GSM8K 69.5% to 71.5%, knowledge 48.1% to 48.1%).
Final held-out results (base vs v2, same session)
Greedy decoding. "Hard loop" = output ends in a periodic repeat, or one sentence appears 5+ times without the model stopping. p-values are paired McNemar tests.
Repetition
| Test | Base | v2 | Fixed / new | p |
|---|---|---|---|---|
| 300 synthetic long-form prompts, 1024 tokens | 35 hard loops | 20 | 26 / 11 | 0.02 |
| 200 real user prompts (No Robots test), 1024 tokens | 18 | 12 | 10 / 4 | 0.18 |
| 100 think-mode prompts, 1200 tokens | 16 | 10 | 10 / 4 | 0.18 |
| All 600 pooled | 69 | 42 | 46 / 19 | 0.001 |
| Metric (300 synthetic prompts) | Base | v2 |
|---|---|---|
| Degenerate outputs (sentence 3x or tail loop) | 26.7% | 13.7% |
| Duplicated sentences | 12.9% | 5.4% |
| Repeated 4-grams | 0.202 | 0.142 |
Capabilities
| Benchmark | Base | v2 | p |
|---|---|---|---|
| GSM8K, 250 test problems, 768 tokens | 67.2% | 68.4% | 0.74 |
| MMLU, 600 test questions | 47.2% | 46.7% | 0.69 |
| ARC-Challenge, 400 test questions | 43.8% | 44.0% | 1.0 |
| HellaSwag, 10,042 validation items (lm-evaluation-harness, acc_norm) | 48.76% | 48.79% | 0.87 |
HellaSwag (plain completion, no chat template) was also unchanged for v1 (48.92%, p=0.30), so v1's losses are specific to multi-step reasoning and knowledge questions asked in chat format. v2 changes 159 of 10,042 HellaSwag answers (78 lost, 81 gained), v1 changes 241.
Absolute base scores differ slightly from the v1 evaluation (for example GSM8K 70.0% there vs 67.2% here) because of batch size and padding differences between sessions; each comparison above is base vs v2 in the same run.
Limitations
- v2 removes fewer loops than v1. It is the safer trade-off, not the strongest loop fix.
- Per-split loop improvements on real prompts and think mode are not individually significant (p=0.18); the pooled improvement is (p=0.001).
- The edit targets sentence and block loops. It does not fix factual errors of the 1B base model.
- With the recommended sampling settings (T=1.0, top_p=0.95, min_p=0) the base model rarely loops, so the benefit is mainly for greedy and low-temperature use.
- English and Chinese only, as with the base model.
v1 notes (zero ablation, branch v1)
v1 zeroes the same 64 neurons. On held-out tests it cut hard loops more (300 synthetic prompts: 42 to 8; 200 real prompts: 17 to 6) but lowered GSM8K from 70.0% to 61.2% (p=0.002), MMLU from 47.2% to 44.7% (p=0.03) and ARC-Challenge from 43.8% to 41.0% (p=0.05). Its first model card reported GSM8K 65.0% vs 65.0% on 60 problems, 40 of which had also been used as protected examples during selection; that check was not independent.
Approaches tried and rejected along the way: removing the residual "copy-mode" direction (it increased repetition, since that direction is the model's own "already said this" signal), amplifying it (fluency cost about equal to the gain), and scaling induction attention heads (broke format following and verbatim copying).
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer
tok = AutoTokenizer.from_pretrained("yasserrmd/MiniCPM5-1B-WSP-NoLoop")
model = AutoModelForCausalLM.from_pretrained("yasserrmd/MiniCPM5-1B-WSP-NoLoop", dtype="auto")
v1: add revision="v1".
- Downloads last month
- 58