Repository navigation
Fixed the issue where FP8 PTPC/BF16 MoE failed to pass correct args to aiter - #30
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Resolve the backend-selection mismatch before approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes FP8 PTPC AITER kernel selection by preserving preshuffle metadata on MoE weights.
Changes:
- Marks
w13andw2weights as AITER-shuffled after transformation. - Enables correct AITER MoE kernel configuration.
File summaries
| File | Summary |
|---|---|
python/sglang/srt/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a8_fp8_moe.py |
Adds shuffle markers; a critical backend-selection issue remains because _use_aiter may mark weights for AITER while the effective runner is Triton. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| layer.w13_weight.is_shuffled = True | ||
| layer.w2_weight.is_shuffled = True |
There was a problem hiding this comment.
Make sense.
SGLANG_USE_AITER=1 and is_hip is not equal to --moe-runner-backend triton
Code updated. will_use_aiter_moe() is used to determine whether aiter moe is used (i.e. preshuffle weight is needed.)
Now use the code like this
if (
self.weight_quant.strategy == QuantizationStrategy.CHANNEL
and will_use_aiter_moe()
):
shuffle_weight(...)
layer.w13_weight.is_shuffled = True
layer.w2_weight.is_shuffled = True
sammysun0711
left a comment
There was a problem hiding this comment.
LGTM, let's merge it after related aiter pr ready.
| _should_use_aiter_moe = ( | ||
| will_use_aiter_moe() | ||
| and self._aiter_ck_moe_supported(layer) | ||
| and not layer._skip_aiter_moe_shuffle |
There was a problem hiding this comment.
After removing the alignment requirement (i.e. physical_intermediate_size%128==0), TP2/TP4 MTP weights are also shuffled.
There was a problem hiding this comment.
Need to revisit here if we integrate qwen3.5 support in same sglang branch later.
cc0c3c5
into
qwen38-flash-next-amd-current-fix-install
Adapt the source branch interfaces required by the PR #30 FP8 PTPC and BF16 MoE import to qwen4_v0.5.21. Keep explicit Triton selection ahead of SGLANG_USE_AITER in allocation, routing and shared-expert setup. Load padded BF16 buffers with logical TP checkpoint offsets. Based-on: 619632b Based-on: 6053574 These are selective interface adaptations, not full cherry-picks of the referenced commits. Keep generic padding at 128 and omit INT4-triggered backend selection. The following commits contain PR #30 itself and the project PTPC alignment and launch policy. Signed-off-by: apinge <[email protected]>
…o aiter (#30) * add preshuffle flag for ptpc * fix(moe): align FP8 PTPC shuffle with runner * recover mtp tp2 and tp4 (cherry picked from commit cc0c3c5) Source-PR: #30 Port notes: - Resolve PTPC context against the new base, which already has some shuffle markers; retain the effective-runner import and source padding behavior. - Preserve the new base gfx95 activation guard and parameter identity while removing the old BF16 128-alignment restriction from PR #30. - Adapt source regression fixtures to the new MoeRunnerConfig interfaces. - Project-specific 64 alignment and launch policy are in the next commit. Signed-off-by: apinge <[email protected]>
Load equal logical TP checkpoint slices before padding FP8 PTPC gate/up weights and channel scales, then pad down-projection K and shuffle. Require PTPC alignment 64 without changing the generic AITER default. Keep explicit Triton MoE free of AITER padding and preshuffle even with SGLANG_USE_AITER=1, as required by the Qwen3.8 TP1 launch. Use 64-aligned physical BF16 dimensions for the gfx942 gated MTP path, with zero pad metadata for the tuned Qwen3.8 kernels. Preserve Qwen3.5 automatic AITER selection, shared-expert routing and ASM/CK layouts. Export the PTPC default in Qwen launch scripts and select AITER for the Qwen3.8 MTP MoE. Keep source PR #30 regressions in the repository; local migration experiments and their artifacts are kept separately in /opt. Qwen3.8 MoE configs: apinge/aiter@23115cc Qwen3.5 ASM configs: apinge/aiter@4752a40 Qwen3.5 CK configs: apinge/aiter@3bb5dfa Signed-off-by: apinge <[email protected]>
Restore the inline F.pad, torch.cat and Parameter assignments from the source branch after PR #30 so reviewers can compare the padding path directly. Remove the local padding helpers and copy_or_rebind_param use. Release temporary tensors after use to limit their lifetime. Keep strict alignment-64 validation, unpadded logical TP loading and effective backend selection unchanged. Explicit Triton still bypasses AITER MoE padding and shuffle. Preserve the padding observation log. Reference: cc0c3c5 Validation: 56 targeted tests and 6 subtests passed. Real GPU FP8 padding and shuffle produce identical weight/scale bytes and layout markers for intermediate 128, 160 and 320. The 160-to-192 single-layer allocation test peaks about 361 MiB above the helper implementation; unpadded cases match. No full model evaluation was rerun for this refactor. Signed-off-by: apinge <[email protected]>
…C padding (#86) * compat(moe): prepare AITER interfaces for PR #30 Adapt the source branch interfaces required by the PR #30 FP8 PTPC and BF16 MoE import to qwen4_v0.5.21. Keep explicit Triton selection ahead of SGLANG_USE_AITER in allocation, routing and shared-expert setup. Load padded BF16 buffers with logical TP checkpoint offsets. Based-on: 619632b Based-on: 6053574 These are selective interface adaptations, not full cherry-picks of the referenced commits. Keep generic padding at 128 and omit INT4-triggered backend selection. The following commits contain PR #30 itself and the project PTPC alignment and launch policy. Signed-off-by: apinge <[email protected]> * Fixed the issue where FP8 PTPC/BF16 MoE failed to pass correct args to aiter (#30) * add preshuffle flag for ptpc * fix(moe): align FP8 PTPC shuffle with runner * recover mtp tp2 and tp4 (cherry picked from commit cc0c3c5) Source-PR: #30 Port notes: - Resolve PTPC context against the new base, which already has some shuffle markers; retain the effective-runner import and source padding behavior. - Preserve the new base gfx95 activation guard and parameter identity while removing the old BF16 128-alignment restriction from PR #30. - Adapt source regression fixtures to the new MoeRunnerConfig interfaces. - Project-specific 64 alignment and launch policy are in the next commit. Signed-off-by: apinge <[email protected]> * fix(moe): align PTPC to 64 and preserve Qwen3.5/Qwen3.8 paths Load equal logical TP checkpoint slices before padding FP8 PTPC gate/up weights and channel scales, then pad down-projection K and shuffle. Require PTPC alignment 64 without changing the generic AITER default. Keep explicit Triton MoE free of AITER padding and preshuffle even with SGLANG_USE_AITER=1, as required by the Qwen3.8 TP1 launch. Use 64-aligned physical BF16 dimensions for the gfx942 gated MTP path, with zero pad metadata for the tuned Qwen3.8 kernels. Preserve Qwen3.5 automatic AITER selection, shared-expert routing and ASM/CK layouts. Export the PTPC default in Qwen launch scripts and select AITER for the Qwen3.8 MTP MoE. Keep source PR #30 regressions in the repository; local migration experiments and their artifacts are kept separately in /opt. Qwen3.8 MoE configs: apinge/aiter@23115cc Qwen3.5 ASM configs: apinge/aiter@4752a40 Qwen3.5 CK configs: apinge/aiter@3bb5dfa Signed-off-by: apinge <[email protected]> * refactor(moe): restore source PTPC padding flow Restore the inline F.pad, torch.cat and Parameter assignments from the source branch after PR #30 so reviewers can compare the padding path directly. Remove the local padding helpers and copy_or_rebind_param use. Release temporary tensors after use to limit their lifetime. Keep strict alignment-64 validation, unpadded logical TP loading and effective backend selection unchanged. Explicit Triton still bypasses AITER MoE padding and shuffle. Preserve the padding observation log. Reference: cc0c3c5 Validation: 56 targeted tests and 6 subtests passed. Real GPU FP8 padding and shuffle produce identical weight/scale bytes and layout markers for intermediate 128, 160 and 320. The 160-to-192 single-layer allocation test peaks about 361 MiB above the helper implementation; unpadded cases match. No full model evaluation was rerun for this refactor. Signed-off-by: apinge <[email protected]> * docs(moe): explain early PTPC alignment validation Signed-off-by: apinge <[email protected]> * fix(moe): restore source AITER padding allocation Restore the source get_moe_padding_size implementation, including the AITER_MOE_PADDING_SIZE override and the generic default of 128. Pass the effective AITER backend directly to PTPC weight allocation again, then use the existing padded loader to copy logical TP weight and scale slices. Remove the project-specific gfx942 BF16 alignment override so BF16 also uses the source environment-driven allocation. Retain the requested strict PTPC alignment-64 check, but validate the same resolved value used for allocation. PTPC launch scripts supply the 64 default; a direct PTPC launch without that setting now fails early instead of validating 64 and silently allocating with the generic 128. Explicit Triton continues to bypass AITER MoE padding and shuffle. Based-on: cc0c3c5 Validation: 47 targeted checks and 6 subtests passed, including every TP rank, presharded inputs, channel scales and explicit Triton selection. Real single-layer GPU loading, normalization and shuffle produced identical weight/scale bytes and markers for Qwen3.8 TP2/TP4. Local experiments are under /opt; no full-model runs were added. Signed-off-by: apinge <[email protected]> --------- Signed-off-by: apinge <[email protected]>
Motivation
This PR adds preshuffle flag
layer.w13_weight.is_shuffled=Trueandlayer.w2_weight.is_shuffled=TruetoAiterMoeQuantInfoafter thecreate_weightsfunction has executed the weight shuffling.With this PR, aiter
fused_moeis able to recognize the correct config and choose the correct moe kernels.This PR also fixes the PTPC FP8 and BF16 MoE paths, where the BF16 MoE path is used for MTP.
This PR also fixes a TP1 model launch failure. Previously, with
SGLANG_USE_AITER=1and--moe-runner-backend triton, the old sglLang still triggered aiter weight preshuffling at launch, creating an extra weight copy and causing high peak memory usage / OOM. Now preshuffling is controlled only by--moe-runner-backend, which reduces peak memory overhead for TP1 model launch with triton moe.Modifications
Accuracy Tests
Tested with apinge/aiter#1
TP 1 and TP 4: only smoke testing performed; passed.
TP2
Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci