Repository navigation
Fix Olive quantized-weight suffix mismatch in preprocess_olive_weights - #491
titaiwangms wants to merge 1 commit into
Conversation
…onvention preprocess_olive_weights() assumed a dotted suffix convention (<pname>.qweight/.scales/.qzeros) that never matches Olive's actual on-disk keys, which use an underscore suffix appended directly to the owning parameter name (<pname>_qweight/_scales/_qzeros, e.g. "...gate_proj.weight_qweight" or "...experts.gate_up_proj_qweight" -- see olive/common/quant/state_dict.py). Every endswith/replace check in this function silently failed to match, so any real Olive-quantized checkpoint fell through to the "pass through unchanged" branch instead of being renamed/reshaped for MatMulNBits/GatherBlockQuantized/QMoE consumption, and was missing an explicit rename branch for `_scales` entirely. This was flagged (for a different, narrower symptom) in #427, which scoped itself to a defensive ndim==2 guard for RTN's older moe=True 3-D case and left "real MoE quantization support" for a follow-up. #451 added that follow-up (QMoE emission for Qwen3.5/3.6-MoE), but its projections dict and `preprocess_olive_weights` reshape logic were themselves written against the same incorrect dotted-suffix assumption, so they never actually exercised a real Olive checkpoint end-to-end. Repro: chaining Olive's Rtn(moe=true) -> MobiusBuilder against yujiepan/qwen3.5-moe-tiny-random surfaced "N initializer(s) without weights" at save time, because every quantized nn.Linear/nn.Embedding key in the checkpoint (attention/MLP projections, embeddings) failed to match and was left un-renamed. Fix: introduce a `_rename` helper that strips the underscore suffix, drops a redundant trailing ".weight" component (present for regular nn.Linear/nn.Embedding parameters but not for bare fused-MoE parameters like "gate_up_proj"), and appends the target dotted name. Update the embed_tokens special case (which keeps the "qweight" name for GatherBlockQuantized instead of renaming to "weight") accordingly, and add the previously-missing "_scales" rename branch for the general (non-embedding) case. Update tests in _weight_utils_test.py/qwen35_test.py/_moe_test.py that had been written against the same incorrect fixture convention. Note: this fixes weight *naming*, not quantization *coverage*. Qwen3.5's Qwen35Attention/GatedDeltaNet/MLP call sites still hardcode plain Linear regardless of config.quantization (only the MoE fused-expert path added in #451 threads through quantization), so self_attn/linear_attn/MLP weights in a quantized Qwen3.5/3.6 checkpoint still fail to load with a shape mismatch after this fix. Tracked separately.
Performance Comparison
|
There was a problem hiding this comment.
Pull request overview
This PR fixes Mobius’s Olive weight preprocessing to correctly recognize and rename Olive’s underscore-suffixed quantized buffers (*_qweight, *_scales, *_qzeros) into the canonical Mobius keys expected by MatMulNBits, GatherBlockQuantized, and QMoE packing.
Changes:
- Update
preprocess_olive_weights()to handle Olive’s underscore suffix convention and normalize names via a_rename()helper (including the previously-missing*_scalesbranch). - Keep
embed_tokensas a special case so the packed table remains*.embed_tokens.qweightforGatherBlockQuantizedconsumption. - Update Qwen3.5 MoE and MoE packing test fixtures to use the correct underscore-suffix input keys.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/mobius/models/qwen35.py | Updates inline documentation to reflect Olive’s underscore-suffix convention for quantized tensors. |
| src/mobius/models/qwen35_test.py | Updates synthetic Olive MoE state_dict fixtures to underscore-suffix keys. |
| src/mobius/components/_moe_test.py | Updates Olive MoE packing test inputs to underscore-suffix keys. |
| src/mobius/_weight_utils.py | Fixes Olive key matching/renaming/reshaping to align with Olive’s underscore suffixes; adds missing scales renaming. |
| src/mobius/_weight_utils_test.py | Updates unit tests/fixtures to match the corrected Olive underscore-suffix format and adds fused-MoE coverage. |
Suppressed comments (3)
src/mobius/_weight_utils.py:789
- The embed_tokens qweight branch assumes the packed table is 2-D (as required by GatherBlockQuantized), but it never validates this. Adding an explicit ndim check will fail fast with a clearer error if a malformed Olive checkpoint (or mis-keyed tensor) is provided.
This issue also appears in the following locations of the same file:
- line 796
- line 801
if value.dtype != torch.uint8:
raise ValueError(
f"Olive embedding qweight must be uint8 for {key}, got {value.dtype}"
)
if value.shape[-1] % blob_size != 0:
src/mobius/_weight_utils.py:800
- Similar to qweight, the embed_tokens qzeros branch is expected to be 2-D for GatherBlockQuantized. Consider validating ndim here as well so shape errors are caught at preprocess time rather than later during graph execution/loading.
if value.dtype != torch.uint8:
raise ValueError(
f"Olive embedding qzeros must be uint8 for {key}, got {value.dtype}"
)
result[key[: -len("weight_qzeros")] + "zero_points"] = value.contiguous()
src/mobius/_weight_utils.py:802
- The embed_tokens scales tensor is also expected to be 2-D ([vocab, n_blocks]) per QuantizedEmbedding. Adding an ndim check here would make malformed checkpoints fail fast and align with the branch’s documentation.
elif key.endswith("embed_tokens.weight_scales"):
result[key[: -len("weight_scales")] + "scales"] = value
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
Pull request was closed
Problem
preprocess_olive_weights()in_weight_utils.pyassumed Olive's quantized checkpoints use a dotted suffix convention (<pname>.qweight/.scales/.qzeros). Olive actually uses an underscore suffix appended directly to the owning parameter name — e.g.model.layers.0.mlp.gate_proj.weight_qweight, or for fused MoE parameters with no nestedLinear,model.layers.0.mlp.experts.gate_up_proj_qweight(seeolive/common/quant/state_dict.py,QWEIGHT_SUFFIX = "_qweight"etc.).Because of this mismatch, every
endswith/replacecheck in the function silently failed to match, so real Olive-quantized checkpoints fell through to the "pass through unchanged" branch instead of being renamed/reshaped forMatMulNBits/GatherBlockQuantized/QMoEconsumption. This surfaced as"N initializer(s) without weights"errors when trying to load an OliveRtn/Gptq-quantized checkpoint into a Mobius-built graph.This exact mismatch was flagged narrowly in #427 (for a defensive
ndim==2guard on the oldermoe=True3-D path) and left unresolved ("parked"). #451 added QMoE emission for Qwen3.5/3.6-MoE on top of the same incorrect dotted-suffix assumption, so it also never actually exercised a real Olive checkpoint end-to-end.Repro
Chaining Olive's
Rtn(moe=true)->MobiusBuilderagainstyujiepan/qwen3.5-moe-tiny-random(oroptimum-intel-internal-testing/tiny-random-qwen3.5-moe) reproduces the failure directly.Fix
_rename()helper that strips the underscore suffix, drops a redundant trailing.weightcomponent (present for regularnn.Linear/nn.Embeddingparams, absent for bare fused-MoE params likegate_up_proj), and appends the correct dotted target name.embed_tokensspecial case separate (its packed weight keeps theqweightname, notweight, sinceQuantizedEmbedding/GatherBlockQuantizedconsume it directly)._scalesrename branch for the general (non-embedding) case._weight_utils_test.py,models/qwen35_test.py, andcomponents/_moe_test.pyfixtures, which had been written against the same incorrect dotted-suffix convention.Scope / what this does NOT fix
This fixes weight naming, not quantization coverage.
Qwen35Attention,GatedDeltaNet, and theMLP(config)call site inQwen35DecoderLayerstill hardcode plainLinearregardless ofconfig.quantization— only the MoE fused-expert path (added in #451) threads quantization through for this model family. So a quantized Qwen3.5/3.6 checkpoint will still fail with a shape mismatch onself_attn/linear_attn/densemlpweights after this fix (confirmed via the same repro, isolated withmodules_to_not_convert). That's a separate, larger gap — will file a follow-up issue for it.Testing
pytest src/mobius/_weight_utils_test.py src/mobius/models/qwen35_test.py src/mobius/models/deepseek_test.py src/mobius/components/_moe_test.py— 117 passed.ruff checkon all changed files — clean.linear_classgap.