Commit a44df86
Fix Qwen3 garbage output: apply RMSNorm +1 to all Qwen-family models (#23)
Qwen's RMSNorm computes `output = norm(x) * (1 + weight)`, not
`norm(x) * weight`. The +1 weight adjustment was only applied when
`delta_n_heads > 0` (DeltaNet/Qwen3.5-hybrid) or `model_type == 1`
(Gemma). Plain Qwen3 (and Qwen2/2.5) models have `delta_n_heads=0`
and `model_type=0`, so the adjustment was skipped entirely.
Without it, RMSNorm produces wrong scales and activations explode
by layer 2 (values reaching 6000+), generating garbage tokens.
Fix: detect any Qwen-family model via `strstr(gguf->arch, "qwen")`
in addition to the existing DeltaNet check. This covers qwen2,
qwen2moe, qwen3, qwen3_5 — all use the same (1+w) RMSNorm.
Applied to tq_model.c (library) + quant.h (single-header/WASM).
WASM binary rebuilt to include the fix.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent c717832 commit a44df86
3 files changed
Lines changed: 20 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9982 | 9982 | | |
9983 | 9983 | | |
9984 | 9984 | | |
9985 | | - | |
| 9985 | + | |
9986 | 9986 | | |
9987 | 9987 | | |
9988 | 9988 | | |
| |||
9992 | 9992 | | |
9993 | 9993 | | |
9994 | 9994 | | |
9995 | | - | |
9996 | | - | |
| 9995 | + | |
| 9996 | + | |
| 9997 | + | |
| 9998 | + | |
| 9999 | + | |
| 10000 | + | |
| 10001 | + | |
| 10002 | + | |
9997 | 10003 | | |
9998 | 10004 | | |
9999 | 10005 | | |
| |||
10022 | 10028 | | |
10023 | 10029 | | |
10024 | 10030 | | |
10025 | | - | |
| 10031 | + | |
10026 | 10032 | | |
10027 | 10033 | | |
10028 | 10034 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1517 | 1517 | | |
1518 | 1518 | | |
1519 | 1519 | | |
1520 | | - | |
| 1520 | + | |
1521 | 1521 | | |
1522 | 1522 | | |
1523 | 1523 | | |
| |||
1527 | 1527 | | |
1528 | 1528 | | |
1529 | 1529 | | |
1530 | | - | |
1531 | | - | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
1532 | 1538 | | |
1533 | 1539 | | |
1534 | 1540 | | |
| |||
1557 | 1563 | | |
1558 | 1564 | | |
1559 | 1565 | | |
1560 | | - | |
| 1566 | + | |
1561 | 1567 | | |
1562 | 1568 | | |
1563 | 1569 | | |
| |||
Binary file not shown.
0 commit comments