Skip to content

Fixed the issue where FP8 PTPC/BF16 MoE failed to pass correct args to aiter - #30

Merged
sammysun0711 merged 3 commits into
qwen38-flash-next-amd-current-fix-installfrom
qwen38-flash-next-moe-ptpc-preshuffle
Sep 21, 2026
Merged

sammysun0711 merged 3 commits into
qwen38-flash-next-amd-current-fix-installfrom
qwen38-flash-next-moe-ptpc-preshuffle

Conversation

@apinge

@apinge apinge commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

Motivation

This PR adds preshuffle flag layer.w13_weight.is_shuffled=True and layer.w2_weight.is_shuffled=True to AiterMoeQuantInfo after the create_weights function has executed the weight shuffling.

With this PR, aiter fused_moe is able to recognize the correct config and choose the correct moe kernels.

#aiter/aiter/fused_moe.py

  if (
      full_impl is not None
      and kernel_name1.startswith("impl__flydsl_")
      and not weights_shuffled
  ):
      cfg = None
      full_impl = None

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=1 and --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

 python -m sglang.test.run_eval   --eval-name gsm8k --num-examples 1319 --max-tokens 16384 --port 7080
 
[aiter] import [module_aiter_core] under /opt/aiter/aiter/jit/module_aiter_core.so
ChatCompletionSampler initialized with self.system_message=None self.temperature=0.0 self.max_tokens=16384 self.reasoning_effort=None self.extra_body=None self.stop=None self.record_meta_info=True
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1314/1314 [19:17<00:00,  1.14it/s]
Total latency: 1157.099 s
Score: 0.979
Output throughput: 531.315 token/s
[METRIC] gsm8k_score=0.9786910197869102 labels={"model": "Qwen/Qwen3.8-Flash-Next-PTPC-FP8", "eval": "gsm8k"}
[METRIC] gsm8k_latency=1157.0990390350053 labels={"model": "Qwen/Qwen3.8-Flash-Next-PTPC-FP8", "eval": "gsm8k"}

Speed Tests and Profiling

 python3 -m pytest -q \
    test/registered/unit/layers/quantization/test_fp8_moe_weight_gating.py \
    -k 'fp8_ptpc_skips_aiter_shuffle_for_triton'

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

@apinge apinge changed the title add preshuffle flag for ptpc Add preshuffle flag for ptpc Sep 15, 2026
@apinge apinge changed the title Add preshuffle flag for ptpc Fixed the issue where FP8 PTPC failed to pass arguments to aiter. Sep 15, 2026
@apinge apinge changed the title Fixed the issue where FP8 PTPC failed to pass arguments to aiter. Fixed the issue where FP8 PTPC failed to pass correct args to aiter Sep 15, 2026
@apinge
apinge marked this pull request as ready for review September 15, 2026 09:05
@apinge
apinge requested review from sammysun0711 and a lite review from Copilot September 15, 2026 09:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 w13 and w2 weights 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.

Comment on lines +392 to +393
layer.w13_weight.is_shuffled = True
layer.w2_weight.is_shuffled = True

@apinge apinge Sep 15, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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 sammysun0711 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.

LGTM, let's merge it after related aiter pr ready.

@apinge apinge changed the title Fixed the issue where FP8 PTPC failed to pass correct args to aiter Fixed the issue where FP8 PTPC/BF16 MoE failed to pass correct args to aiter Sep 21, 2026
_should_use_aiter_moe = (
will_use_aiter_moe()
and self._aiter_ck_moe_supported(layer)
and not layer._skip_aiter_moe_shuffle

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

After removing the alignment requirement (i.e. physical_intermediate_size%128==0), TP2/TP4 MTP weights are also shuffled.

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.

Need to revisit here if we integrate qwen3.5 support in same sglang branch later.

@sammysun0711
sammysun0711 merged commit cc0c3c5 into qwen38-flash-next-amd-current-fix-install Sep 21, 2026
75 of 88 checks passed
@apinge
apinge deleted the qwen38-flash-next-moe-ptpc-preshuffle branch October 12, 2026 03:31
apinge added a commit that referenced this pull request Nov 6, 2026
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]>
apinge added a commit that referenced this pull request Nov 6, 2026
…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]>
apinge added a commit that referenced this pull request Nov 6, 2026
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]>
apinge added a commit that referenced this pull request Nov 6, 2026
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]>
apinge added a commit that referenced this pull request Nov 7, 2026
…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]>
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