Skip to content

Pin the eager experts implementation in moe=True quantized checkpoints - #2740

Open
Oke Iyanuoluwa Enoch (Iyanuoluwa007) wants to merge 2 commits into
microsoft:mainfrom
Iyanuoluwa007:pin-eager-experts-for-moe-quant
Open

Oke Iyanuoluwa Enoch (Iyanuoluwa007) wants to merge 2 commits into
microsoft:mainfrom
Iyanuoluwa007:pin-eager-experts-for-moe-quant

Conversation

@Iyanuoluwa007

Copy link
Copy Markdown
Contributor

Describe your changes

After Rtn, Gptq or KQuant with moe=True, reloading the checkpoint and calling model(...) crashes with:

RuntimeError: Shape-movement / view ops (transpose, reshape, view, permute, flatten, expand, …) are not supported on an Olive QuantTensor ...

transformers selects the grouped_mm fused-experts forward by default (even on CPU), and its _grouped_linear calls weight.transpose(-2, -1), which the storage-only QuantTensor deliberately rejects. The eager implementation works, but users had to know to call model.set_experts_implementation("eager") themselves.

finalize() (shared by all three passes) now writes "experts_implementation": "eager" to the saved config.json for moe=True runs, so from_pretrained loads the checkpoint with the eager forward by default. save_pretrained does not persist the implementation choice, and save_metadata rewrites config.json, so the key is written after both.

The quantization docs section that described the manual workaround now explains this default instead.

This only addresses the inference crash (item 1 of the issue). Making QuantTensor support a transpose (and whether batched_mm is affected) stays with the transposed-layout design in #2621.

Checklist before requesting a review

  • Add unit tests for this change. (test_rtn_moe_checkpoint_runs_with_default_experts_implementation: quantizes a tiny local Qwen3-MoE whose config uses the default implementation, reloads it and runs a forward pass. Without the fix it fails with the QuantTensor RuntimeError above.)
  • Make sure all tests can pass. (test_rtn.py, test_kquant.py, test_gptq_moe.py, test_selective_mixed_precision.py: 278 passed, 3 skipped)
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a (ruff 0.15.11 check and format on changed files)
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.
    Checkpoints quantized with moe=True now load with the eager experts implementation, so native PyTorch inference works without calling set_experts_implementation("eager") manually.

(Optional) Issue link

Fixes #2619

transformers picks the grouped_mm fused-experts forward by default, even on
CPU. It transposes the expert weight, which a storage-only QuantTensor can't
do, so running a reloaded Rtn/Gptq/KQuant(moe=True) checkpoint crashed with
"Shape-movement / view ops ... are not supported on an Olive QuantTensor".

save_pretrained doesn't persist the experts implementation, so finalize()
now writes "experts_implementation": "eager" to the saved config.json (after
save_metadata, which rewrites that file). from_pretrained then loads the
checkpoint with the eager forward, which uses the weight without moving it.

Fixes microsoft#2619
Copilot AI balanced review requested due to automatic review settings October 17, 2026 09:25
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🟢 Approval recommended

The focused shared-path fix addresses the reported crash with regression coverage and no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes #2619 by making MoE-quantized checkpoints default to eager experts during native PyTorch inference.

Changes:

  • Persists the eager setting after shared quantization finalization saves metadata.
  • Adds a regression test covering checkpoint reload and inference.
  • Updates documentation to explain the new default.
File Description
test/​passes/​pytorch/​test_rtn.py Tests default reload and inference for an MoE-quantized checkpoint.
olive/​passes/​pytorch/​quant_utils.py Pins eager experts in saved configuration for moe=True.
docs/​source/​features/​quantization.md Documents the eager default and explicit overrides.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

MoE-quantized models crash on default grouped_mm inference path (QuantTensor transpose not supported)

2 participants