Repository navigation
[Build] Reuse preshuffle_on ck2stages modules for non-fp4 MoE and add PREBUILD_KERNELS=4 - #7243
AndreasKaratzas wants to merge 2 commits into
Conversation
…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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
DRAFT — evaluation pausedPR Self-ReviewRevision 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. |
There was a problem hiding this comment.
🟡 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_onmodules 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
| ( | ||
| "preshuffle_off" | ||
| if weight_dtype == dtypes.fp4x2 and not preshuffle_mode | ||
| else "preshuffle_on" | ||
| ), |
There was a problem hiding this comment.
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.
|
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
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:
|
|
Update: #7589 fixes #5766. I tested this PR on top of #7589 on MI300X (gfx942). The module was built with
The rename needs no change with #7589. After #7589 merges, I will rebase this PR and move it out of draft. |

Summary
Unshuffled fp8/bf16/i8 MoE callers load the prebuilt
preshuffle_onck2stages module instead of JIT-compiling a copy of it.PREBUILD_KERNELS=4is a new level that builds the most modules.This PR depends on #7589. Do not merge it before #7589.
Motivation
gen_instances.pyreads the preshuffle flag only for fp4x2 (A4W4). For all other weight dtypes,get_moe_stage_moduleemits the same codegen command forpreshuffle_onandpreshuffle_off. The two names are the same build. Wheels ship only thepreshuffle_onname. 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 modulespreshuffle_offonly for fp4x2 weights. Other dtypes resolve topreshuffle_on.is_shuffledstill goes to the kernel as before.setup.py: addPREBUILD_KERNELS=4(every non-tune module plus the level 1mha_varlen_fwdvariants, a superset of levels 1-3). Document all levels inget_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_fwdvariants, not six. Then theget_exclude_ops()docstring must say "four".docs/installation.rst: add level 4 to thePREBUILD_KERNELStable.Performance (if applicable)
Not applicable. No kernel changes. The change removes a JIT build of about 10 minutes per module on first use.
Testing
Documentation
Dependencies
Breaking Changes
None. Today any
PREBUILD_KERNELSvalue 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_offmodule. Wheels do not ship it, so the call JIT-compiles a module that is the same build as the prebuiltpreshuffle_onone.After: only fp4x2 uses the
preshuffle_offname. All other dtypes load the prebuiltpreshuffle_onmodule 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_funcvariants (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:inter_dim=192inter_dim=256preshuffle_on(what this PR loads)device_gemm ... does not support this GEMM problem)preshuffle_off(what main loads)gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128, got 192)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):
preshuffle_onandpreshuffle_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) andblack --checkpass.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?
module_moe_ck2stages_..._preshuffle_offto..._preshuffle_on. The codegen command is the same, so the binary is the same.PREBUILD_KERNELS=4is new and opt-in. Levels 0-3 build the same module sets as before.preshuffle_offmodule for a non-fp4x2 dtype is no longer used. The call loadspreshuffle_on(prebuilt, or JIT once if absent). The old directory stays on disk and is not deleted.Changed op tests
None.