Repository navigation
Conversation
The gfx950 v4 nm auto split pick (ignore_total_kv=1) maximizes CU occupancy only, so it prefers whole multiples of cu_num: for gqa=128 single-token decode it picks 13-16 splits (several workgroup waves) for batches whose KV already fits one wave, paying extra partial writes and a wider stage-2 merge for no added parallelism. - On gfx950, pick num_kv_splits by minimizing a fitted latency model: workgroup waves x per-wave KV time, plus the partial-write/stage-2 cost of splitting. Other archs keep the existing pick. - Add kv_len_hint: callers that pass capacity-sized kv_page_indices (e.g. CUDA-graph decode) cannot be planned from total_kv / num_seqs, so they pass the per-seq KV length to plan for. The pick depends only on shapes and this int, so it stays fixed across graph capture and replay. - Fix the stage-2 merge for a caller-supplied split_indptr with one split per seq on a grid > 1: it took the in-place BF16 copy (keyed on split_indptr[-1] == num_seqs) although the kernel wrote FP32 partials, returning NaN. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: yihonglie <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Planning inside mla_decode_fwd_v4_nm needs a per-seq KV length, and the only one the wrapper can see, kv_page_indices.shape[0] / num_seqs, is meaningless for CUDA-graph callers whose index buffers are capacity-sized. - Add get_mla_v4_nm_split_plan(num_seqs, num_heads, kv_len, split_indptr=): returns the split count (cost model on gfx950, occupancy pick elsewhere) and fills a caller-owned persistent split_indptr in place. Callers build it in their metadata step and pass both to the wrapper. - Drop kv_len_hint; the wrapper's own auto pick is unchanged from main. - Tests: plan fill, accuracy through the wrapper, and CUDA-graph replay with different KV lengths under a captured plan. _run_varlen_point now returns its checkAllclose error so the new tests gate on it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: yihonglie <[email protected]>
- get_mla_v4_nm_split_plan returns MlaV4NmSplitPlan(num_kv_splits, split_indptr). The field names are the wrapper's kwargs, so callers pass a plan on as mla_decode_fwd_v4_nm(..., **plan._asdict()). - Latency-model coefficients live in a per-arch table; archs without an entry keep the occupancy-only pick. Only gfx950 is fitted. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: yihonglie <[email protected]>
|
Superseded by #6126, which now carries these commits (split plan helper, cost-model split count, stage-2 fix) together with the persistent V4-NM decode kernel, merged with current main. Closing in favour of that PR. |
Summary
get_mla_v4_nm_split_plan(num_seqs, num_heads, kv_len, *, split_indptr=None) -> MlaV4NmSplitPlan. New helper that builds the KV split plan formla_decode_fwd_v4_nm.MlaV4NmSplitPlan(num_kv_splits, split_indptr)is a NamedTuple whose field names are the wrapper's kwargs, so callers pass it on asmla_decode_fwd_v4_nm(..., **plan._asdict()).split_indptris the uniform[0, s, 2s, ...]. Given a caller-owned persistent buffer it is filled in place (one device launch, no host sync), so CUDA-graph callers keep the buffer alive across replays and rebuild the plan before each replay.num_seqs,num_headsand the caller'skv_len, never onkv_page_indices, whose length is meaningless for capacity-sized graph buffers.mla_decode_fwd_v4_nmis the same as main.split_indptrthat gives every seq one split on a grid > 1, the merge took the in-place BF16 copy (keyed onsplit_indptr[-1] == num_seqs) even though the kernel wrote FP32 partials, returning NaN. The v4 nm merge now always reduces the FP32 partials.Why planned callers should not rely on the old auto pick: it maximizes CU occupancy only, so for gqa=128 single-token decode it picks 13-16 splits (several workgroup waves) for batches whose KV already fits one wave, adding partial writes and stage-2 work without adding parallelism.
Consumer: DeepSeek-V4 FP8 decode in ATOM (ROCm/ATOM#2411).
Test plan
op_tests/test_mla_v4_nm.pyon gfx950 (MI355X): all passtest_v4_nm_split_planner_picks,test_v4_nm_split_plan_fills_buffer_in_place,test_v4_nm_split_plan_accuracy,test_v4_nm_split_plan_cudagraph_replay(plan captured once, replayed with different KV lengths),test_v4_nm_one_split_per_seq_on_wide_grid🤖 Generated with Claude Code