LFM3-1.7B-think-lang-fix
Direct weight edit of LiquidAI/LFM3-1.7B that makes the thinking language (<think …>) match the prompt language — no training, no gradients, no extra tokens. Chinese prompt → Chinese reasoning, English prompt → English reasoning.
This is a surgical rank-1 edit of 13 MLP output matrices (2.5–3.3% relative change per edited tensor, 0.05% of all parameters), produced with the Weight-Space Programming method: diagnosis by forward-pass hooks + linear algebra only, followed by targeted subtraction/amplification of specific directions in the residual stream.
TL;DR results
25-prompt multilingual battery, official sampling settings (temperature=0.1, top_k=50, repetition_penalty=1.1), default system prompt:
| Prompt language | Baseline think-language match | Edited |
|---|---|---|
| Chinese | 3/12 (25%) | 12/12 (100%) |
| English | 8/8 (100%) | 8/8 (100%), no regression |
| Malay | 1/3 (33%) | 2/3 (67%) |
| Japanese | 0/2 (0%) | 2/2 (100%) |
Quality spot-checks (long-form + math): all answers remain correct (12/2+5=11 ✓, perimeter 26 / area 40 ✓, 9.9>9.11 ✓); enable_thinking=False mode unaffected.
Root cause (found with forward passes + linear algebra only)
- The reasoning language is decided at the first
<thinktoken; the contest is between English openers (We/The, an English-CoT corpus prior) and local-language openers (用户/我们/ユーザー, a prompt-following circuit). - Layer-wise decomposition of residual-stream writes shows layers 18–22 MLPs indiscriminately write an "English-opener" direction (+0.16 to +0.53 even for Chinese/Japanese prompts; layer 21 strongest), while layer 23's MLP is the correct language-follower (EN prompt +0.31, ZH prompt −0.37) but is outvoiced. Attention layers keep writing prompt-language-aligned signal and get drowned out.
- The English system prompt is not the cause (removing it lowers Chinese-thinking rate: 8% vs 25%) — the prior lives in the weights (training corpus is English-CoT dominated).
What the edit does
Rank-1 updates to feed_forward.w2.weight [2048, 7680] of 13 layers (fp32 math, cast back to bf16):
axis d_tok = mean(E[We, The]) − mean(E[用户, 我们, ユーザー, ユーザーは])
d_res = normalize(final_norm_w ⊙ d_tok)
g_l = normalize(post_ffn_norm_w_l ⊙ d_res) # per-layer direction in w2 output space
proj_l = w2_lᵀ g_l # per-column component along g
remove layers {5,6,7,11,12,13,16,18,20,21,22}: w2 ← w2 − 1.2 · outer(g_l, proj_l)
amplify layers {19, 23}: w2 ← w2 + 1.5 · outer(g_l, proj_l)
- Remove: projects out the "English-opener prior" written by those MLPs (γ=1.2, 20% overshoot to cover the strongest prior on math problems).
- Amplify: boosts the correct prompt-following writers (layers 19/23) 2.5× along that direction.
- All other 273 tensors are byte-identical to the original.
Usage
Works exactly like the base model (same config, tokenizer, chat template). Requires trust_remote_code=True for the LFM3 architecture files.
transformers
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "dokoomae/LFM3-1.7B-think-lang-fix"
tok = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map="auto"
)
messages = [{"role": "user", "content": "小明有12个苹果,分给朋友一半又买了5个,现在有几个?"}]
inputs = tok.apply_chat_template(
messages, add_generation_prompt=True, enable_thinking=True, return_dict=True, return_tensors="pt"
).to(model.device)
out = model.generate(**inputs, max_new_tokens=1024)
print(tok.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False))
vLLM
vllm serve dokoomae/LFM3-1.7B-think-lang-fix \
--dtype bfloat16 --max-model-len 32768
Known limitations
- The English-CoT prior is strongest on math word problems: without the default system prompt, Chinese-thinking consistency is 10/12 (12/12 with it).
- Malay uses the Latin script and shares tokens (
User) with English openers; one math prompt still reasons in English. - Validated in an int8 sandbox against the transformers reference implementation (logit error < 0.007); not re-regressed on bf16 GPU. Run the bundled battery if you deploy seriously.
- This edit removes a bias / unlocks an existing ability; it does not add capabilities the base model lacks.
Reproduction artifacts
Also in this family:
| File | Description |
|---|---|
thinklang_rank1_patch.safetensors | Compact rank-1 patch (g[2048] + proj[7680] + coeff per layer) — see the patch bundle |
apply_patch.py | Applies the patch to a local copy of the base model |
patch_meta.json | Patch config and metadata |
A compact patch bundle (497 KB) that reproduces this model from the original weights, plus a full technical report (diagnosis data, layer-wise tables, method), is available at LFM3-1.7B-think-lang-fix patch bundle.
License
The model inherits the Liquid AI Community License (LICENSE). The original model card and license: LiquidAI/LFM3-1.7B.