Repository navigation
Commit 70de6ad
committed
fix(qwen35): thread linear_class through self_attn/linear_attn/shared_expert
Qwen35Attention, GatedDeltaNet, and Qwen2MoELayer's shared_expert
(reused by Qwen35MoEBlock) all hardcoded plain Linear regardless of
config.quantization, unlike the generic Attention/MLP classes used
elsewhere in Mobius. Since Mobius rebuilds the ONNX graph from scratch
rather than tracing the PyTorch model, this meant the corresponding
initializer slots were always built expecting dense float weights --
so a quantized checkpoint's packed uint8 tensors for these modules
could never load, failing with a shape mismatch (or, before #491's
suffix fix, "initializer without weights").
Fix:
- Add an optional `linear_class` constructor parameter to
Qwen35Attention (q/k/v/o_proj) and GatedDeltaNet (in_proj_qkv/z/b/a,
out_proj), matching the pattern already used by the generic
Attention/MLP classes. GatedDeltaNet's dt_bias/A_log/conv1d.weight
are small recurrent-state parameters and are intentionally left
unquantized regardless of this argument.
- Add an optional `linear_class` parameter to Qwen2MoELayer for its
shared_expert/shared_expert_gate (the routed experts are already
quantized separately via the fused QMoE path, driven directly by
config.quantization -- this only covers the always-active shared
expert, which isn't part of that fused op). Defaults to None
(plain Linear), so existing Qwen2MoEDecoderLayer callers are
unaffected.
- Add a `_linear_factory(config)` helper in qwen35.py (mirrors the
existing pattern in deepseek.py) and thread it through
Qwen35DecoderLayer/Qwen35MoEDecoderLayer's self_attn/linear_attn/mlp
construction.
Verified end-to-end: Olive Rtn(bits=4, group_size=16, sym=true,
moe=true) -> MobiusBuilder against
optimum-intel-internal-testing/tiny-random-qwen3.5-moe now succeeds
without excluding linear_attn/shared_expert via
modules_to_not_convert -- self_attn/linear_attn/shared_expert weights
save as quantized u8 tensors and a full ONNX model + genai_config are
produced.
Fixes #492.1 parent 1a88a3c commit 70de6ad
4 files changed
Lines changed: 83 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
470 | 477 | | |
471 | 478 | | |
472 | 479 | | |
473 | 480 | | |
474 | 481 | | |
| 482 | + | |
475 | 483 | | |
476 | 484 | | |
| 485 | + | |
| 486 | + | |
477 | 487 | | |
478 | 488 | | |
479 | 489 | | |
| |||
486 | 496 | | |
487 | 497 | | |
488 | 498 | | |
489 | | - | |
| 499 | + | |
490 | 500 | | |
491 | 501 | | |
492 | 502 | | |
493 | 503 | | |
494 | | - | |
| 504 | + | |
495 | 505 | | |
496 | 506 | | |
497 | 507 | | |
498 | 508 | | |
499 | | - | |
| 509 | + | |
500 | 510 | | |
501 | 511 | | |
502 | 512 | | |
503 | 513 | | |
504 | | - | |
| 514 | + | |
505 | 515 | | |
506 | 516 | | |
507 | 517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
105 | 116 | | |
106 | 117 | | |
107 | | - | |
| 118 | + | |
108 | 119 | | |
| 120 | + | |
| 121 | + | |
109 | 122 | | |
110 | 123 | | |
111 | 124 | | |
| |||
118 | 131 | | |
119 | 132 | | |
120 | 133 | | |
121 | | - | |
| 134 | + | |
122 | 135 | | |
123 | 136 | | |
124 | 137 | | |
125 | 138 | | |
126 | 139 | | |
127 | | - | |
| 140 | + | |
128 | 141 | | |
129 | | - | |
| 142 | + | |
130 | 143 | | |
131 | | - | |
| 144 | + | |
132 | 145 | | |
133 | 146 | | |
134 | 147 | | |
| |||
141 | 154 | | |
142 | 155 | | |
143 | 156 | | |
144 | | - | |
| 157 | + | |
145 | 158 | | |
146 | 159 | | |
147 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
282 | 287 | | |
283 | 288 | | |
284 | 289 | | |
285 | 290 | | |
| 291 | + | |
| 292 | + | |
286 | 293 | | |
287 | 294 | | |
288 | 295 | | |
289 | | - | |
290 | | - | |
| 296 | + | |
| 297 | + | |
291 | 298 | | |
292 | 299 | | |
293 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | 33 | | |
37 | 34 | | |
38 | 35 | | |
39 | 36 | | |
40 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
41 | 58 | | |
42 | 59 | | |
43 | 60 | | |
| |||
47 | 64 | | |
48 | 65 | | |
49 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
50 | 73 | | |
51 | 74 | | |
52 | 75 | | |
| |||
55 | 78 | | |
56 | 79 | | |
57 | 80 | | |
| 81 | + | |
58 | 82 | | |
59 | 83 | | |
60 | | - | |
| 84 | + | |
61 | 85 | | |
62 | | - | |
| 86 | + | |
63 | 87 | | |
64 | | - | |
| 88 | + | |
65 | 89 | | |
66 | 90 | | |
67 | 91 | | |
| |||
247 | 271 | | |
248 | 272 | | |
249 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
250 | 281 | | |
251 | 282 | | |
252 | 283 | | |
253 | 284 | | |
254 | | - | |
| 285 | + | |
255 | 286 | | |
256 | 287 | | |
257 | 288 | | |
| |||
0 commit comments