Commit cefc55e
Fix SmolLM3 inverted no_rope_layers logic and add L3/L5 tests (#233)
## Summary
Fix inverted no_rope_layers interpretation in SmolLM3, fix BF16 type
mismatch in RoPE, and add missing L3/L5 tests.
## Bug Fix: Inverted no_rope_layers
HuggingFace convention: no_rope_layers[i] == 1 means USE RoPE (despite
the misleading name). Mobius had it backwards, causing 27/36 layers to
have wrong RoPE gating.
## Bug Fix: BF16 RoPE Type Mismatch
The ONNX RotaryEmbedding op requires all tensor inputs (x, cos, sin) to
share the same type T. The RoPE cos/sin cache is always computed in FP32
(numpy limitation), so BF16/FP16 models had a type constraint violation:
BF16 query/key + FP32 cos/sin. This cascaded through Attention -> o_proj
-> residual Add causing ORT type errors.
Fix: Added a dtype parameter to BaseRope that all RoPE subclasses thread
from config.dtype. BaseRope._cast_embeddings() inserts Cast ops after
gathering cos/sin when the model dtype differs from FP32. For FP32
models, no Cast is added (zero overhead). Covers all RoPE variants.
Also fixes a latent bug in YarnRope where attn_scale dtype was derived
from cos_cache.dtype (always FP32), fixing Ministral3/Mistral4 BF16
support.
## Results
- Prefill max diff: 6.87 -> 0.00005 (143,000x improvement)
- L5 generation: now matches HF exactly (100% token match)
- BF16 model: zero Add type mismatches (verified with real SmolLM3-3B
weights)
## Tests
- L3: Added integration test entry for smollm3-3b
- L5: Removed xfail, generation now passes
- L1: Added no_rope_layers to tiny config for direct gating coverage
- All 1185 L1 tests + 1463 unit tests pass
---------
Signed-off-by: Justin Chu <justinchu@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 0fc75da commit cefc55e
5 files changed
Lines changed: 27 additions & 23 deletions
File tree
- src/mobius/models
- testdata/golden/causal-lm
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
87 | 90 | | |
88 | | - | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | | - | |
| 412 | + | |
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| |||
0 commit comments