Skip to content

[FlyDSL] Make PA planner batch and capacity runtime values - #7205

Merged
coderfeli merged 8 commits into
mainfrom
fix/flydsl-pa-plan-dynamic-batch
Nov 5, 2026
Merged

coderfeli merged 8 commits into
mainfrom
fix/flydsl-pa-plan-dynamic-batch

Conversation

@fsx950223

@fsx950223 fsx950223 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PA planner compilation currently specializes on every exact batch size and task capacity, so nearby batches or workgroup budgets build separate kernels. Pass both values at runtime and reuse compiled kernels within batch and block-size buckets, while preserving the exact task budget and metadata buffer shapes. Buckets that fit the thread block give each thread one row in straight-line code; larger buckets walk only actual rows with runtime bounds. Buckets therefore add no per-row work, and register use does not grow with the batch. The partition cap and the sliding window are runtime values as well, so kernels vary only by batch bucket, block size and whether a window is enabled. Buckets clip only to LDS, not to max_batch_size, so wheel builds precompile every planner kernel up to each architecture's LDS limit and that set serves every cap.

Motivation

The configured max_batch_size already limits accepted batches, but the planner still uses the actual batch to size LDS, construct scan vectors, and unroll task lookup. Exact capacity also remains in the compilation key. Separating the runtime values from the compilation bounds lets nearby shapes and budgets reuse the same compiled callable.

Unrolled per-row vectors also scale registers with the batch: on main, batch 32768 holds 32 Int64 rows per thread at 1024 threads and spills 381 VGPRs on gfx1250. Sizing those vectors to a bucket upper bound would make batches just above a power of two pay for up to twice their rows.

The partition cap defaults to the device's CU count, which differs between SKUs of one architecture (80 on MI308X, 304 on MI300X), and sliding windows differ by model. While either stayed in the compilation key, the planner kernels a server needs could not be compiled before it started.

