Add fused MoE support to SelectiveMixedPrecision heuristics - #2645
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d9a8b1f-9b83-4a52-bfe4-92437196e1c1
There was a problem hiding this comment.
Pull request overview
This PR extends Olive’s SelectiveMixedPrecision fixed heuristics to support explicitly recognized fused-MoE (Qwen3/Qwen3.5) expert output projections, and enforces a “double opt-in” so MoE-capable quantizers must explicitly enable MoE when consuming a plan that requires it.
Changes:
- Add
moe: truesupport to fixedSelectiveMixedPrecisionMLP heuristics by resolving fused expertdown_projtargets viaLayerWrapper+ canonicaliter_quant_targetsidentities, and emitmixed_precision_info.requires_moewhen expert overrides are produced. - Add fail-closed validation and consumer-side enforcement in PyTorch quantization utilities so required MoE overrides can’t be silently skipped (unless already materialized by a compatible prior Olive checkpoint).
- Add unit tests and documentation covering supported MoE layouts, rejection paths, and the double-opt-in workflow.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
olive/passes/pytorch/selective_mixed_precision.py |
Adds moe config, MoE-aware fixed-heuristic targeting, and emits requires_moe metadata. |
olive/passes/pytorch/quant_utils.py |
Validates/propagates requires_moe, enforces consumer opt-in, and delays parameter mutation until after validation. |
olive/common/hf/wrapper.py |
Adds fail-closed LayerWrapper.get_expert_output for supported fused-expert output parameter resolution. |
test/passes/pytorch/test_selective_mixed_precision.py |
Adds MoE planning and end-to-end RTN consumption tests (including rejection and hybrid cases). |
test/passes/pytorch/test_quant_utils.py |
Adds tests for requires_moe enforcement, malformed metadata rejection, and required-target survival checks. |
test/common/test_hf_wrapper.py |
Adds tests validating LayerWrapper.get_expert_output behavior and fail-closed errors. |
docs/source/features/quantization.md |
Documents MoE selective mixed precision support and the required double opt-in behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d9a8b1f-9b83-4a52-bfe4-92437196e1c1
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d9a8b1f-9b83-4a52-bfe4-92437196e1c1
There was a problem hiding this comment.
🟡 Changes recommended
Stale targets and mismatched materialized precision can be accepted, while failure paths may mutate tied embeddings before validation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
olive/passes/pytorch/quant_utils.py:669
- Name-only membership does not prove that an already-materialized target fulfills the mixed-precision override. For example, the added test installs
experts.down_projat 4 bits while metadata requires 8 bits, and this path accepts it because the name is present. Compare the existing QuantTensor/effective existing qcfg settings with the required override before treating it as fulfilled; otherwise a follow-up pass can silently preserve the wrong precision.
materialized_names = already_quantized_names if has_compatible_existing_config else set()
if config.moe is True:
materialized_names = materialized_names | new_target_names
missing = sorted(required_names - materialized_names)
olive/passes/pytorch/quant_utils.py:894
- This does not actually defer parameter mutation until after validation because
wrapper.maybe_untie_word_embeddings()is still called earlier at lines 751-752. If a required MoE target then fails validation, tied embeddings and configuration have already been mutated. Remove the earlier call and keep this post-validation call so the fail-closed path remains mutation-free.
# Everything above is discovery/validation. Mutate parameters only after all required
# final targets have been proven present.
if fresh_qcfg.lm_head or fresh_qcfg.embeds:
wrapper.maybe_untie_word_embeddings()
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d9a8b1f-9b83-4a52-bfe4-92437196e1c1
There was a problem hiding this comment.
🟡 Changes recommended
The documentation implies support for an export path that the PR explicitly leaves out of scope.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d9a8b1f-9b83-4a52-bfe4-92437196e1c1
Describe your changes
Add explicit, fail-closed fused-MoE support to the fixed
SelectiveMixedPrecisionheuristics.moe: truesupport tohigh_precision_mlp_downandhigh_precision_mlp_down_qkvfor explicitly recognized Qwen3/Qwen3.5 fused K-last expert layouts.LayerWrapperand canonicaliter_quant_targetsidentities, emitting whole per-layerexperts.down_projoverrides rather than per-expert precision.high_precision_lm_headas a legal MoE no-op, and reject score-based algorithms withmoe: trueuntil their parameter-level scoring is implemented separately.mixed_precision_info.requires_moeand require an explicitmoe: trueon the first MoE-capable RTN, GPTQ, or KQuant consumer. Validate that required expert overrides survive skip/component selection and are actually selected or already materialized before mutating parameters.This is the first implementation stage for #2638. A follow-up will generalize SNR/IQE scoring to fused parameter targets; KLD-gradient requires separate routing/gradient/memory design.
Checklist before requesting a review
lintrunner -a.Release note:
SelectiveMixedPrecisionfixed heuristics can now plan higher precision for supported fused Qwen MoE expert output projections with explicit downstream MoE opt-in and fail-closed validation.(Optional) Issue link
Part of #2638.