Repository navigation
[FlyDSL] [Perf] MiniMax-M3 prefill scorer and sparse attention: per-forward launch plans - #8465
ganyi1996ppo wants to merge 1 commit into
Conversation
…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>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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) andmake_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 existingtensor_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 isbind+launch, so its checks and launch arguments are unchanged.ScorePrefillPlan/SparsePaPrefillPlan(+make_*factories, lazily exported fromaiter.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 raisesValueErroron any mismatch. The plan owns/keeps alive the batch tensors andout; 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_layoutandcheck_plan_operandhelpers (no second dispatch copy: the launch is still_run_compiled; the plan path usescurrent_raw_stream).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_perftestkernel time: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
New
op_tests/test_flydsl_prefill_launch_plan.py: 25 checks, all PASS on gfx950 (also contains the host-time / device-time sweep):Also re-run on the same card, unchanged and passing:
op_tests/test_flydsl_sparse_pa_nvfp4.py(PASSED 0 failures) andop_tests/test_flydsl_minimax_m3_index_score_prefill_fp4.py --case matches typed nvfp4 rejections(135 PASS, 0 FAIL).Documentation
Dependencies
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 callerout. 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.pyis 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