Changes

  • Compile against batch upper bounds 1, 2, 4, ..., clipped to available LDS. The bucket sizes only the LDS task-end storage and the lookup depth, and selects the row path; loads, stores, and row loops use the actual batch. The configured batch limit does not clip the bucket: a limit between a batch and its power-of-two bound gives the same lookup depth and row path, and the planner's single block pays no occupancy for the larger LDS array.
  • Buckets that fit the thread block, which covers every batch up to 1024, use straight-line code with one row per thread; rows without tiles skip the Int64 divisions. Larger buckets walk consecutive rows with runtime bounds, carrying scalar tile, row, and task totals, and each row's lower split bound reuses the previous row's upper bound. Block scans and the row reduction take one value per thread, which preserves sequence order. Helpers compute visible tile ranges and task counts for both paths.
  • Task lookup runs (max_batch - 1).bit_length() levels. Rows lie below max_batch, so max_batch.bit_length() did one extra LDS read per slot at power-of-two buckets.
  • Pass actual batch and task capacity as fx.Int32 kernel arguments. Capacity only determines the 64–1024 thread block-size bucket; allocation sizes and partition-budget calculations remain exact.
  • Pass the partition cap and the window offset query_length - 1 + sliding_window as fx.Int32 kernel arguments. The offset is clamped to 2**31 - 1, which keeps every visible range because no int32 length exceeds it. Only whether a window is enabled stays a compile-time value. The partition-cap clamp runs in Int32, because a row's tile count from an int32 length fits.
  • Add aiter/aot/flydsl/pa_decode_plan.py, a replaying module like fmha_fp8.py ([FlyDSL] [JIT] Build the GEMM, conv, chunk_gdn_h and FP8 FMHA AOT caches by replaying the runtime #6956), and register it in AOT_MODULES, so run_aot, which PREBUILD_KERNELS wheel builds call, builds it. It replays plan_pa_decode itself on FakeTensors inside dry_run, so the planner's own rules pick each kernel. For each architecture GPU_ARCHS names (gfx942, gfx950 and gfx1250 when unset), it replays the largest batch of every power-of-two bucket and of the final bucket clipped to the architecture's LDS limit (16256 on gfx942, 40832 on gfx950, 81792 on gfx1250), at each task capacity where the block size can change, dense and windowed: 96, 96 and 98 kernels. Capacity cannot exceed the batch times the CU count, the partition cap's bound, so each architecture replays with the most CUs of any of its devices (304, 256 and 256). Block sizes beyond that, such as bucket 1 at 1024 threads, are unreachable and not built. Because buckets ignore max_batch_size, the set serves every cap. python -m aiter.aot.flydsl.pa_decode_plan builds it outside a wheel build, and --check reports missing kernels without compiling. aiter/aot/flydsl/README.md documents it.
  • Clip the final batch bucket to the aligned LDS limit so rounding cannot reject a batch that already fits. Use the existing architecture LDS helper when older PyTorch versions lack shared_memory_per_block.
  • Restore test_pa_decode_plan, which [FlyDSL] Merge gfx1250 PA decode partitions in the tile kernel and speed up dense decode #7079 removed from main, and extend it to check launcher reuse with changed runtime batches, capacities, partition caps and windows, non-power-of-two caps that keep their power-of-two bucket, batches above 4096, the LDS boundary, task allocation, padding, and graph refresh. No other test functions are added.

Performance (if applicable)

MI308X, head 9e616c422: buckets no longer clip to max_batch_size

Hardware: AMD Instinct MI308X (gfx942, 80 CUs). Before is the kernel that 23eca0860's cap-clipped bucket compiles, after is the head's power-of-two bucket. Both run the same plan on the same buffers, and only the bucket, and with it the size of the LDS task-end array, differs. These are planner-only CUDA-graph measurements: each graph holds ten refreshes, each sample times 50 replays after five warm-up replays, and each value is the median of three processes, each reporting the median of seven samples in alternating kernel order. Plans use one KV head, max_partitions=80, the default workgroup budget, no window, and sparse lengths repeating (257, 0, -1, 1027, 4096, 16384, 65537, 12345). Both kernels produce identical work_info and reduce_info. Spread between processes is up to 2.1%; within each process the after/before ratio stays within 0.3% of 1.

Hardware Workload/configuration Before After Change
MI308X / gfx942 batch=65, max_batch_size=100, capacity=160 (256 threads) 5.014 μs (bucket 100) 5.025 μs (bucket 128) +0.2%
MI308X / gfx942 batch=100, max_batch_size=100, capacity=160 (256 threads) 5.036 μs (bucket 100) 5.034 μs (bucket 128) 0.0%
MI308X / gfx942 batch=1500, max_batch_size=1500, capacity=1500 (1024 threads) 11.282 μs (bucket 1500) 11.286 μs (bucket 2048) 0.0%
MI308X / gfx942 batch=3000, max_batch_size=3000, capacity=3000 (1024 threads) 16.042 μs (bucket 3000) 16.035 μs (bucket 4096) 0.0%
MI308X / gfx942 batch=4097, max_batch_size=5000, capacity=4097 (1024 threads) 20.872 μs (bucket 5000) 20.872 μs (bucket 8192) 0.0%
MI308X / gfx942 batch=5000, max_batch_size=5000, capacity=5000 (1024 threads) 23.381 μs (bucket 5000) 23.386 μs (bucket 8192) 0.0%

Batch 65 under cap 100 is the only reproducible difference: +0.011 μs (+0.2%) in all three processes. Power-of-two caps, including the default 4096, and caps at or above the LDS limit compile the same kernels as before, so the measurements below still apply.

gfx1250, commit a2fb1f4ce

In this section, "Head" and "head" mean a2fb1f4ce, before the partition cap and window became runtime values; it has not been re-measured on gfx1250 at the current head.

These are planner-only CUDA-graph measurements: each graph holds ten refreshes, and each sample times 20–100 replays after five warm-up replays. Values are µs per refresh, the median of five samples with alternating kernel order. The baseline is main 8bcab96511 (planner unchanged at 05dbf3453); 01788507b and ca05d2dba are earlier commits of this PR. Compilation is excluded. All plans use one KV head, sliding_window=0, and query_length=1. All four kernels produce identical work_info and reduce_info, which match an exact Python reference.

Review configurations: dense rows hold 65536 tokens, and sparse rows repeat (257, 0, -1, 1027, 4096, 16384, 65537, 12345).

Hardware Plan Main 01788507b ca05d2dba Head
gfx1250 Dense decode bs1, capacity 256 2.610 μs 2.805 μs 2.947 μs 2.563 μs
gfx1250 Dense decode bs4, capacity 512 3.439 μs 3.619 μs 3.359 μs 3.006 μs
gfx1250 Dense decode bs32, capacity 512 3.786 μs 3.749 μs 3.425 μs 3.191 μs
gfx1250 Sparse decode 64 rows, 8 partitions 3.702 μs 3.775 μs 3.346 μs 3.159 μs
gfx1250 Sparse prefill 1000 rows, 1 partition 5.898 μs 5.878 μs 6.047 μs 5.821 μs
gfx1250 Sparse prefill 2047 rows, 1 partition 8.010 μs 8.162 μs 8.386 μs 8.230 μs
gfx1250 Sparse prefill 4000 rows, 1 partition 12.112 μs 12.697 μs 12.249 μs 12.090 μs

Bucket boundaries and large batches: max_parts=80, sparse lengths as above, and the default workgroup budget (capacity equals batch) unless stated. Batches above 4096 use max_batch_size=32768.

Hardware Plan Main 01788507b ca05d2dba Head
gfx1250 batch=65, capacity=256 3.114 μs 3.231 μs 3.182 μs 2.970 μs
gfx1250 batch=257, capacity=2048 6.866 μs 7.075 μs 6.003 μs 5.908 μs
gfx1250 batch=1024 5.973 μs 6.136 μs 6.203 μs 5.955 μs
gfx1250 batch=1025 7.384 μs 7.485 μs 6.231 μs 6.170 μs
gfx1250 batch=4096 13.304 μs 14.034 μs 13.581 μs 13.380 μs
gfx1250 batch=4097 15.082 μs 19.140 μs 14.398 μs 14.180 μs
gfx1250 batch=8193 26.383 μs 42.807 μs 25.006 μs 24.673 μs
gfx1250 batch=16384 50.841 μs 57.911 μs 47.746 μs 46.994 μs
gfx1250 batch=16385 63.228 μs 105.199 μs 56.457 μs 56.015 μs
gfx1250 batch=20000 81.336 μs 131.769 μs 70.969 μs 70.024 μs
gfx1250 batch=24577 113.975 μs 147.931 μs 87.916 μs 86.705 μs
gfx1250 batch=32768 154.873 μs 169.536 μs 117.214 μs 115.781 μs
gfx1250 batch=32768, capacity=262144 475.969 μs 509.579 μs 451.866 μs 440.007 μs

The batch=32768 row is the median of three repeated runs; one earlier sample was disturbed by another process on the shared GPU. Head stays above main only at 2047 rows (+0.22 μs) and 4096 rows (+0.08 μs). Above about 100k task slots, the single-block task-write loop dominates; this PR leaves it unchanged.

Compiled resources on gfx1250:

Kernel VGPRs VGPR spills Private segment
main, batch 32768 128 381 1152 B
01788507b, bucket 32768 128 400 1180 B
head, bucket 32768 84 0 0 B
01788507b, bucket 4096 100 0 0 B
head, bucket 4096 88 0 0 B
head, bucket 1024 84 0 0 B
head, bucket 1 42 0 0 B

First-call time (compile plus launch) for the 32768 bucket is about 0.3 s at head versus about 1.0 s at 01788507b. Without the 64-row floor, decode batches 1–64 can compile up to seven planner kernels instead of one for the same block size and plan options.

Batches above 4096 require an explicit max_batch_size. The planner's LDS check caps batches at 16256 on gfx942 (64 KiB), 40832 on gfx950 (160 KiB), and 81792 on gfx1250 (320 KiB).

MI308X, head 5029f684a

Hardware: AMD Instinct MI308X (gfx942, 80 CUs). These are planner-only CUDA-graph measurements: each graph holds ten refreshes, each sample times 50 replays after five warm-up replays, and each value is the median of three processes per kernel, run in alternating order, with each process reporting the median of seven samples. The baseline is the previous head a2fb1f4ce; compilation is excluded. Plans use one KV head, max_partitions=80, and sparse lengths repeating (257, 0, -1, 1027, 4096, 16384, 65537, 12345); batch 8193 uses max_batch_size=16384. Run-to-run spread is at most 1.9%.

Hardware Workload/configuration Before After Change
MI308X / gfx942 batch=1, capacity=80 4.392 μs 4.371 μs -0.5%
MI308X / gfx942 batch=6, capacity=80 4.478 μs 4.539 μs +1.4%
MI308X / gfx942 batch=63, capacity=80 4.725 μs 4.752 μs +0.6%
MI308X / gfx942 batch=65, capacity=256 5.003 μs 5.046 μs +0.9%
MI308X / gfx942 batch=257, capacity=2048 9.677 μs 9.713 μs +0.4%
MI308X / gfx942 batch=1024, capacity=1024 9.197 μs 9.143 μs -0.6%
MI308X / gfx942 batch=4096, capacity=4096 20.183 μs 20.009 μs -0.9%
MI308X / gfx942 batch=8193, capacity=8193 41.536 μs 41.466 μs -0.2%
MI308X / gfx942 batch=64, capacity=512, window 257, query_length=4 5.289 μs 5.295 μs +0.1%
MI308X / gfx942 batch=1025, capacity=4096, window 8193, query_length=4 15.614 μs 15.785 μs +1.1%

Batch 6 (+0.06 μs) and the windowed batch 1025 (+0.17 μs) are the largest reproducible costs: all three runs of each are slower than every baseline run. An Int64 partition-cap clamp cost up to +2.3% at batch 6, which is why the clamp runs in Int32. For these plans, with extra windowed shapes and max_partitions 7 and 1 (36 plans in total), head and baseline produce identical work_info and reduce_info.

AOT compilation on this host, with the GPUs hidden: at 23eca0860 the wheel set of 290 kernels for gfx942, gfx950 and gfx1250 replayed in 9.6 s through python -m aiter.aot.flydsl.pa_decode_plan (at e91be70a0, before the replay port, 304 kernels took 8.9 s through run_aot).

MI308X, first commit 01788507b

These numbers predate the later commits and have not been re-measured at head.

Hardware: AMD Instinct MI308X (gfx942). These are planner-only CUDA-graph measurements using triton.testing.do_bench_cudagraph(rep=20), taking the median of three measurements with interleaved before/after order. The baseline is main 8bcab96511; compilation is excluded. Both kernels use max_parts=80, sliding_window=0, and query_length=1, with context lengths repeating (257, 0, -1, 1027, 4096, 16384, 65537, 12345). Each configuration produces identical work_info and reduce_info before and after.

Hardware Workload/configuration Before After Change
MI308X / gfx942 batch=1, capacity=80 3.483 μs 3.949 μs +13.4%
MI308X / gfx942 batch=6, capacity=80 3.651 μs 3.914 μs +7.2%
MI308X / gfx942 batch=63, capacity=80 3.770 μs 4.171 μs +10.6%
MI308X / gfx942 batch=65, capacity=256 4.260 μs 4.381 μs +2.8%
MI308X / gfx942 batch=257, capacity=2048 9.909 μs 10.141 μs +2.3%
MI308X / gfx942 batch=4096, capacity=4096 19.163 μs 19.786 μs +3.3%

At the first commit, runtime bounds added approximately 0.12–0.62 μs per planner invocation in these workloads. End-to-end latency and compilation-time savings were not benchmarked.

Testing

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

Head 9e616c422 (buckets no longer clip to max_batch_size; the planner reuse case varies partition cap and window) was validated on MI308X (gfx942): 277 passed, 107 skipped in the PA decode test file, and the planner test passed using only replayed AOT kernels, including the non-power-of-two caps. Its planner test also passed on MI355X (gfx950), with JIT and with only replayed AOT kernels. Merge head 23eca0860 (origin/main merged in, the AOT module ported to the replay driver) was validated on MI308X (gfx942): 277 passed, 107 skipped in the PA decode test file, and the planner test passed using only replayed AOT kernels. Commit 5029f684a was validated on MI308X (gfx942): 197 tests passed and 4 were skipped for architecture reasons, and the planner test also passed using only AOT-compiled kernels. Commit e91be70a0 changes only AOT registration and documentation; its wheel AOT set was validated on the same GPU. Commit a2fb1f4ce was validated on gfx1250: 124 tests passed and 77 skipped, all for architecture reasons. The first commit was validated on MI308X (gfx942): 197 tests passed and 4 were skipped for architecture reasons. See validation scope below.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The planner docstring describes compilation buckets, runtime parameters, and LDS clipping, and points to the AOT script, which aiter/aot/flydsl/README.md documents. Public calling conventions are unchanged, so no user-guide migration is needed.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None for the public plan_pa_decode and PADecodePlan APIs. The internal compile_pa_decode_plan factory now takes max_batch, threads and windowed in place of exact batch, capacity, partition cap, window and query length; its launcher receives actual batch, capacity, partition cap and window offset at runtime.

PR Self-Review

Reviewed revision

9e616c4228ef7fc7b40c4d2b921c7046f4d0c35e

Behavior and intent

Kernel specialization follows batch upper bounds and block size. Buckets that fit the block give each thread at most one row; larger buckets bound row loops by the actual batch. Each launch uses the actual batch to guard metadata accesses, and the exact capacity to allocate partitions and clear padding. Threads with no rows and rows without tiles contribute zero to the scans and the reduction, and LDS lookup only accesses rows below the actual batch. Plan allocation, validation, and refresh semantics are preserved. The partition cap and window are launch arguments, and buckets clip only to LDS, so the compiled set is finite and depends on neither max_batch_size, the device's CU count nor the model's window; run_aot replays the planner over that set for wheel builds up to each architecture's LDS limit.

Validation and unverified scope

Head 9e616c422 takes two review follow-ups: buckets no longer clip to max_batch_size, and the planner reuse case also changes the partition cap, window and query length. Environment: MI308X (gfx942, 80 CUs), Python 3.12, PyTorch 2.8.0 with ROCm 7.2, FlyDSL 0.4.1.

  • python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan: 11 passed. All of op_tests/test_flydsl_pa_decode.py: 277 passed, 107 skipped. tests/test_flydsl_aot_replay.py: 5 passed.
  • Negative control for the extended reuse case: a patched planner made each launcher keep the partition cap and window of its first launch, as a kernel that compiled them in would. Run one case per process, all 9 reuse cases failed the metadata check, while the previous reuse case passed all 9.
  • HIP_VISIBLE_DEVICES=-1 python -m aiter.aot.flydsl.pa_decode_plan into an empty FLYDSL_RUNTIME_CACHE_DIR: gfx942 96, gfx950 96 and gfx1250 98 replays ok, 0 failed, the same counts as 23eca0860 since that set already reached every LDS limit; --check then reported 0 failed. Against that cache, FLYDSL_RUNTIME_RUN_ONLY=1 python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan: 11 passed, including the cap-100 and cap-5000 cases that previously needed their own run.
  • Black (stable) and ruff==0.16.0 check: passed on the changed Python files.

Head 9e616c422 on gfx950: MI355X (256 CUs), PyTorch 2.10 with ROCm 7.2.4, FlyDSL 0.4.1. test_pa_decode_plan: 11 passed. GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.pa_decode_plan into an empty cache succeeded, and test_pa_decode_plan against it with FLYDSL_RUNTIME_RUN_ONLY=1: 11 passed, including the cap-100, cap-5000 and LDS-limit (bucket 40832) cases. At 23eca0860, the reviewer ran all of op_tests/test_flydsl_pa_decode.py on gfx950 (347 passed, 37 skipped).

Merge head 23eca0860 environment: MI308X (gfx942, 80 CUs), Python 3.12, PyTorch 2.8.0 with ROCm 7.2, FlyDSL 0.4.1 (the pinned version). Main's #6956 removed OpKind, so the AOT module was ported to the replay driver; the planner kernel and runtime code are unchanged apart from main's arrival_counters.

  • python -m aiter.aot.flydsl.pa_decode_plan into an empty FLYDSL_RUNTIME_CACHE_DIR: gfx942 96, gfx950 96 and gfx1250 98 replays ok, 0 failed, including the full-LDS buckets; --check then reported 0 failed.
  • The kernels the replays reach equal e91be70a0's plan_variants minus those above the CU-count bound (2, 6 and 6 at cap 81792), checked for caps 81792, 4096, 5000 and 1, one replay per kernel.
  • Against that cache, FLYDSL_RUNTIME_RUN_ONLY=1 python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan: 8 passed, 3 failed on cache misses at caps 100 and 5000, by design. After GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.pa_decode_plan --max-batch-size 100 5000 into the same cache: 11 passed.
  • python -m pytest -q op_tests/test_flydsl_pa_decode.py: 277 passed, 107 skipped.
  • python -m pytest -q tests/test_flydsl_aot_replay.py: 5 passed.
  • black==25.1.0 --check and ruff==0.11.11 check on the changed Python files: passed.

Commit e91be70a0 and commit 5029f684a environment: MI308X (gfx942, 80 CUs), Python 3.12, PyTorch 2.8.0 with ROCm 7.2, FlyDSL 0.4.0. The planner kernel and runtime code are identical at both; the full test runs below used 5029f684a.

  • run_aot into an empty cache, with the MoE and MegaMoE replays and the other kinds stubbed out: 304 planner kernels for gfx942, gfx950 and gfx1250 compiled, 0 failed, including the full-LDS buckets 16256, 40832 and 81792. GPU_ARCHS="gfx942;gfx950" selects 200 of them.
  • Against that cache, FLYDSL_RUNTIME_RUN_ONLY=1 python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan: 8 passed, 3 failed. The failures are exactly the cases with caps 100 and 5000, all cache misses, which the wheel set does not cover by design. Plans with caps 4096, 16384, 32768 and 81792, including a windowed one, loaded without JIT.
  • python -m pytest -q op_tests/test_flydsl_pa_decode.py: 197 passed, 4 skipped.
  • HIP_VISIBLE_DEVICES=-1 python -m aiter.aot.flydsl.pa_decode_plan --arch gfx942 --max-batch-size 4096 1 100 5000 16257 into an empty FLYDSL_RUNTIME_CACHE_DIR, then FLYDSL_RUNTIME_RUN_ONLY=1 python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan: 11 passed with no JIT compilation. With only the default 4096 set compiled, exactly the four cases with caps 100, 5000 and the LDS limit failed on cache misses.
  • The script's variant list equals a brute-force enumeration of the runtime bucket and block-size rules for 1842 combinations of cap and LDS size (64, 160 and 320 KiB).
  • Planner metadata matched an exact Python reference with window offsets clamped at 2**31 - 1 (windows up to 2**40, query lengths 1 to 20) and lengths near 2**31 - 1.
  • Black (stable) and ruff==0.16.0 check: passed on the changed Python files.

Commit a2fb1f4ce environment: gfx1250, Python 3.12, PyTorch 2.11 with ROCm 10.1, FlyDSL 0.4.1.

  • python -m pytest -q op_tests/test_flydsl_pa_decode.py: 124 passed, 77 skipped. The skips are gfx1250 head-dimension, FP16-query/plain-V, and pipeline unowned-row cases.
  • Planner metadata matched an exact Python reference, including after CUDA-graph refresh, for batches from 1 to 32768. Cases cover default and large budgets (capacity up to 8,388,608), sliding window 8193 with query_length=4, max_partitions=1, and all lengths at 2**31 - 1.
  • End-to-end pa_decode (BF16) at batch 32768 matched the FP32 reference (max error 6.3e-4). Cases: single-token decode at capacity 32768 and 131072, and query_length=4 with window 257; 8192 sequences use multiple tasks.
  • python -m black --check and ruff check on both changed files: passed.
  • git show --check: passed.
  • Compiled VGPR, spill, and LDS counts were taken from the final ISA dumps reported above.
  • [FlyDSL] Merge gfx1250 PA decode partitions in the tile kernel and speed up dense decode #7079 landed first and removed test_pa_decode_plan; merge head 23eca0860 keeps this PR's version beside [FlyDSL] Merge gfx1250 PA decode partitions in the tile kernel and speed up dense decode #7079's tests.

First commit 01788507b environment: MI308X (gfx942), Python 3.12, PyTorch 2.8.0 with ROCm 7.2, FlyDSL 0.4.0.

  • HIP_VISIBLE_DEVICES=1 python -m pytest -q op_tests/test_flydsl_pa_decode.py -k 'test_pa_decode_plan' -x: 11 passed.
  • python -m pytest -q op_tests/test_flydsl_pa_decode.py -k 'not test_pa_decode_plan' -x: 186 passed, 4 skipped.
  • Six planner-only before/after benchmarks: metadata equality verified; timings reported above.

Head 9e616c422 has not run on gfx1250, MI250X, or MI300X: on gfx1250 the replayed AOT kernels, including the full-LDS bucket 81792, are compiled but neither loaded nor executed, and the gfx1250 numbers above predate the runtime partition cap and window. Run-only loading is verified on gfx942 and gfx950. The full PA decode test file has not run on gfx950 at this head; its planner test has. A complete PREBUILD_KERNELS wheel build and run_aot with the MoE and other replays enabled were not run. End-to-end serving latency and startup savings remain unmeasured.

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

The planner test is the canonical test of plan_pa_decode's metadata; #7079 removed it from main, and this PR restores and extends it, since no other test checks task allocation directly. Before this PR, the bucket-bound assertion would fail for batches below their bucket upper bound because compilation uses the exact batch. The reuse assertion would fail because changing exact batch and capacity creates another compiled launcher. Exact partition-count checks verify that a reused launcher receives the new launch budget. The prior fixed-shape coverage checked tile coverage and graph replay but did not change batch and capacity under a shared launcher. The reuse case also changes the partition cap, to the smallest that admits the new capacity so long rows reach it, and moves a positive window and the query length; a launcher that kept its first cap and window fails the metadata check in every reuse case (negative control above). Custom-cap cases check that a non-power-of-two cap keeps the power-of-two bucket, and the LDS-boundary case covers clipping introduced by bucket rounding. All coverage remains in the existing test function.

Changed op tests

op_tests/test_flydsl_pa_decode.py: restores the planner test that #7079 removed and extends it; no other test changes. The previous coverage checked task coverage and graph refresh at fixed shapes. The extension changes actual batch, capacity, partition cap, window and query length inside the same compilation bucket and checks launcher identity and exact partition counts, catching stale runtime arguments and unwanted specialization. Additional parameter cases exercise non-power-of-two caps (which keep the power-of-two bucket), batches above the default cap, and the final LDS bucket.

Bucket planner compilation by batch upper bound and block size while preserving exact task budgets and metadata buffer shapes. Clip the last batch bucket to the configured limit and available LDS, with an architecture fallback for older PyTorch device properties.

Extend the existing planner test to verify compiled callable reuse across runtime batches and capacities, custom batch caps, LDS boundaries, and graph refresh. Validation on gfx942: 197 passed, 4 architecture skips; Black, Ruff, and diff checks passed.
@fsx950223
fsx950223 requested review from a team and a balanced review from Copilot October 30, 2026 07:23

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@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 7205 --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.

@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 9e616c4228ef · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Kernel specialization follows batch upper bounds and block size. Buckets that fit the block give each thread at most one row; larger buckets bound row loops by the actual batch. Each launch uses the actual batch to guard metadata accesses, and the exact capacity to allocate partitions and clear padding. Threads with no rows and rows without tiles contribute zero to the scans and the reduction, and LDS lookup only accesses rows below the actual batch. Plan allocation, validation, and refresh semantics are preserved. The partition cap and window are launch arguments, and buckets clip only to LDS, so the compiled set is finite and depends on neither `max_batch_size`, the device's CU count nor the model's window; `run_aot` replays the planner over that set for wheel builds up to each architecture's LDS limit.

Validation and unverified scope

Head `9e616c422` takes two review follow-ups: buckets no longer clip to `max_batch_size`, and the planner reuse case also changes the partition cap, window and query length. Environment: MI308X (`gfx942`, 80 CUs), Python 3.12, PyTorch 2.8.0 with ROCm 7.2, FlyDSL 0.4.1.

- `python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan`: 11 passed. All of `op_tests/test_flydsl_pa_decode.py`: 277 passed, 107 skipped. `tests/test_flydsl_aot_replay.py`: 5 passed.
- Negative control for the extended reuse case: a patched planner made each launcher keep the partition cap and window of its first launch, as a kernel that compiled them in would. Run one case per process, all 9 reuse cases failed the metadata check, while the previous reuse case passed all 9.
- `HIP_VISIBLE_DEVICES=-1 python -m aiter.aot.flydsl.pa_decode_plan` into an empty `FLYDSL_RUNTIME_CACHE_DIR`: gfx942 96, gfx950 96 and gfx1250 98 replays ok, 0 failed, the same counts as `23eca0860` since that set already reached every LDS limit; `--check` then reported 0 failed. Against that cache, `FLYDSL_RUNTIME_RUN_ONLY=1 python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan`: 11 passed, including the cap-100 and cap-5000 cases that previously needed their own run.
- Black (stable) and `ruff==0.16.0` check: passed on the changed Python files.

Head `9e616c422` on gfx950: MI355X (256 CUs), PyTorch 2.10 with ROCm 7.2.4, FlyDSL 0.4.1. `test_pa_decode_plan`: 11 passed. `GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.pa_decode_plan` into an empty cache succeeded, and `test_pa_decode_plan` against it with `FLYDSL_RUNTIME_RUN_ONLY=1`: 11 passed, including the cap-100, cap-5000 and LDS-limit (bucket 40832) cases. At `23eca0860`, the reviewer ran all of `op_tests/test_flydsl_pa_decode.py` on gfx950 (347 passed, 37 skipped).

Merge head `23eca0860` environment: MI308X (`gfx942`, 80 CUs), Python 3.12, PyTorch 2.8.0 with ROCm 7.2, FlyDSL 0.4.1 (the pinned version). Main's #6956 removed `OpKind`, so the AOT module was ported to the replay driver; the planner kernel and runtime code are unchanged apart from main's `arrival_counters`.

- `python -m aiter.aot.flydsl.pa_decode_plan` into an empty `FLYDSL_RUNTIME_CACHE_DIR`: gfx942 96, gfx950 96 and gfx1250 98 replays ok, 0 failed, including the full-LDS buckets; `--check` then reported 0 failed.
- The kernels the replays reach equal `e91be70a0`'s `plan_variants` minus those above the CU-count bound (2, 6 and 6 at cap 81792), checked for caps 81792, 4096, 5000 and 1, one replay per kernel.
- Against that cache, `FLYDSL_RUNTIME_RUN_ONLY=1 python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan`: 8 passed, 3 failed on cache misses at caps 100 and 5000, by design. After `GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.pa_decode_plan --max-batch-size 100 5000` into the same cache: 11 passed.
- `python -m pytest -q op_tests/test_flydsl_pa_decode.py`: 277 passed, 107 skipped.
- `python -m pytest -q tests/test_flydsl_aot_replay.py`: 5 passed.
- `black==25.1.0 --check` and `ruff==0.11.11 check` on the changed Python files: passed.

Commit `e91be70a0` and commit `5029f684a` environment: MI308X (`gfx942`, 80 CUs), Python 3.12, PyTorch 2.8.0 with ROCm 7.2, FlyDSL 0.4.0. The planner kernel and runtime code are identical at both; the full test runs below used `5029f684a`.

- `run_aot` into an empty cache, with the MoE and MegaMoE replays and the other kinds stubbed out: 304 planner kernels for gfx942, gfx950 and gfx1250 compiled, 0 failed, including the full-LDS buckets 16256, 40832 and 81792. `GPU_ARCHS="gfx942;gfx950"` selects 200 of them.
- Against that cache, `FLYDSL_RUNTIME_RUN_ONLY=1 python -m pytest -q op_tests/test_flydsl_pa_decode.py -k test_pa_decode_plan`: 8 passed, 3 failed. The failures are exactly the cases with caps 100 and 5000, all cache misses, which the wheel set does not cover by design. Plans with caps 4096, 16384, 32768 and 81792, including a windowed one, loaded without JIT.
- `python

[truncated in readiness report; see the PR description for the full answer]

PR-specific question

> What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

The planner test is the canonical test of `plan_pa_decode`'s metadata; #7079 removed it from main, and this PR restores and extends it, since no other test checks task allocation directly. Before this PR, the bucket-bound assertion would fail for batches below their bucket upper bound because compilation uses the exact batch. The reuse assertion would fail because changing exact batch and capacity creates another compiled launcher. Exact partition-count checks verify that a reused launcher receives the new launch budget. The prior fixed-shape coverage checked tile coverage and graph replay but did not change batch and capacity under a shared launcher. The reuse case also changes the partition cap, to the smallest that admits the new capacity so long rows reach it, and moves a positive window and the query length; a launcher that kept its first cap and window fails the metadata check in every reuse case (negative control above). Custom-cap cases check that a non-power-of-two cap keeps the power-of-two bucket, and the LDS-boundary case covers clipping introduced by bucket rounding. All coverage remains in the existing test function.

Changed op tests

`op_tests/test_flydsl_pa_decode.py`: restores the planner test that #7079 removed and extends it; no other test changes. The previous coverage checked task coverage and graph refresh at fixed shapes. The extension changes actual batch, capacity, partition cap, window and query length inside the same compilation bucket and checks launcher identity and exact partition counts, catching stale runtime arguments and unwanted specialization. Additional parameter cases exercise non-power-of-two caps (which keep the power-of-two bucket), batches above the default cap, and the final LDS bucket.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot could not review the current head (for example, quota or service failure)

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

@zhiding512 zhiding512 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.

Checked on gfx1250 (256 CUs, PyTorch 2.11 / ROCm 10.1, HIP 7.16, FlyDSL 0.4.1) against this PR's parent 8bcab96.

Compilation reuse works. First plan_pa_decode call for sparse-prefill batches 1000, 1001, 1023, 1234, 2047, 3001 and 4000 in one process (one partition, so capacity == batch):

First call per batch Before This PR
Empty FlyDSL disk cache 214–402 ms each 241–277 ms for the first batch of a bucket, 0.05–0.07 ms for the rest
Warm disk cache 21–22 ms each 23–24 ms for the first batch of a bucket, 0.05–0.07 ms for the rest
Planner kernels compiled 7 3

The process's first call (batch 1000) also pays one-time initialization in both versions and is left out of the ranges.

Planner GPU time per refresh (CUDA graphs of ten refreshes, median of five alternating rounds; metadata is bit-identical in every column):

Plan Before This PR Without the 64-row floor
Dense decode bs1, capacity 256 2.626 µs 2.805 µs 2.688 µs
Dense decode bs4, capacity 512 3.327 µs 3.474 µs 3.379 µs
Dense decode bs32, capacity 512 3.865 µs 3.918 µs 3.901 µs
Sparse decode 64 rows, 8 partitions 3.894 µs 3.932 µs 3.938 µs
Sparse prefill 1000 rows, 1 partition 6.057 µs 6.197 µs 6.214 µs
Sparse prefill 2047 rows, 1 partition 8.435 µs 8.609 µs 8.609 µs
Sparse prefill 4000 rows, 1 partition 13.243 µs 13.995 µs 14.014 µs

See the inline note about the floor.

Tests: op_tests/test_flydsl_pa_decode.py gives 124 passed and 77 skipped (existing gfx1250 skips); all 11 test_pa_decode_plan cases pass.

Merge order: #7079 (through #7147) deletes test_pa_decode_plan, which this PR extends. On top of #7079's head, pa_decode_plan.py merges cleanly but op_tests/test_flydsl_pa_decode.py conflicts. Whichever PR lands second should keep this PR's version of the test; Copilot on #7079 also asked for the planner test back.

Batch buckets unrolled per-thread vectors sized to the bucket upper bound,
so batches just above a power of two paid for padding rows (+57% at batch
8193, +64% at 16385 on gfx1250), and the 32768 bucket held 32 Int64 rows
per thread, spilling 400 VGPRs at 1024 threads.

Each thread now loops over its consecutive rows with runtime bounds and
carries scalar totals; block scans and the row reduction take one value
per thread. Each row's lower split bound reuses the previous row's upper
bound, halving the Int64 divisions. Buckets now size only LDS and the
lookup depth. A shared helper replaces the duplicated window arithmetic.
Metadata is unchanged.

gfx1250 planner graph replay (main / previous commit / this commit):
batch 8193: 28.9 / 45.3 / 27.4 us; 16385: 67.3 / 110.3 / 59.1 us;
32768: 156.6 / 172.2 / 119.2 us. Batches up to 4096 are within noise.
The 32768 bucket uses 84 VGPRs without spills.

The planner test checks the reused launcher directly instead of its
cached compiled function.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 08:16

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Review on gfx1250 found the 64-row bucket floor costs small decode plans
on every refresh. The runtime row loops made it worse: bs1 took 2.947 us
versus 2.610 us on main.

Drop the floor, so buckets are 1, 2, 4, and so on. Buckets that fit the
block, which covers every batch up to 1024, use straight-line code with
one row per thread, and rows without tiles skip the Int64 divisions.
Larger buckets keep the runtime row loops. Task lookup runs
(max_batch - 1).bit_length() levels: rows lie below max_batch, so
power-of-two buckets did one extra LDS read per slot.

gfx1250 planner time per refresh (10 refreshes per graph, median of five
alternating rounds; main / previous commit / this commit):
bs1 cap 256: 2.610 / 2.947 / 2.563 us; bs4 cap 512: 3.439 / 3.359 /
3.006 us; 2047 rows: 8.010 / 8.386 / 8.230 us; batch 32768: 157.0 /
119.1 / 117.5 us. Metadata matches main and an exact reference.

Decode batches 1-64 can now compile up to seven planner kernels instead
of one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 08:29

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@fsx950223

Copy link
Copy Markdown
Contributor Author

@zhiding512 thanks for checking this on gfx1250. The 64-row floor is addressed in the inline thread (a2fb1f4).

On merge order: agreed. Whichever of #7079 and this PR lands second should keep this PR's test_pa_decode_plan. At a2fb1f4, pa_decode_plan.py still merges cleanly onto #7079's head f5fc18e and keeps its arrival_counters; op_tests/test_flydsl_pa_decode.py still conflicts.

@XiaobingSuper

XiaobingSuper commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

No blocking issues. Correction of my earlier ask: the planner already rounds max_batch up; the per-length compiles came from ATOM passing the exact row count as max_batch_size, which caps that rounding.

ATOM's MiniMax-M3 sparse prefill did so past 4096 rows; it now passes a power of two (8526dcb8e). MI455X @ a2fb1f4: output bitwise equal to main (96 cases); new-length TTFT 0.48 to 0.10 s.

Evidence

First plan_pa_decode call per batch, kv_heads 1, MI455X, fresh process with an empty FlyDSL cache (FLYDSL_RUNTIME_CACHE_DIR), after a warm-up call:

batch max_batch_size = batch max_batch_size = next power of two
6005 244.2 ms 240.0 ms (8192 bucket compiled)
6075 240.1 ms 0.1 ms
6145 240.2 ms 0.1 ms
7405 239.3 ms 0.1 ms
9000 334.5 ms 243.0 ms (16384 bucket compiled)

With a warm on-disk cache a length seen before still reloads per process (about 23 ms each).

Bitwise check: work_info and reduce_info against main's planner for batches 1 to 16384, heads 1 and 8, query length 1 and 4, windows 0 and 128, random and partly empty lengths: 96 cases, 0 mismatches. op_tests/test_flydsl_pa_decode.py -k plan: 11 passed.

The planner still compiled the partition cap, sliding window and query
length into each kernel. The cap defaults to the device's CU count,
which differs between SKUs of one architecture (80 on MI308X, 304 on
MI300X), and windows differ by model, so the kernels a server needs
could not be compiled before it started.

Pass the partition cap and the window offset query_length - 1 +
sliding_window as Int32 kernel arguments. The offset is clamped to
2**31 - 1, which keeps every visible range because no int32 length
exceeds it. Only whether a window is enabled stays compile-time, so
kernels vary by batch bucket, block size and window mode: 94 per
architecture at the default max_batch_size of 4096. The partition-cap
clamp runs in Int32, since a row's tile count from an int32 length
fits; an Int64 clamp cost up to 2.3% at batch 6.

Add aiter/aot/flydsl/pa_decode_plan.py, a standalone script outside
run_aot. For gfx942, gfx950 and gfx1250 it compiles every power-of-two
bucket below max_batch_size, the clipped final bucket, every block size
reachable from each bucket's batches and both window modes.

MI308X planner time per refresh (10 refreshes per graph, median of
three alternating runs; previous commit / this commit): bs1 cap 80:
4.392 / 4.371 us; bs6 cap 80: 4.478 / 4.539 us; bs65 cap 256: 5.003 /
5.046 us; bs4096: 20.183 / 20.009 us; bs1025 window 8193: 15.614 /
15.785 us. Metadata is identical to the previous commit.

On MI308X the full PA decode test passes (197 passed, 4 skipped), and
the planner test passes 11/11 using only AOT-compiled kernels with
FLYDSL_RUNTIME_RUN_ONLY=1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: fsx950223 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 06:10

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

Two new architecture probes read properties.gcnArchName directly instead of using the shared test and runtime helpers, bypassing the established architecture-selection contract.

2 open issues

Review effort: Balanced

Comment thread op_tests/test_flydsl_pa_decode.py Resolved
XiaobingSuper added a commit that referenced this pull request Nov 2, 2026
Squash of #7205 at 5029f68, by @fsx950223.

Conflict: op_tests/test_flydsl_pa_decode.py. #7079 drops the old test_pa_decode_plan and adds its merge tests; #7205 updates test_pa_decode_plan for runtime batch buckets. Kept #7079's tests and #7205's test_pa_decode_plan at its original spot.
Register the planner's AOT script with run_aot, which PREBUILD_KERNELS
wheel builds call, at max_batch_size 81792, gfx1250's LDS limit. Each
architecture clips the final bucket to its own limit (16256 on gfx942,
40832 on gfx950), so the set covers every power-of-two cap, including
the default 4096, and every cap at or above the limit: 98, 102 and 104
kernels for gfx942, gfx950 and gfx1250. A non-power-of-two cap below
the limit, such as 5000, still needs its own
python -m aiter.aot.flydsl.pa_decode_plan --max-batch-size run.

Through run_aot, with the MoE replays and the other kinds stubbed out,
all 304 kernels compile in 8.9 s. Against that cache with
FLYDSL_RUNTIME_RUN_ONLY=1 on MI308X, plans with caps 4096, 16384, 32768,
81792 and the LDS limit load without JIT; only the planner test cases
with caps 100 and 5000 miss.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: fsx950223 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 09:01

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

Direct gcnArchName probes in the planner and test bypass shared architecture helpers, leaving LDS selection inconsistent with runtime AOT overrides and test GPU_ARCHS handling.

2 open issues

Review effort: Balanced

XiaobingSuper added a commit that referenced this pull request Nov 2, 2026
Squash of #7205 at e91be70, by @fsx950223.

Conflict: op_tests/test_flydsl_pa_decode.py. #7079 drops the old test_pa_decode_plan and adds its merge tests; #7205 updates test_pa_decode_plan for runtime batch buckets. Kept #7079's tests and #7205's test_pa_decode_plan at its original spot.
Co-authored-by: Cursor <[email protected]>
Resolve conflicts with #6956 (AOT caches built by replaying the runtime)
and #7079 (gfx1250 PA decode partition merges).

- aiter/aot/flydsl/pa_decode_plan.py now follows the replay protocol
  instead of the removed OpKind/compile_one_config dispatch: it replays
  plan_pa_decode on FakeTensors at the largest batch of each bucket and
  at each capacity where the block size can change, dense and windowed.
  Each arch replays with the most CUs of its devices, so the set equals
  the previous plan_variants minus the variants no device can reach
  (e.g. bucket 1 at 1024 threads). common.py registers it in AOT_MODULES;
  arch selection moves from --arch to GPU_ARCHS, as for every module.
- README: main's module table and GPU_ARCHS wording, plus the planner
  entry and section.
- op_tests: #7079 dropped test_pa_decode_plan; keep this PR's version
  alongside main's new tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 4, 2026 03:49

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 launcher reuse test leaves the partition cap and window offset unchanged, so it cannot detect unintended specialization on these runtime parameters.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread op_tests/test_flydsl_pa_decode.py Resolved

@zhiding512 zhiding512 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.

Reviewed at 23eca08 and tested it on gfx950 (MI355X, 256 CUs, torch 2.10 / ROCm 7.2.4). I found no correctness issues. The inline comment and the two thread replies are non-blocking.

What I checked in the code:

  • The clipped final bucket always fits LDS, since _lds_max_batch inverts the LDS check right above it.
  • With lookup_bits = (max_batch - 1).bit_length(), the task lookup still reaches every row below the bucket bound.
  • Buckets up to the block size take the one-row-per-thread straight-line path.
  • jobs_for_arch replays every block size (64 to 1024 threads) the runtime can pick for a bucket.
  • The compile_pa_decode_plan signature change breaks no other caller.

gfx950 results at the head:

  1. test_pa_decode_plan: 11 passed. All of op_tests/test_flydsl_pa_decode.py: 347 passed, 37 skipped.
  2. GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.pa_decode_plan into an empty cache: 96 ok, 0 failed.
  3. test_pa_decode_plan against that cache with FLYDSL_RUNTIME_RUN_ONLY=1: 8 passed, 3 failed. The three failures are the cap-100 and cap-5000 cases, which the README says need their own run, so they are expected. The lds-limit case (final bucket 40832) loaded from the cache. So did the cases whose max_partitions and window differ from the replayed values, so neither value is compiled into the kernel.

Not covered: gfx1250 at this head (no machine available today). The gfx1250 data posted so far was measured before the partition cap and window became runtime values. The kernel change is arch-independent, so the risk is low, but one planner test run on gfx1250 would close this gap.

My earlier thread on the 64-row floor is addressed at this head, since buckets now start at 1.

fsx950223 and others added 2 commits November 4, 2026 07:42
A cap between a batch and its power-of-two bound gives the same lookup
depth and the same row path, and the planner's single block pays nothing
for the larger LDS array, so buckets now clip only to the device's LDS.
One AOT set per arch then serves every max_batch_size: the AOT module
drops its --max-batch-size option and job key, and the cap-100 and
cap-5000 planner cases expect buckets 128 and 8192.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reuse case kept max_partitions and the window offset unchanged, so a
launcher specialized on either would still have passed. It now also picks
the smallest partition cap that admits a capacity one slot away, so long
rows reach it, and moves a positive window and the query length, then
checks launcher identity and metadata against the new values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 4, 2026 07: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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@fsx950223

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the gfx950 run. Both follow-ups are in at 9e616c4:

  • 20fceda: buckets clip only to LDS, so the wheel's AOT set serves every max_batch_size; --max-batch-size and the README paragraph about other caps are gone.
  • 9e616c4: the reuse case also changes the partition cap, the window and the query length.

At 9e616c4 on MI355X (gfx950, 256 CUs, torch 2.10 / ROCm 7.2.4, FlyDSL 0.4.1), test_pa_decode_plan gives 11 passed. GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.pa_decode_plan into an empty cache succeeded. Against that cache with FLYDSL_RUNTIME_RUN_ONLY=1, the planner test gives 11 passed, now including the cap-100 and cap-5000 cases. On MI308X, the full PA decode test file gives 277 passed, 107 skipped. The description and self-review are updated for this head.

gfx1250 at this head is still unverified, and the description lists it under unverified scope.

@coderfeli
coderfeli merged commit bb0f9c4 into main Nov 5, 2026
@coderfeli
coderfeli deleted the fix/flydsl-pa-plan-dynamic-batch branch November 5, 2026 03:14
fsx950223 added a commit that referenced this pull request Nov 5, 2026
Resolve conflicts with the runtime-batch PA planner (#7205).

- The planner keeps main's batch buckets and runtime batch, capacity,
  partition cap and window, and compiles the context partition size as
  a constant in place of 256. A runtime shift instead measured up to 2%
  slower per refresh on gfx1250; with the constant, refreshes match main
  within 0.3% and 256-token plans produce identical metadata.
- The planner AOT module replays every partition size an arch supports:
  gfx1250 builds 196 kernels (128 and 256 tokens), gfx942 and gfx950
  keep 96.
- test_pa_decode_plan, restored on main, checks tiles against the plan's
  partition size, the default size of new and hand-built plans, and that
  each other size compiles its own kernel for the same bucket.

gfx1250: op_tests/test_flydsl_pa_decode.py 274 passed, 159 skipped;
test_pa_decode_plan passes against a freshly built AOT cache with
FLYDSL_RUNTIME_RUN_ONLY=1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rebklee added a commit to rebklee/aiter that referenced this pull request Nov 25, 2026
Conflicts in op_softmax.py, traits.py, pa_decode_kernel.py,
pa_decode.py, pa_decode_tuning.py and test_flydsl_pa_decode.py, all
where main and this PR add fields or arguments side by side. Kept
main's code and added causal on top:
- traits.py: causal is a named PaDecodeCacheKey field, which main now
  builds by keyword, and the last Gfx1250Traits field, since
  gfx1250_tile_traits passes the earlier ones by position.
- pa_decode_kernel.py: causal reaches compile_gfx1250_pa_decode through
  Gfx1250Traits, and ROCm#7619's wave-pair pipelines keep this PR's
  causal_rows gate.
- pa_decode.py: causal goes into tile_options, which feeds the cluster
  steps probe, _fuses_quant_output and compile_pa_decode_tile.
- op_softmax.py: this PR's causal-aware slack, with TILE_TOK renamed
  to KV_COMPUTE_BLOCK.
- The test file keeps both case lists. _check_pipe_policy builds one
  set of schedule kwargs for the MTP4 pin and main's pipe and NHD
  pins.

Main's BF16_MTP_FUSED, FP8_MTP4_LEAN and NHD paths take their row
bounds from context.py's offsets, so causal=False reaches them
unchanged. With main's planner fallback for torch builds without
shared_memory_per_block (ROCm#7205), the non-causal cases also pass on
torch 2.9.1.

Signed-off-by: Rebecca Lee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants