Skip to content

Fix Olive quantized-weight suffix mismatch in preprocess_olive_weights - #491

Closed
titaiwangms wants to merge 1 commit into
mainfrom
fix/olive-suffix-mismatch
Closed

titaiwangms wants to merge 1 commit into
mainfrom
fix/olive-suffix-mismatch

Conversation

@titaiwangms

Copy link
Copy Markdown
Contributor

Problem

preprocess_olive_weights() in _weight_utils.py assumed 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 nested Linear, model.layers.0.mlp.experts.gate_up_proj_qweight (see olive/common/quant/state_dict.py, QWEIGHT_SUFFIX = "_qweight" etc.).

Because of this mismatch, every endswith/replace check 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 for MatMulNBits / GatherBlockQuantized / QMoE consumption. This surfaced as "N initializer(s) without weights" errors when trying to load an Olive Rtn/Gptq-quantized checkpoint into a Mobius-built graph.

This exact mismatch was flagged narrowly in #427 (for a defensive ndim==2 guard on the older moe=True 3-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) -> MobiusBuilder against yujiepan/qwen3.5-moe-tiny-random (or optimum-intel-internal-testing/tiny-random-qwen3.5-moe) reproduces the failure directly.

Fix

  • Added a _rename() helper that strips the underscore suffix, drops a redundant trailing .weight component (present for regular nn.Linear/nn.Embedding params, absent for bare fused-MoE params like gate_up_proj), and appends the correct dotted target name.
  • Kept the embed_tokens special case separate (its packed weight keeps the qweight name, not weight, since QuantizedEmbedding/GatherBlockQuantized consume it directly).
  • Added a previously-missing _scales rename branch for the general (non-embedding) case.
  • Updated _weight_utils_test.py, models/qwen35_test.py, and components/_moe_test.py fixtures, 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 the MLP(config) call site in Qwen35DecoderLayer still hardcode plain Linear regardless of config.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 on self_attn/linear_attn/dense mlp weights after this fix (confirmed via the same repro, isolated with modules_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 check on all changed files — clean.
  • Repro confirmed to now get past the suffix/rename stage and fail only at the (separately tracked) linear_class gap.

…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.
@titaiwangms
titaiwangms requested review from a team and a lite review from Copilot August 14, 2026 22:29
@CLAassistant

CLAassistant commented Aug 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown

Performance Comparison

Comparing 01008cf → 1a88a3c

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 264 264 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 126 126 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 428 428 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 *_scales branch).
  • Keep embed_tokens as a special case so the packed table remains *.embed_tokens.qweight for GatherBlockQuantized consumption.
  • 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.

@github-actions

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 01008cf → 1a88a3c

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@titaiwangms

Copy link
Copy Markdown
Contributor Author

Consolidated into #495 along with #493 and #494 to simplify review.

auto-merge was automatically disabled August 14, 2026 23:08

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants