Skip to content

[AMD] Fix Quark Shared Experts Fusion Gate after load-time-override Removal - #35200

Merged
HaiShaw merged 2 commits into
sgl-project:mainfrom
ColinZ22:fix-quark-shared-experts-fusion-gate
Aug 18, 2026
Merged

HaiShaw merged 2 commits into
sgl-project:mainfrom
ColinZ22:fix-quark-shared-experts-fusion-gate

Conversation

@ColinZ22

@ColinZ22 ColinZ22 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

PR #33889 replaced process-global load-time config overrides with per-runner model-class gates and deleted declare_load_time_override. PR #29328 landed afterward still calling that deleted function from QuarkConfig.__init__, so any Quark checkpoint or online quantized checkpoint that cannot fuse shared expert(s) due to precision mismatch now raises ImportError at load. This PR restores the mixed-precision shared-experts decision path through the new gate architecture instead of the deleted global-override path.

Modifications

  • quark/quark.py: remove _maybe_disable_shared_experts_fusion and its __init__ call. Quark no longer imperatively pushes a decision; its can_fuse_shared_expert() reader stays as the source of truth.
  • models/deepseek_v2.py: DeepseekV3ForCausalLM.shared_experts_fusion_disable_reason now checks quant_config.can_fuse_shared_expert(), matching qwen2_moe.can_fuse_shared_expert's implementation. The decision flows through the per-runner gate the loader calls (install_shared_experts_fusion_decision) instead of the deleted global override. This covers the whole DeepSeek family (V2/V3, Kimi-K2.5, Kimi-VL, DeepSeek-VL2/OCR, dots_vlm).

Tests

Verified on AMD MI355X with both native AMD Quark MXFP4 checkpoint and online NVFP4 to MXFP4 requantization
(--quantization quark_mxfp4 introduced in PR #29328) with both quantized and excluded shared expert.

Checkpoint Arch / gate Fusion decision Verified
nvidia/Kimi-K2.6-NVFP4 KimiK25 / DeepseekV3 gate disabled (shared experts kept higher precision) ✅ loads + serves
nvidia/DeepSeek-R1-NVFP4 DeepseekV3 gate enabled (shared_expert quantized, precision matches routed precision) ✅ loads + serves
nvidia/Qwen3.5-397B-A17B-NVFP4 Qwen3.5 gate disabled ✅ loads + serves
amd/Qwen3.5-35B-A3B-MXFP4 Qwen3.5 gate disabled ✅ loads + serves

CI States

Latest PR Test (Base): ❌ Run #32088497917
Latest PR Test (Extra): ❌ Run #32088497735

if isinstance(self.dequantization_config, Fp8Config):
self.weight_block_size = self.dequantization_config.weight_block_size

self._maybe_disable_shared_experts_fusion()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

so this is no longer needed now?

@ColinZ22 ColinZ22 Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, Quark's can_fuse_shared_expert() decision is still used, but PR #33889 inverted the decision flow (model family specific gates now pull the answer from Quark once per runner instead of Quark pushing it into a global flag with the removed declare_load_time_override).

@BowenBao BowenBao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for quick fix. Left a question there for my understanding.

Comment thread python/sglang/srt/models/deepseek_v2.py Outdated
)
if is_wint4afp8_or_wint4a16_config(quant_config):
return "Deepseek V3/R1 W4AFP8/W4A16 model uses different quant method for routed experts and shared experts."
can_fuse_fn = getattr(quant_config, "can_fuse_shared_expert", None)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: not for this regression fix PR, but should can_fuse_shared_expert be added into base QuantConfig class?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, after this PR is merged, I can open another PR to refactor this.

@zijiecode

Copy link
Copy Markdown
Collaborator

@ColinZ22 Thanks for fixing this, the default Qwen3.5 and DeepSeek paths look good now. One edge case may still be missing: in the DeepSeek V2/V3 gate, enforce_shared_experts_fusion is checked before quant_config.can_fuse_shared_expert(). So if the shared expert stays in FP8/BF16 while the routed experts are MXFP4, --enforce-shared-experts-fusion can still force an incompatible fusion. DeepSeek V4 has the same gap because its gate does not call can_fuse_shared_expert() at all. Can we move the can_fuse_shared_expert() check before the enforce_shared_experts_fusion early return for DeepSeek V2/V3, and add the same check to the DeepSeek V4 gate? Please also add a small unit test covering mixed-precision Quark with forced fusion.

@ColinZ22

ColinZ22 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@ColinZ22 Thanks for fixing this, the default Qwen3.5 and DeepSeek paths look good now. One edge case may still ...

Good point! I updated the handling to address potential incorrect --enforce-shared-experts-fusion override and similar handling for DSV4. I also added tests.

@HaiShaw

HaiShaw commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Narrow scope to Quark specific

@HaiShaw
HaiShaw merged commit ea27e3d into sgl-project:main Aug 18, 2026
105 of 121 checks passed
longxin9715 added a commit to longxin9715/sglang that referenced this pull request Aug 18, 2026
…n-transport1

* 'main' of https://github.com/sgl-project/sglang: (255 commits)
  [Perf] Hoist DSv4 draft-extend SWA write locs; unify SWA graph buffer naming (sgl-project#34890)
  [Chore] Move version tag helper to release scripts (sgl-project#35196)
  [DSV4] Turn on mhc post pre fusion by default (sgl-project#35214)
  [diffusion] Per-section LoRA adapters on fused linear layers (sgl-project#34933)
  [XPU] Fix decode graph runner is_current_stream_capturing on non-CUDA devices (sgl-project#35050)
  [AMD] Update amd k3 cookbook for PR#34580 (sgl-project#35263)
  [Diffusion][Refactor] Refactor and extract complex RoPE implementation to layers/rotary_embedding for MOVA DiT (sgl-project#31453)
  refactor: rename chat response token IDs (sgl-project#35225)
  [mem_cache][8/N] refactor: move MambaPoolHost to pool_host.mamba (sgl-project#31180)
  [AMD] Fix Quark Shared Experts Fusion Gate after load-time-override Removal (sgl-project#35200)
  [AMD] Scope the EAGLE greedy-verify TP broadcast to ROCm only (sgl-project#35195)
  [AMD] Add the Kimi-K3 MI35x perf benchmarks in nightly (sgl-project#34985)
  Skip inkling sheared bias under batch invariance (sgl-project#35161)
  [AMD] Optimize KIMI-K3 with Triton MLA decode kernel by tuning the stage-1 geometry for gfx950 (sgl-project#34580)
  [Docs] Enable PD disaggregation for DSV4 low-latency recipes (sgl-project#35224)
  [DCP] Drop the prefill index-selection syncs by taking each rank's rows by stride (sgl-project#35084)
  [Feature] Optimize TP LMHead with All-to-All (sgl-project#32313)
  [XPU] Enable fused GDN QKV split Triton kernel on XPU (sgl-project#30144)
  [CPU] Explicitly import sgl_kernel in CPU kernel tests (sgl-project#35119)
  [diffusion] feat: load quantized H3 text encoder checkpoints (sgl-project#34986)
  ...

# Conflicts:
#	python/sglang/srt/multimodal/processors/base_processor.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants