Skip to content

[FlyDSL] [Perf] MiniMax-M3 prefill scorer and sparse attention: per-forward launch plans - #8465

Draft
ganyi1996ppo wants to merge 1 commit into
ROCm:mainfrom
ganyi1996ppo:ganyi/flydsl-prefill-launch-plan
Draft

ganyi1996ppo wants to merge 1 commit into
ROCm:mainfrom
ganyi1996ppo:ganyi/flydsl-prefill-launch-plan

Conversation

@ganyi1996ppo

Copy link
Copy Markdown
Contributor

Summary

Per-forward launch plans for the MiniMax-M3 NVFP4 prefill path: make_score_prefill_plan (index scorer, score_prefill_flydsl, fp8 / MXFP4 / NVFP4 caches) and make_sparse_pa_prefill_plan (sparse_pa_nvfp4_prefill). The ragged batch, the geometry and the launch argument list are validated and built once per forward pass; each layer's call only swaps the operand pointers and launches through the existing tensor_shim._run_compiled. The plain entry points keep their signatures and defaults.

Motivation

A prefill forward calls the scorer and the attention once per layer (60 layers) with the same batch. Every call re-runs the shape/dtype/stride/alignment checks, the geometry selection and the argument-list construction in Python. For short prefill chunks the forward is host-bound, so this Python is on the critical path; the kernels themselves do not change.

Changes

  • minimax_m3_index_score_prefill.py, sparse_pa_nvfp4_prefill.py: the body of each entry point is split into _bind_* (all validation + everything layer-independent) and _launch_* (pointer swap + launch). The plain entry point is bind + launch, so its checks and launch arguments are unchanged.
  • New ScorePrefillPlan / SparsePaPrefillPlan (+ make_* factories, lazily exported from aiter.ops.flydsl). A plan call compares each per-layer operand against the layout the plan was built from (tensor_layout: dtype, device, shape, strides; plus base alignment) and raises ValueError on any mismatch. The plan owns/keeps alive the batch tensors and out; raw pointers, contents are read at launch (same contract as the plain call), no allocation or host sync per call, usable under graph capture with pointer-stable buffers.
  • tensor_shim.py: tensor_layout and check_plan_operand helpers (no second dispatch copy: the launch is still _run_compiled; the plan path uses current_raw_stream).
  • A scale left out of a sparse-attention plan call means one, exactly as in the plain call.

Performance (if applicable)

Host-side time of one call with the compiled launcher replaced by a no-op (so it is the Python in front of the kernel), 300 calls, MI355X (gfx950) node, one GPU; device time is the usual run_perftest kernel time:

Hardware Workload/configuration Before (host us) After (host us) Change
MI355X scorer nvfp4 e4m3/exact, b=1..4, q=512/2048, ctx=8192 43-44 8-9 about -35 us/call
MI355X sparse attention prefill, q=512/2048, ctx=8192, Hkv=1/4 16-18 6.7-8.3 about -9.5 us/call

Device time is unchanged within noise (e.g. scorer b=4 q=512 exact 11.7 us direct vs 11.0 us plan; attention q=2048 Hkv=4 281.5 vs 280.6 us). Across 60 layers this is roughly 2.6 ms of host time per forward (an extrapolation of the per-call numbers, not an end-to-end measurement); it only shows up where the forward is host-bound (short chunks); no gain for long chunks. No e2e/server run was done.

Testing

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

New op_tests/test_flydsl_prefill_launch_plan.py: 25 checks, all PASS on gfx950 (also contains the host-time / device-time sweep):

python op_tests/test_flydsl_prefill_launch_plan.py                       # checks + perf tables
python op_tests/test_flydsl_prefill_launch_plan.py --case plan lazy      # checks only

Also re-run on the same card, unchanged and passing: op_tests/test_flydsl_sparse_pa_nvfp4.py (PASSED 0 failures) and op_tests/test_flydsl_minimax_m3_index_score_prefill_fp4.py --case matches typed nvfp4 rejections (135 PASS, 0 FAIL).

Documentation

  • Docstrings updated

Dependencies

  • No new third-party dependencies added

Breaking Changes

None.

PR Self-Review

Behavior and intent

Plain entry points: identical checks and launch arguments (refactor into bind + launch). New: plan objects that give bit-identical results to the plain call for operands of the validated layout and refuse any other layout.

Validation and unverified scope

gfx950 only (the kernels are gfx950). Bit-identical (torch.equal) vs the plain call for: NVFP4 e4m3 and exact, bf16 and e4m3 Q, ragged batches, two heads, MXFP4 with typed fp4x2/e8m0 views, fp8 cache, sparse attention Hkv 1/4, group 8/16, tq/rounds 1/1 and 4/2 and auto, two different layers per plan and layers revisited, plan-owned and caller out. Rejection checks cover rank/shape/dtype/device/alignment/scale operands. Not verified: CUDA-graph capture of a plan call, MI300X/MI250X (not supported by the kernels), end-to-end model runs.

Changed op tests

op_tests/test_flydsl_prefill_launch_plan.py is new: plan == plain call bit for bit (not covered elsewhere because the plan did not exist), per-layer layout rejection, lazy-export sanity, and host/device timing of plan vs plain.

🤖 Generated with Claude Code

…launch plans

Validate the ragged batch, pick the geometry and build the launch argument list
once per forward pass; a layer's call only swaps the operand pointers. The plain
entry points are unchanged: they bind and launch through the same helpers.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8465 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant