Skip to content

[Build] Reuse preshuffle_on ck2stages modules for non-fp4 MoE and add PREBUILD_KERNELS=4 - #7243

Draft
AndreasKaratzas wants to merge 2 commits into
ROCm:mainfrom
AndreasKaratzas:akaratza_prebuild_all
Draft

AndreasKaratzas wants to merge 2 commits into
ROCm:mainfrom
AndreasKaratzas:akaratza_prebuild_all

Conversation

@AndreasKaratzas

@AndreasKaratzas AndreasKaratzas commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Unshuffled fp8/bf16/i8 MoE callers load the prebuilt preshuffle_on ck2stages module instead of JIT-compiling a copy of it. PREBUILD_KERNELS=4 is a new level that builds the most modules.

This PR depends on #7589. Do not merge it before #7589.

Motivation

gen_instances.py reads the preshuffle flag only for fp4x2 (A4W4). For all other weight dtypes, get_moe_stage_module emits the same codegen command for preshuffle_on and preshuffle_off. The two names are the same build. Wheels ship only the preshuffle_on name. Thus a caller with unshuffled fp8 weights (for example f8 silu per_tensor/per_token, Stage1 and Stage2) JIT-compiles a copy for about 10 minutes per module (#5766 (comment)).

Changes

  • aiter/ops/moe_op.py: name runtime ck2stages modules preshuffle_off only for fp4x2 weights. Other dtypes resolve to preshuffle_on. is_shuffled still goes to the kernel as before.
  • setup.py: add PREBUILD_KERNELS=4 (every non-tune module plus the level 1 mha_varlen_fwd variants, a superset of levels 1-3). Document all levels in get_exclude_ops().
    After [Build] [MHA] Stop flash_attn_varlen_func from dropping sequences with seqlen_q <= min_seqlen_q #7473 merges, level 1 keeps four mha_varlen_fwd variants, not six. Then the get_exclude_ops() docstring must say "four".
  • docs/installation.rst: add level 4 to the PREBUILD_KERNELS table.

Performance (if applicable)

Not applicable. No kernel changes. The change removes a JIT build of about 10 minutes per module on first use.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. Today any PREBUILD_KERNELS value other than 1-3 falls through to "exclude _tune", so defining 4 changes nothing for current users. Levels 1-3 keep the same module sets.

AI assistance (Claude Code) was used to draft this change. Every line was reviewed by the submitter.

PR Self-Review

Reviewed revision

60af5ff

Behavior and intent

Before: an unshuffled fp8/bf16/i8 ck2stages MoE call asks for the preshuffle_off module. Wheels do not ship it, so the call JIT-compiles a module that is the same build as the prebuilt preshuffle_on one.

After: only fp4x2 uses the preshuffle_off name. All other dtypes load the prebuilt preshuffle_on module at every non-zero prebuild level, with no extra build time. Level 4 gives one "build the most" setting.

Out of scope: MoE shapes outside the tuned configs and other gen_func variants (mha fwd/bwd suffixes, binary op dtype pairs) still JIT.

Validation and unverified scope

GPU, MI300X (gfx942), module built with GPU_ARCHS="gfx942;gfx950", unshuffled fp8 per_tensor Stage2, block_m=32:

Build inter_dim=192 inter_dim=256
aiter v0.1.27, prebuilt preshuffle_on (what this PR loads) FAIL (device_gemm ... does not support this GEMM problem) PASS
aiter v0.1.27, gfx942 JIT preshuffle_off (what main loads) PASS PASS
This PR alone FAIL (gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128, got 192) not run
This PR on top of #7589 PASS not run

So this PR alone regresses gfx942 in a multi-arch wheel. With #7589 it does not. This is the reason for the merge order.

CPU checks, on 3350c6d (Oct 31, before the later merges from main):

  • All 8 f8 silu per_tensor/per_token Stage1/Stage2 names (shuffled and unshuffled) resolve to a module in the prebuild set with the same codegen command. Main has 4 misses.
  • fp4x2 still maps to both preshuffle_on and preshuffle_off.
  • get_exclude_ops() levels 1-3 are unchanged (139/138/4 modules). Level 4 has 155 modules and contains every module of levels 1-3.
  • ruff check (0.16.0) and black --check pass.

Not verified:

PR-specific question

What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path?

  • Dependency: none added.
  • Compilation: for non-fp4x2 dtypes, the runtime module name changes from module_moe_ck2stages_..._preshuffle_off to ..._preshuffle_on. The codegen command is the same, so the binary is the same. PREBUILD_KERNELS=4 is new and opt-in. Levels 0-3 build the same module sets as before.
  • Cache: an existing JIT cache that has a preshuffle_off module for a non-fp4x2 dtype is no longer used. The call loads preshuffle_on (prebuilt, or JIT once if absent). The old directory stays on disk and is not deleted.
  • Clean build: verified only by the module-set counts above (CPU) and the MI300X module build. A full clean wheel build at the current head is not verified.
  • Existing-cache path: not verified at the current head.

Changed op tests

None.

…nd add PREBUILD_KERNELS=4

The ck2stages codegen only reads the preshuffle flag for fp4x2 weights,
so for every other dtype the preshuffle_on and preshuffle_off modules
are identical builds. Name them preshuffle_on at runtime unless the
weights are fp4x2, so unshuffled fp8/bf16/i8 callers load the prebuilt
module instead of JIT-compiling a duplicate. is_shuffled is still passed
to the kernel at runtime.

Add PREBUILD_KERNELS=4, which builds every non-tune module plus the
level 1 mha_varlen_fwd variants, a superset of levels 1-3. Variants
outside the tuned configs and other gen_func variants still JIT.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7243 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Oct 31, 2026 •

Copy link
Copy Markdown

DRAFT — evaluation paused

PR Self-Review

Revision 60af5ff318e8 · mode shadow

This pull request is a draft, so readiness evaluation is paused and no verdict applies. Evaluation resumes when it is marked ready for review and the required CI completes.

@github-actions github-actions Bot changed the title [JIT] [Build] Reuse preshuffle_on ck2stages modules for non-fp4 MoE and add PREBUILD_KERNELS=4 [Build] Reuse preshuffle_on ck2stages modules for non-fp4 MoE and add PREBUILD_KERNELS=4 Nov 5, 2026
@github-actions github-actions Bot added the Build label Nov 5, 2026
@zufayu
zufayu requested a review from valarLip November 6, 2026 00:54
@azaidy
azaidy requested a balanced review from Copilot November 6, 2026 19:28

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.

🟡 Changes recommended

The alias redirects gfx942 unshuffled fp8 calls to gfx950 prebuilt tables, rejecting valid gfx942 configurations because the prerequisite per-architecture table fix is missing.

1 open issue
What changed in this PR

This PR reduces duplicate MoE compilation by aligning non-fp4 runtime module names with prebuilt modules, and adds a broader prebuild option.

Changes:

  • Reuse preshuffle_on modules for non-fp4 weights while preserving distinct fp4 naming.
  • Add PREBUILD_KERNELS=4, combining non-tuning modules with level 1’s variable-length attention variants.
  • Document prebuild levels and the remaining runtime compilation limits.
File Description
setup.py Enables level 4 attention variants and documents prebuild behavior.
docs/​installation.rst Adds level 4 to the environment-variable table.
aiter/​ops/​moe_op.py Aligns non-fp4 module names with prebuilt artifacts.

Review effort: Balanced

Comment thread aiter/ops/moe_op.py
Comment on lines +639 to +643
(
"preshuffle_off"
if weight_dtype == dtypes.fp4x2 and not preshuffle_mode
else "preshuffle_on"
),

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.

Agreed, this is the #5766 problem. On MI300X (gfx942), with the module built for GPU_ARCHS="gfx942;gfx950", I ran unshuffled fp8 per_tensor Stage2 with block_m=32 and inter_dim=192. This branch alone fails with gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128, got 192. The same branch on top of #7589 passes. #7589 gives each arch its own ck2stages table, so the rename itself does not need to change. The fix comes from rebasing on #7589. The PR stays in draft until #7589 merges, and then I will rebase it.

@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

Status: blocked on #5766. I am moving this PR to draft.

The Copilot comment is correct. I reproduced it on MI300X (gfx942) with aiter v0.1.27 built for GPU_ARCHS="gfx942;gfx950". Case: fp8 per_tensor stage2, block_m=32.

Module inter_dim Result
prebuilt preshuffle_on (used after this PR) 192 device_gemm ... does not support this GEMM problem
prebuilt preshuffle_on 256 pass
gfx942 JIT preshuffle_off (used today) 192 pass

The prebuilt modules carry the gfx950 instance table (#5766). Today, unshuffled fp8 callers on gfx942 miss the prebuilt name and JIT the gfx942 table. This is slow but correct. With the rename, these callers load the gfx950 table and some valid shapes fail.

After the per-arch table fix for #5766 merges, I will:

  • Rebase on that fix. If the fix keeps one module per name and selects the table at runtime (like fix(ck_gemm): fix multi-arch build targeting and kernel dispatch across all CK GEMM modules #2645 for CK GEMM), the rename needs no change. If the fix adds the arch to the module name, I will keep the arch part and remove only the preshuffle part for non-fp4 weights.
  • Build a gfx942;gfx950 wheel and run the case above again. The unshuffled fp8 call with inter_dim=192 must load the prebuilt module and pass on gfx942.
  • Remove the dependency note from the description, add these results, and move the PR out of draft.

@AndreasKaratzas
AndreasKaratzas marked this pull request as draft November 6, 2026 21:11
@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

Update: #7589 fixes #5766. I tested this PR on top of #7589 on MI300X (gfx942). The module was built with GPU_ARCHS="gfx942;gfx950". Case: unshuffled fp8 per_tensor stage2, block_m=32, inter_dim=192.

Branch Result
this PR gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128, got 192
this PR on #7589 pass

The rename needs no change with #7589. After #7589 merges, I will rebase this PR and move it out of draft.

@zufayu
zufayu removed the request for review from valarLip November 7, 2026 00:03
@AndreasKaratzas
AndreasKaratzas marked this pull request as ready for review November 30, 2026 22:14
@zufayu
zufayu self-requested a review December 1, 2026 04:28
@AndreasKaratzas
AndreasKaratzas marked this pull request as draft December 3, 2026 17:49
@zufayu
zufayu removed their request for review December 3, 2026 23:06

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants