Repository navigation
[FlyDSL] Make PA planner batch and capacity runtime values - #7205
Conversation
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.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
zhiding512
left a comment
There was a problem hiding this comment.
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]>
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]>
|
@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 |
|
No blocking issues. Correction of my earlier ask: the planner already rounds 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. EvidenceFirst
With a warm on-disk cache a length seen before still reloads per process (about 23 ms each). Bitwise check: |
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]>
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]>
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]>
zhiding512
left a comment
There was a problem hiding this comment.
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_batchinverts 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_archreplays every block size (64 to 1024 threads) the runtime can pick for a bucket.- The
compile_pa_decode_plansignature change breaks no other caller.
gfx950 results at the head:
test_pa_decode_plan: 11 passed. All ofop_tests/test_flydsl_pa_decode.py: 347 passed, 37 skipped.GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.pa_decode_planinto an empty cache: 96 ok, 0 failed.test_pa_decode_planagainst that cache withFLYDSL_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. Thelds-limitcase (final bucket 40832) loaded from the cache. So did the cases whosemax_partitionsand 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.
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]>
|
Thanks for the review and the gfx950 run. Both follow-ups are in at 9e616c4:
At 9e616c4 on MI355X (gfx950, 256 CUs, torch 2.10 / ROCm 7.2.4, FlyDSL 0.4.1), gfx1250 at this head is still unverified, and the description lists it under unverified scope. |
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]>
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]>


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_sizealready 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
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.(max_batch - 1).bit_length()levels. Rows lie belowmax_batch, somax_batch.bit_length()did one extra LDS read per slot at power-of-two buckets.fx.Int32kernel arguments. Capacity only determines the64–1024thread block-size bucket; allocation sizes and partition-budget calculations remain exact.query_length - 1 + sliding_windowasfx.Int32kernel arguments. The offset is clamped to2**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.aiter/aot/flydsl/pa_decode_plan.py, a replaying module likefmha_fp8.py([FlyDSL] [JIT] Build the GEMM, conv, chunk_gdn_h and FP8 FMHA AOT caches by replaying the runtime #6956), and register it inAOT_MODULES, sorun_aot, whichPREBUILD_KERNELSwheel builds call, builds it. It replaysplan_pa_decodeitself on FakeTensors insidedry_run, so the planner's own rules pick each kernel. For each architectureGPU_ARCHSnames (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 ignoremax_batch_size, the set serves every cap.python -m aiter.aot.flydsl.pa_decode_planbuilds it outside a wheel build, and--checkreports missing kernels without compiling.aiter/aot/flydsl/README.mddocuments it.shared_memory_per_block.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 tomax_batch_sizeHardware: AMD Instinct MI308X (
gfx942, 80 CUs). Before is the kernel that23eca0860'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 identicalwork_infoandreduce_info. Spread between processes is up to 2.1%; within each process the after/before ratio stays within 0.3% of 1.max_batch_size=100, capacity=160 (256 threads)max_batch_size=100, capacity=160 (256 threads)max_batch_size=1500, capacity=1500 (1024 threads)max_batch_size=3000, capacity=3000 (1024 threads)max_batch_size=5000, capacity=4097 (1024 threads)max_batch_size=5000, capacity=5000 (1024 threads)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
a2fb1f4ceIn 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 at05dbf3453);01788507bandca05d2dbaare earlier commits of this PR. Compilation is excluded. All plans use one KV head,sliding_window=0, andquery_length=1. All four kernels produce identicalwork_infoandreduce_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).01788507bca05d2dbaBucket boundaries and large batches:
max_parts=80, sparse lengths as above, and the default workgroup budget (capacity equals batch) unless stated. Batches above 4096 usemax_batch_size=32768.01788507bca05d2dbaThe 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:
01788507b, bucket 3276801788507b, bucket 4096First-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
5029f684aHardware: 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 heada2fb1f4ce; 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 usesmax_batch_size=16384. Run-to-run spread is at most 1.9%.query_length=4query_length=4Batch 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_partitions7 and 1 (36 plans in total), head and baseline produce identicalwork_infoandreduce_info.AOT compilation on this host, with the GPUs hidden: at
23eca0860the wheel set of 290 kernels for gfx942, gfx950 and gfx1250 replayed in 9.6 s throughpython -m aiter.aot.flydsl.pa_decode_plan(ate91be70a0, before the replay port, 304 kernels took 8.9 s throughrun_aot).MI308X, first commit
01788507bThese 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 usingtriton.testing.do_bench_cudagraph(rep=20), taking the median of three measurements with interleaved before/after order. The baseline is main8bcab96511; compilation is excluded. Both kernels usemax_parts=80,sliding_window=0, andquery_length=1, with context lengths repeating(257, 0, -1, 1027, 4096, 16384, 65537, 12345). Each configuration produces identicalwork_infoandreduce_infobefore and after.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
Head
9e616c422(buckets no longer clip tomax_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 head23eca0860(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. Commit5029f684awas 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. Commite91be70a0changes only AOT registration and documentation; its wheel AOT set was validated on the same GPU. Commita2fb1f4cewas 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
The planner docstring describes compilation buckets, runtime parameters, and LDS clipping, and points to the AOT script, which
aiter/aot/flydsl/README.mddocuments. Public calling conventions are unchanged, so no user-guide migration is needed.Dependencies
Breaking Changes
None for the public
plan_pa_decodeandPADecodePlanAPIs. The internalcompile_pa_decode_planfactory now takesmax_batch,threadsandwindowedin 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
9e616c4228ef7fc7b40c4d2b921c7046f4d0c35eBehavior 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_aotreplays the planner over that set for wheel builds up to each architecture's LDS limit.Validation and unverified scope
Head
9e616c422takes two review follow-ups: buckets no longer clip tomax_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 ofop_tests/test_flydsl_pa_decode.py: 277 passed, 107 skipped.tests/test_flydsl_aot_replay.py: 5 passed.HIP_VISIBLE_DEVICES=-1 python -m aiter.aot.flydsl.pa_decode_planinto an emptyFLYDSL_RUNTIME_CACHE_DIR: gfx942 96, gfx950 96 and gfx1250 98 replays ok, 0 failed, the same counts as23eca0860since that set already reached every LDS limit;--checkthen 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.ruff==0.16.0check: passed on the changed Python files.Head
9e616c422on 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_planinto an empty cache succeeded, andtest_pa_decode_planagainst it withFLYDSL_RUNTIME_RUN_ONLY=1: 11 passed, including the cap-100, cap-5000 and LDS-limit (bucket 40832) cases. At23eca0860, the reviewer ran all ofop_tests/test_flydsl_pa_decode.pyon gfx950 (347 passed, 37 skipped).Merge head
23eca0860environment: 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 removedOpKind, so the AOT module was ported to the replay driver; the planner kernel and runtime code are unchanged apart from main'sarrival_counters.python -m aiter.aot.flydsl.pa_decode_planinto an emptyFLYDSL_RUNTIME_CACHE_DIR: gfx942 96, gfx950 96 and gfx1250 98 replays ok, 0 failed, including the full-LDS buckets;--checkthen reported 0 failed.e91be70a0'splan_variantsminus 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.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. AfterGPU_ARCHS=gfx942 python -m aiter.aot.flydsl.pa_decode_plan --max-batch-size 100 5000into 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 --checkandruff==0.11.11 checkon the changed Python files: passed.Commit
e91be70a0and commit5029f684aenvironment: 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 used5029f684a.run_aotinto 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.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 16257into an emptyFLYDSL_RUNTIME_CACHE_DIR, thenFLYDSL_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.2**31 - 1(windows up to2**40, query lengths 1 to 20) and lengths near2**31 - 1.ruff==0.16.0check: passed on the changed Python files.Commit
a2fb1f4ceenvironment: 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.query_length=4,max_partitions=1, and all lengths at2**31 - 1.pa_decode(BF16) at batch 32768 matched the FP32 reference (max error 6.3e-4). Cases: single-token decode at capacity 32768 and 131072, andquery_length=4with window 257; 8192 sequences use multiple tasks.python -m black --checkandruff checkon both changed files: passed.git show --check: passed.test_pa_decode_plan; merge head23eca0860keeps 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
01788507benvironment: 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.Head
9e616c422has 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 completePREBUILD_KERNELSwheel build andrun_aotwith the MoE and other replays enabled were not run. End-to-end serving latency and startup savings remain unmeasured.PR-specific question
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.