Skip to content

Feat/v2 tune merge - #4410

Merged
charlieguo1106 merged 16 commits into
feat/dsv4-a8w4-mxmoe-v2-gemmfrom
feat/v2_tune_merge
Jul 29, 2026
Merged

charlieguo1106 merged 16 commits into
feat/dsv4-a8w4-mxmoe-v2-gemmfrom
feat/v2_tune_merge

Conversation

@Bernard-Liu

Copy link
Copy Markdown
Contributor

Motivation

Integrate FlyDSL v2 GEMM2 into the existing DSV4 A8W4/A4W4 MXMoE tuning and runtime paths, allowing the tuner to select the best implementation between native MXMoE GEMM2 and v2 GEMM2 while fixing tuning timeout and runtime dispatch issues.

Technical Details

Added FlyDSL v2 stage1/stage2 data generation, correctness validation, and candidate tasks to the FMoE tuner.
Added support for GEMM2 BN/BK values of 128/256, with invalid tiles filtered according to the actual shape.
Unified kernel-name parsing for native MXMoE and FlyDSL v2 GEMM2.
Automatically route stage2 to the native path or v2 path B based on kernelName2.
Align inter_dim according to the v2 GEMM2 BK during AOT generation.
Restrict tile_m=16 to the native SBM=16 layout.
Tighten the non-persistent GEMM2 grid size to avoid launching unnecessary blocks.
Add explicit validation for unsupported padded shards and invalid BN/BK configurations.
Fix the quant-sort benchmark to use the same HIP implementation as the runtime path.
Start multiprocessing tuner timeout tracking only when a task begins execution and reset timestamps when tasks are resubmitted.

Test Plan

Run the op_tests.tuning_tests.test_mp_tuner_logic unit tests.
Validate the following on a FlyDSL-supported GPU:
Stage1/stage2 correctness with FP8/FP4 activations and FP4 weights.
Atomic and reduce epilogues.
Candidate combinations with BN/BK = 128/256.
Runtime dispatch between native MXMoE and v2 path B.
Tuner output configurations and AOT parsing results.

Bernard-Liu and others added 15 commits July 27, 2026 14:56
Add coupled v2 gemm1/gemm2 candidate generation + selection to the main
fmoe tuner (gemm_moe_tune.py), so it can produce/pick flydslv2_moe2_*
kernels paired with a v2-output-layout gemm1:

- extract v2 gemm data-prep helpers into aiter/ops/flydsl/mxfp4_v2_tune_utils.py
- flydslv2 gemm2 name builder + full candidate generator in moe_kernels.py
- v2 stage1: time via flydsl_moe_stage1(v2_output_layout=True) over the full
  fused stage1 sweep; sorted-ref + dequant-cosine correctness helpers
- v2 stage2: mxfp4_moe_gemm2 candidates fed by a fixed (untimed) producer
- pair v2 gemm1<->gemm2 in post_process (v2 tag merge; skip us_quant_sort)
- guard mp_tuner generic res/ref reshape when a custom compare_fn is present
- glm5 fp4 tuned config refreshed for M=1,4,32,256,1024,4096,8192,16384
Preserve selected tiles through runtime and AOT so 128-aligned shapes dispatch the tuned kernel.
The fairness penalty added to non-fused stage1 kernels was timed against
the triton fused_dynamic_mxfp4_quant_moe_sort, but fused_moe_ resolves
that name to the aiter.ops.quant (HIP) implementation. Benchmark the one
that actually runs so the penalty reflects real cost.
tile_m=16 A-scale chunks are only valid when the sort block equals 16,
but the candidate list produced tile_m=16 for every sort block that is a
multiple of 16. Filter it at the source so callers cannot pick an
invalid re-tiling; block_m=16 (mxfp4 port path) is unaffected.
Cover both directions at the candidate source and at the tuner: block_m=16
must still offer tile_m=16 (native SBM16, used by the mxfp4 port path), and
any larger sort block must not. Both tests fail if the constraint is removed.
The stage2 forward picks path B purely from kernelName2's format, but no
test covered that hand-off. Characterize the parameters it derives so the
routing can be refactored safely.
kernelName2 was decoded by the same v2-or-mxmoe if/else in four places,
twice of them along the _mxfp4_a4w4_stage2_fw -> _mxfp4_a4w4_stage2 call
chain. Add parse_g2_kname_any as the single decode entry and lift the
path B hand-off up into the forward, so _mxfp4_a4w4_stage2 no longer
carries seven arguments that its path B branch ignored.
Resetting the start-time slots was a separate loop written at the pool
restart call site, so keeping it in sync with submitting was a convention
rather than a guarantee: a resubmit that skipped it would be measured
against the previous attempt's timestamp and time out on the first poll.
Fold the reset into submit_tasks so every submission path gets it.
_mxfp4_a4w4_stage2_fw forwarded cfg["BM"] as the v2 wrapper's block_m,
but that argument is the fallback the wrapper uses when the kernel name
carries no _sbm suffix. Passing tile_m made the fallback a tautology and
discarded the moe_sorting block the forward already receives, so a name
without _sbm paired with a larger sort block would resolve the wrong
expert per tile. Forward block_m instead.

The same hand-off never threads inter_dim_pad, so the v2 gemm2's has_pad
K-skip stays off and a pre-padded w2 would accumulate its pad columns
rather than skip them. The native gemm2 covers that case by baking
D_INTER_REAL into the kernel, while v2 exists precisely because K only
needs BK alignment, so an unpadded shard is the intended input here.
Fail loudly instead of returning a silently wrong result, and point at
the native gemm2 for pre-padded weights.
@zufayu
zufayu requested a review from coderfeli July 29, 2026 02:06
@charlieguo1106
charlieguo1106 merged commit 5d93b71 into feat/dsv4-a8w4-mxmoe-v2-gemm Jul 29, 2026
2 checks passed
@charlieguo1106
charlieguo1106 deleted the feat/v2_tune_merge branch July 29, 2026 06:31
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