Skip to content

[ASM] [HIP] feat(pa): add opt-in prefix-budget metadata planner - #6815

Merged
fangche123 merged 15 commits into
mainfrom
chefang/pa_metadata_load_balance
Oct 29, 2026
Merged

fangche123 merged 15 commits into
mainfrom
chefang/pa_metadata_load_balance

Conversation

@fangche123

@fangche123 fangche123 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Add GPU prefix-budget planning behind fast_mode=False while preserving the default v1_2 and PA ASM metadata ABI. Bound worker loads and avoid splitting work within the same persistent worker.

Add capacity sizing, metadata/graph regression coverage, and paired benchmark diagnostics adapted to current main and its page16 ASM reducer.

Validation: 12 metadata cases and 12 graph refreshes passed after a clean JIT rebuild; page256 paired smoke and targeted lint passed. Page16 GQA8/qlen1 baseline correctness failure remains unresolved.

Motivation

PA persistent-scheduling (PS) metadata generation for MiniMax-style decode was a serial single-block kernel, and its cost grew with batch size. This PR adds a parallel generation path for page size 16 and keeps the serial path as the fallback. It also ships rebuilt MTP PS attention kernels, which were the next bottleneck: the Q2–Q4 gfx950 kernel was spending most of its time in a per-task fixed cost and in a full-width tail tile.

Technical Details

PA persistent scheduling for gfx950 (pa_metadata v1_2 + MTP PS attention):

  • Metadata generation: the v1_2 generator gets an internal parallel path (shared-block path for B <= 512, four-launch chunked path for 513 <= B <= 32768). It is enabled only when block_size == kv_granularity == 16, the dispatch is dense with a single Q tile, and the full CU worker budget and buffers are available. Everything else (page size 1024, reduced budget, sparse input, ...) falls back to the unchanged serial generator, which produces the same effective work/reduction layout. fast_mode=False forces serial.
  • Attention code objects: the four page-16 GQA16 per-token-FP8 MTP persistent kernels pa_{bf16,fp16}_pertokenFp8_gqa16_1tg_4w_mtp_msk{0,1}_ps.co are rebuilt from an optimized SP3. The tail tile is dispatched by its valid 64-column groups (masked groups skip QK/softmax/PV), causal zeroing is a scalar branch, per-row scales use packed fp32 ops with Q kept in AGPR, row-max reductions and the epilogue are batched. Output is bit-identical to the previous code objects.
  • Metadata layout, reducer and all other code objects are unchanged.

Test Plan

  • Strict output check (every element within atol=rtol=0.01, before and after timing, NaN/sentinel-filled buffers) on 139 BF16/FP8 stress configs and 72 dtype/page/mask configs, main vs this PR.
  • Native op_tests/test_pa_ps.py grids (page 16 / 1024, bf16 / fp16, fp8 / int8 KV, per-block 256 / 1024, non-quantized): 3564 rows over both revisions.
  • Serial vs parallel metadata: identical active work_indptr / work_info and reduction maps, graph-replay refresh, guard regions, boundary batches (B512/513, B32769), legacy buffer sizes.
  • ASM code objects vs previous code objects: 24 bit-exactness cases (tails of 1..255 valid tokens, Q2/3/4) plus 8 Q1 cases, and a 336-config test_pa_ps.py sweep.

Performance

gfx950 (MI355X, 256 CUs), GPU clocks not locked, 3 alternating rounds x 101 profiled iterations x 8 rotated tensor sets, medians, geometric mean of ratios over strict-pass pairs. Main = bbef5a6f2, PR = 5ea9d4e0a.

1. Metadata generation time (main -> PR, us)

Shape (page 16) Main PR Speedup
B1 / C1024 / Q1 26.1 6.5 4.0x
B16 / C4096 / Q4 100.5 7.4 13.7x
B200 long, Hkv1, Q4 175.5 9.9 17.7x
B513 short, Hkv8, Q4 1227.2 24.2 50.7x
NPZ deep_32768 8965.4 58.3 153.9x

Geometric mean over the 139-case stress suite: page 16 (93 valid pairs) 14.8x metadata, 3.81x total (metadata + attention + reduce). Page 1024 keeps the serial generator and is unchanged (1.01x), because the parallel launch has a fixed cost of about 4.7-7 us and loses below roughly 8 work items.

2. Attention code objects (old .co -> new .co, same run, test_pa_ps.py --profile)

Variant Attention kernel (mean us) Attention change Attention + reduce change
bf16 causal (msk1) 34.52 -> 29.45 -14.97% -12.02%
fp16 causal (msk1) 34.71 -> 29.63 -15.04% -11.87%
bf16 non-causal (msk0) 32.18 -> 28.28 -12.39% -9.89%
fp16 non-causal (msk0) 32.42 -> 28.51 -12.35% -9.92%

96 of 96 variant/shape pairs are faster (page 16, Hq/Hkv 16/1, context 282/1024/4097/8192, batch 64/158, Q2-4). By Q length (bf16 causal): Q2 -11.7%, Q3 -14.7%, Q4 -18.3%. Long contexts gain less (32 x 32768, Q2 -3%).

3. End to end (main -> PR, geometric mean)

Suite Metadata Attention Reduce Total
139-case stress (121 valid pairs) 7.96x 1.066x 1.028x 2.80x
page 16, GQA16 (79 pairs) 12.86x 1.100x 1.021x 3.95x
72-case dtype/page/mask 8.29x 1.032x 1.015x 2.53x

Correctness: stress 130/139 strict (main 121/139; 9 cases fixed, 0 new failures; the 9 shared failures are tiny-context shapes and bands_32768), dtype/page/mask 72/72, native grids 3564 rows with max mismatch 4.46% (limit 5%).

Limits: clocks not locked; page 1024 gets no metadata gain; no full-model measurement.

Submission Checklist

Add GPU prefix-budget planning behind fast_mode=False while preserving the default v1_2 and PA ASM metadata ABI. Bound worker loads and avoid splitting work within the same persistent worker.

Add capacity sizing, metadata/graph regression coverage, and paired benchmark diagnostics adapted to current main and its page16 ASM reducer.

Validation: 12 metadata cases and 12 graph refreshes passed after a clean JIT rebuild; page256 paired smoke and targeted lint passed. Page16 GQA8/qlen1 baseline correctness failure remains unresolved.
@fangche123
fangche123 requested review from a team and a balanced review from Copilot October 22, 2026 02:22
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 6815 --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.

@github-actions github-actions Bot changed the title feat(pa): add opt-in prefix-budget metadata planner [HIP] feat(pa): add opt-in prefix-budget metadata planner Oct 22, 2026
@github-actions github-actions Bot added the HIP label Oct 22, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

ruff

⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

actual_works = buffers[2][: len(expected_works)].cpu().tolist()


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable batch

if batch == 32 and heads == 8 and workers == 256 and max(current_lengths) == 257:


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable heads

if batch == 32 and heads == 8 and workers == 256 and max(current_lengths) == 257:


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

assert int(buffers[1][-1].item()) == 256, "uniform workload must not be oversplit"


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

assert buffers[3][-1].item() == 0, "uniform workload should write output directly"


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable batch

if batch == 32 and heads == 8 and workers == 256 and max(current_lengths) == 70612:


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable heads

if batch == 32 and heads == 8 and workers == 256 and max(current_lengths) == 70612:


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

actual_offsets = buffers[1].cpu().tolist()


⚠️ [ruff] <RUF007> reported by reviewdog 🐶
Prefer itertools.pairwise() over zip() when iterating over successive pairs

for begin, end in zip(actual_offsets, actual_offsets[1:])


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable batch

assert actual_works == expected_works, (batch, heads, cap, "works")


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable heads

assert actual_works == expected_works, (batch, heads, cap, "works")


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable cap

assert actual_works == expected_works, (batch, heads, cap, "works")


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

assert buffers[1].cpu().tolist() == expected_indptr, (


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable batch


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable heads


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable cap


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

assert buffers[3].cpu().tolist() == reduce_offsets, (


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable batch


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable heads


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable cap


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

assert buffers[4].cpu().tolist() == list(


⚠️ [ruff] <RUF007> reported by reviewdog 🐶
Prefer itertools.pairwise() over zip() when iterating over successive pairs

map(list, zip(qo_offsets[:-1], qo_offsets[1:]))


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qo_offsets

map(list, zip(qo_offsets[:-1], qo_offsets[1:]))


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qo_offsets

map(list, zip(qo_offsets[:-1], qo_offsets[1:]))


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

assert buffers[5][: len(partial_map)].cpu().tolist() == partial_map


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

assert buffers[0].cpu().tolist() == [


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

buffers[1].data_ptr(),


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

buffers[2].data_ptr(),


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qo_lengths

assert partial_before <= capacity * max(qo_lengths)


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable guards

assert all(torch.all(guard == 777).item() for guard in guards)


⚠️ [ruff] <PLC0206> reported by reviewdog 🐶
Extracting value from dictionary without calling .items()

for mode in samples:


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qo


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable kv


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable context

context,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable query_heads

query_heads // kv_heads,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable kv_heads

query_heads // kv_heads,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable kv_heads

kv_heads,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

*buffers,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable page_size

kv_granularity=page_size,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable page_size

block_size=page_size,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qlen

max_seqlen_qo=qlen,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qlen

uni_seqlen_qo=qlen,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable fast_mode

fast_mode=fast_mode,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable query


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable key


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable value


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable kv


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable indices

indices,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable context

context,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable scale


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qlen

max_qlen=qlen,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable key_scale

K_QScale=key_scale,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable value_scale

V_QScale=value_scale,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable output

out_=output,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qo

qo_indptr=qo,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

work_indptr=buffers[1],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

work_info=buffers[2],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable partial

splitData=partial,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable partial_lse

splitLse=partial_lse,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable quant_type

quant_type=quant_type,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable reduce_fn

reduce_fn(


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable partial

partial,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable partial_lse

partial_lse,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

buffers[3],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

buffers[4],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

buffers[5],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qlen


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable output

output,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable final_lse

final_lse,


⚠️ [ruff] <RUF007> reported by reviewdog 🐶
Prefer itertools.pairwise() over zip() when iterating over successive pairs

for begin, end in zip(work_offsets, work_offsets[1:])


⚠️ [ruff] <RUF007> reported by reviewdog 🐶
Prefer itertools.pairwise() over zip() when iterating over successive pairs

end - begin for begin, end in zip(work_offsets, work_offsets[1:])

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Benchmark defaults and architecture filtering need correction, and the new planner regressions are not exercised by the normal CI path.

3 open issues
What changed in this PR

Adds an opt-in GPU prefix-budget planner for persistent paged attention, preserving the default v1_2 path and existing ASM metadata ABI.

Changes:

  • Adds budget-based work partitioning and a same-stream metadata finalizer.
  • Extends buffer sizing and documents the fast_mode=False contract.
  • Adds metadata/graph regression checks and paired benchmark diagnostics.
File Description
op_tests/​test_pa_ps.py Adds planner selection, regression checks, and paired benchmarks.
csrc/​kernels/​mla/​metadata/​v1_1_pa_device.cuh Implements prefix-budget planning, finalization, and input checks.
csrc/​kernels/​mla/​metadata.cu Dispatches between planners using fast_mode.
aiter/​ops/​attention.py Adds planner-aware capacity sizing and API documentation.

Review effort: Balanced

Comment thread op_tests/test_pa_ps.py Resolved
Comment thread op_tests/test_pa_ps.py Resolved
Comment thread op_tests/test_pa_ps.py Resolved
Rebuild eight BF16/FP16 page16 persistent attention variants from the native MI350 SP3 templates. FP8 decode uses K128 MFMA; MTP changes are ELF symbols only, and INT8 decode preserves matrix arithmetic with reordered prologue self-moves. Keep the PR/main reducers unchanged.

Validation: committed blobs match the previously validated native artifacts; PA metadata/graph, page16 correctness, and mixed-context performance checks passed. No universal speedup is claimed.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 08:52
@github-actions github-actions Bot changed the title [HIP] feat(pa): add opt-in prefix-budget metadata planner [ASM] [HIP] feat(pa): add opt-in prefix-budget metadata planner Oct 22, 2026
@github-actions github-actions Bot added the ASM label Oct 22, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

ruff

⚠️ [ruff] <PLC0206> reported by reviewdog 🐶
Extracting value from dictionary without calling .items()

for mode in samples:


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qo


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable kv


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable context

context,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable query_heads

query_heads // kv_heads,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable kv_heads

query_heads // kv_heads,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable kv_heads

kv_heads,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

*buffers,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable page_size

kv_granularity=page_size,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable page_size

block_size=page_size,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qlen

max_seqlen_qo=qlen,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qlen

uni_seqlen_qo=qlen,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable fast_mode

fast_mode=fast_mode,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable query


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable key


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable value


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable kv


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable indices

indices,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable context

context,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable scale


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qlen

max_qlen=qlen,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable key_scale

K_QScale=key_scale,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable value_scale

V_QScale=value_scale,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable output

out_=output,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qo

qo_indptr=qo,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

work_indptr=buffers[1],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

work_info=buffers[2],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable partial

splitData=partial,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable partial_lse

splitLse=partial_lse,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable quant_type

quant_type=quant_type,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable reduce_fn

reduce_fn(


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable partial

partial,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable partial_lse

partial_lse,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

buffers[3],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

buffers[4],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable buffers

buffers[5],


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable qlen


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable output

output,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable final_lse

final_lse,


⚠️ [ruff] <RUF007> reported by reviewdog 🐶
Prefer itertools.pairwise() over zip() when iterating over successive pairs

for begin, end in zip(work_offsets, work_offsets[1:])


⚠️ [ruff] <RUF007> reported by reviewdog 🐶
Prefer itertools.pairwise() over zip() when iterating over successive pairs

end - begin for begin, end in zip(work_offsets, work_offsets[1:])

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new GPU scheduling path needs human review, particularly because the reported page16 baseline correctness failure leaves end-to-end validation incomplete.

4 open issues

Review effort: Balanced

Comment thread op_tests/test_pa_ps.py Resolved
Copilot AI balanced review requested due to automatic review settings October 23, 2026 07:02
@github-actions github-actions Bot changed the title [ASM] [HIP] feat(pa): add opt-in prefix-budget metadata planner [ASM] [HIP] [CI] feat(pa): add opt-in prefix-budget metadata planner Oct 23, 2026
@github-actions github-actions Bot added the CI label Oct 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

CI does not yet validate end-to-end attention outputs using the new planner.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Add v1_1 attention-output correctness coverage to CI

.github/​scripts/​aiter_test.sh:175

--test-metadata-v1-1 only checks metadata arrays and graph refreshes, then exits. The following invocation defaults to --metadata-mode v1_2, so neither CI command checks attention outputs produced using the new planner. An incompatibility in direct-output handling or partial-output/reduction addressing could therefore pass this job. Retain the baseline run and add a bounded v1_1 correctness grid covering direct and split/reduced work. The suggested page256/page1024 grid uses the existing attention-output comparison and avoids the unresolved page16 baseline case.

3 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 23, 2026 08:06
@github-actions github-actions Bot changed the title [ASM] [HIP] [CI] feat(pa): add opt-in prefix-budget metadata planner [ASM] [HIP] feat(pa): add opt-in prefix-budget metadata planner Oct 23, 2026
@github-actions github-actions Bot removed the CI label Oct 23, 2026
Generate PA v1_2 metadata with parallel kernels for dense single-Q-tile inputs (fast_mode=True, up to 32768 requests) and keep the serial generator as the fallback. Remove the separate PA v1_1 planner and its test selector.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 06:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The planner dispatch reverses the advertised opt-in behavior, and the chunked path lacks regression coverage for request-count boundaries, metadata capacity, and graph replay with changed context lengths.

3 open issues
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 07:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The planner dispatch reverses the advertised opt-in contract and changes the default execution path, while the new multi-chunk pipeline lacks regression coverage for boundary indexing and graph metadata refresh.

2 open issues
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new large-batch planner lacks automated boundary, buffer-safety, and replay regression coverage, while its reversed fast_mode gate switches existing callers despite the documented opt-in contract.

2 open issues

Review effort: Balanced

Page size 1024 and other sizes keep the serial generator: the parallel launch has a fixed cost that is slower for few work items (B1/C1024/Q1 metadata 2.47 us serial vs 4.71 us parallel).
Copilot AI balanced review requested due to automatic review settings October 28, 2026 09:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The planner dispatch reverses the advertised opt-in and changes default behavior, while committed tests lack coverage for the new page16 path, chunk boundaries, and graph replays with changed context lengths.

2 open issues

Review effort: Balanced

Rebuild the four pa_{bf16,fp16}_pertokenFp8_gqa16_1tg_4w_mtp_msk{0,1}_ps.co from an optimized MTP SP3: tail tile only processes the 64-column groups that hold valid tokens, causal zeroing is a scalar branch, packed fp32 math for scale/softmax/accumulate, batched wave reductions, and a cheaper epilogue. Outputs are bit-identical to the previous .co on the validation shapes; test_pa_ps error statistics match across bf16/fp16 x causal/non-causal x qlen 1-4. On MI355 the attention kernel is 12-15% faster (up to ~23% for qlen 4, ctx<=1024) and pa_persistent_fwd 10-12% faster.
Copilot AI balanced review requested due to automatic review settings October 29, 2026 03:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Multi-tile reduction writes can exceed allocated buffers, while the new planner reverses the advertised opt-in behavior and lacks committed regression coverage.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@zufayu

zufayu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

ROCm/aiter PR #6815 — [ASM] [HIP] feat(pa): add opt-in prefix-budget metadata planner

Adds a parallel CU-budget-planned generation path for the v1_2 PA persistent-scheduling metadata (one 512-thread block for up to 512 requests, four chunked launches up to 32768) behind fast_mode=True for page-16 dense decode, replaces eight gfx950 page-16 GQA16 attention code objects with rebuilt binaries, and re-gates the serial fallback generator's reduce-map writes.

Review (advisory): 🔴 HIGH RISK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0); the single test target op_tests/test_pa_ps.py existed but produced no report, and this box has no torch install or gfx950 GPU to run it by hand (environment gap, not a PR defect).
Perf (advisory): NOT RUN — no validation report (REVIEW_AUTO_VALIDATE=0) and no MI355X/torch environment here to hand-run python3 op_tests/test_pa_ps.py base vs head; the PR's own MI355X numbers (metadata 14.8x geomean on page 16, attention −12 to −15%) are unverified here.

🔴 [verified] csrc/kernels/mla/metadata/v1_2_pa_device.cuh:559-568,639-640 re-gates the serial fallback generator's reduce-map writes from lane 0 to split 0 and advances the entry counter by num_qo_tiles per split batch, changing fallback output for multi-QO-tile or >64-split batches — inputs that never reach the new parallel path — while the PR body calls this generator "unchanged"; aiter/ops/attention.py:1002-1003 still sizes reduce_indptr/reduce_final_map at batch_size+1/batch_size, so a public-API input like B=64, page 1024, num_heads_per_head_k=128, qlen=16 (16 QO tiles per batch) with ≥5 split batches writes ≥80 entries into the 65-entry reduce_indptr — an out-of-bounds write where the old code wrote one entry per split batch — and the PR's own op_tests/test_pa_ps.py grid (qlen 1-4, GQA8/10, contexts ≤10240) is single-tile with ≤~4 splits, so no test in the suite can distinguish old from new serial output. Author must resize reduce_indptr/reduce_final_map for the per-tile layout (or gate the per-tile writes to tile-count-sized buffers), add a multi-tile split regression case, and correct the "unchanged serial generator" claim.

🔴 [verified] aiter/ops/attention.py is a Tier-2 downstream-facing contract and this PR changes its behavior — get_pa_metadata_info_v1's allocation grows for 512<batch≤32768 and the fast_mode=True default silently flips page-16 dense decode onto the new parallel generator, on top of the serial fallback's layout change — yet the de-facto owner of both this file and csrc/kernels/mla/metadata/ is minmengdie (top committer, 17 commits on each) and the PR carries no sign-off from them. Reviewer must @-mention minmengdie in a PR comment requesting explicit sign-off before merge, on top of green CI.

⚠️ [verified] The diff rebuilds eight hsa/gfx950/pa code objects but the PR body documents only the four MTP kernels (pa_bf16_pertokenFp8_gqa16_1tg_4w_mtp_msk0_ps.co and its fp16/msk1 siblings) and states "all other code objects are unchanged", while hsa/gfx950/pa/pa_bf16_pertokenFp8_gqa16_2tg_4w_ps.co, hsa/gfx950/pa/pa_fp16_pertokenFp8_gqa16_2tg_4w_ps.co, hsa/gfx950/pa/pa_bf16_pertokenInt8_gqa16_2tg_4w_ps.co and hsa/gfx950/pa/pa_fp16_pertokenInt8_gqa16_2tg_4w_ps.co — the non-MTP GQA16 page-16 decode kernels (fp8 and int8 KV) that hsa/gfx950/pa/pa_asm.csv selects for the serving path — also change with no stated reason. Author must state why the four non-MTP code objects were rebuilt and confirm the bit-exactness and 336-config sweeps cover them.

⚠️ [verified] The PR's own validation line admits "Page16 GQA8/qlen1 baseline correctness failure remains unresolved", and page-16 GQA8 qlen-1 dense decode is exactly the input class the new parallel generator takes over (block_size=kv_granularity=16, single Q tile, num_heads_k=2 dividing 256 CUs), so if that failure reproduces on this PR the headline path ships with a known correctness failure in a default-grid config. Author must state whether the failure reproduces on main, on this PR, or both, and whether it gates merge.

⚠️ [verified] The PA PS metadata path is the MiniMax-style decode path this PR's own motivation names, and downstream serving stacks consume the changed aiter/ops/attention.py get_pa_metadata_v1 contract to plan it, but the PR carries only HIP/ASM labels and no ci:atom/ci:sglang/ci:vllm label, so every downstream job is skipped and a metadata regression would only surface after merge. Reviewer should ask for a ci:all (or the minimal ci:vllm/ci:sglang) run green before merge.

@aiter-bot

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 5ea9d4e0a219 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_pa_ps.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@fangche123
fangche123 merged commit a24724e into main Oct 29, 2026
74 of 76 checks passed
@fangche123
fangche123 deleted the chefang/pa_metadata_load_balance branch October 29, 2026 14:45
solinzby1 pushed a commit that referenced this pull request Nov 2, 2026
* feat(pa): add opt-in prefix-budget metadata planner

Add GPU prefix-budget planning behind fast_mode=False while preserving the default v1_2 and PA ASM metadata ABI. Bound worker loads and avoid splitting work within the same persistent worker.

Add capacity sizing, metadata/graph regression coverage, and paired benchmark diagnostics adapted to current main and its page16 ASM reducer.

Validation: 12 metadata cases and 12 graph refreshes passed after a clean JIT rebuild; page256 paired smoke and targeted lint passed. Page16 GQA8/qlen1 baseline correctness failure remains unresolved.

* build(pa): refresh gfx950 GQA16 PS code objects

Rebuild eight BF16/FP16 page16 persistent attention variants from the native MI350 SP3 templates. FP8 decode uses K128 MFMA; MTP changes are ELF symbols only, and INT8 decode preserves matrix arithmetic with reordered prologue self-moves. Keep the PR/main reducers unchanged.

Validation: committed blobs match the previously validated native artifacts; PA metadata/graph, page16 correctness, and mixed-context performance checks passed. No universal speedup is claimed.

* fix(pa): resolve metadata test CI lint failures

* test(pa): simplify persistent attention test integration

* perf(pa): align v1_1 partitions with PR5546 and balance persistent workers

Split work by 256-token KV tiles using prefix quotas (partition cap is the
device CU count), keeping the PA ASM interface unchanged. For large uniform
workloads, pair longest and shortest works across persistent workers with a
stable multi-wave bitonic sort to reduce the worst per-worker load.

* perf(pa): optimize metadata planning and default tests to v1_1

* fix(pa): support large metadata batches and bound reduction scratch

* perf(pa): preserve v1_2 scheduling in parallel metadata

Keep the v1_2 KV work allocation while using parallel metadata scans and compact reduction rows. Retain large-batch support and bounded scratch, and add standalone work-layout and graph-replay regression coverage.

* fix(pa): emit v1_2 reduction rows once per query tile

Emit each reduction row and final work record only from split index zero. Advance the reduction-row counter once after the split loop to prevent duplicate rows and out-of-bounds writes when a request spans more than one wave of splits. Keep attention partitioning and ASM binaries unchanged.

* perf(pa): integrate parallel metadata into v1_2

Generate PA v1_2 metadata with parallel kernels for dense single-Q-tile inputs (fast_mode=True, up to 32768 requests) and keep the serial generator as the fallback. Remove the separate PA v1_1 planner and its test selector.

* docs(pa): drop version names from metadata docstrings

* perf(pa): enable parallel metadata only for page size 16

Page size 1024 and other sizes keep the serial generator: the parallel launch has a fixed cost that is slower for few work items (B1/C1024/Q1 metadata 2.47 us serial vs 4.71 us parallel).

* perf(pa): faster gfx950 MTP PS kernels for page16 GQA16 fp8

Rebuild the four pa_{bf16,fp16}_pertokenFp8_gqa16_1tg_4w_mtp_msk{0,1}_ps.co from an optimized MTP SP3: tail tile only processes the 64-column groups that hold valid tokens, causal zeroing is a scalar branch, packed fp32 math for scale/softmax/accumulate, batched wave reductions, and a cheaper epilogue. Outputs are bit-identical to the previous .co on the validation shapes; test_pa_ps error statistics match across bf16/fp16 x causal/non-causal x qlen 1-4. On MI355 the attention kernel is 12-15% faster (up to ~23% for qlen 4, ctx<=1024) and pa_persistent_fwd 10-12% faster.
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…#6815)

* feat(pa): add opt-in prefix-budget metadata planner

Add GPU prefix-budget planning behind fast_mode=False while preserving the default v1_2 and PA ASM metadata ABI. Bound worker loads and avoid splitting work within the same persistent worker.

Add capacity sizing, metadata/graph regression coverage, and paired benchmark diagnostics adapted to current main and its page16 ASM reducer.

Validation: 12 metadata cases and 12 graph refreshes passed after a clean JIT rebuild; page256 paired smoke and targeted lint passed. Page16 GQA8/qlen1 baseline correctness failure remains unresolved.

* build(pa): refresh gfx950 GQA16 PS code objects

Rebuild eight BF16/FP16 page16 persistent attention variants from the native MI350 SP3 templates. FP8 decode uses K128 MFMA; MTP changes are ELF symbols only, and INT8 decode preserves matrix arithmetic with reordered prologue self-moves. Keep the PR/main reducers unchanged.

Validation: committed blobs match the previously validated native artifacts; PA metadata/graph, page16 correctness, and mixed-context performance checks passed. No universal speedup is claimed.

* fix(pa): resolve metadata test CI lint failures

* test(pa): simplify persistent attention test integration

* perf(pa): align v1_1 partitions with PR5546 and balance persistent workers

Split work by 256-token KV tiles using prefix quotas (partition cap is the
device CU count), keeping the PA ASM interface unchanged. For large uniform
workloads, pair longest and shortest works across persistent workers with a
stable multi-wave bitonic sort to reduce the worst per-worker load.

* perf(pa): optimize metadata planning and default tests to v1_1

* fix(pa): support large metadata batches and bound reduction scratch

* perf(pa): preserve v1_2 scheduling in parallel metadata

Keep the v1_2 KV work allocation while using parallel metadata scans and compact reduction rows. Retain large-batch support and bounded scratch, and add standalone work-layout and graph-replay regression coverage.

* fix(pa): emit v1_2 reduction rows once per query tile

Emit each reduction row and final work record only from split index zero. Advance the reduction-row counter once after the split loop to prevent duplicate rows and out-of-bounds writes when a request spans more than one wave of splits. Keep attention partitioning and ASM binaries unchanged.

* perf(pa): integrate parallel metadata into v1_2

Generate PA v1_2 metadata with parallel kernels for dense single-Q-tile inputs (fast_mode=True, up to 32768 requests) and keep the serial generator as the fallback. Remove the separate PA v1_1 planner and its test selector.

* docs(pa): drop version names from metadata docstrings

* perf(pa): enable parallel metadata only for page size 16

Page size 1024 and other sizes keep the serial generator: the parallel launch has a fixed cost that is slower for few work items (B1/C1024/Q1 metadata 2.47 us serial vs 4.71 us parallel).

* perf(pa): faster gfx950 MTP PS kernels for page16 GQA16 fp8

Rebuild the four pa_{bf16,fp16}_pertokenFp8_gqa16_1tg_4w_mtp_msk{0,1}_ps.co from an optimized MTP SP3: tail tile only processes the 64-column groups that hold valid tokens, causal zeroing is a scalar branch, packed fp32 math for scale/softmax/accumulate, batched wave reductions, and a cheaper epilogue. Outputs are bit-identical to the previous .co on the validation shapes; test_pa_ps error statistics match across bf16/fp16 x causal/non-causal x qlen 1-4. On MI355 the attention kernel is 12-15% faster (up to ~23% for qlen 4, ctx<=1024) and pa_persistent_fwd 10-12% faster.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants