Repository navigation
[FlyDSL] [Misc] Simplify PA decode reducer bound and reuse shared helpers - #7077
Conversation
- Fold the reducer's partition_bound into max_partitions: pa_decode passes one tight per-call bound; above a wave the power-of-two round-up is capped by the CU count. - Use dtypes.fp8 for the KV FP8 dtype, tensor_shim._FX_ELEM for the reducer's dtype lookup, and fx.as_ir_value instead of _to_raw. - Name the gfx1250 thread count Gfx1250Traits.BLOCK_THREADS instead of hardcoding 128. - Treat any nonpositive sliding_window as disabled in pa_decode and plan_pa_decode instead of rejecting values below -1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
#7077 made pa_decode require dtypes.fp8 for FP8 KV instead of a per-arch dtype table. The capability and default-budget helpers still used that table, so they could accept a dtype pa_decode rejects. Compare against dtypes.fp8 there too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…7077) - Fold the reducer's partition_bound into max_partitions: pa_decode passes one tight per-call bound; above a wave the power-of-two round-up is capped by the CU count. - Use dtypes.fp8 for the KV FP8 dtype, tensor_shim._FX_ELEM for the reducer's dtype lookup, and fx.as_ir_value instead of _to_raw. - Name the gfx1250 thread count Gfx1250Traits.BLOCK_THREADS instead of hardcoding 128. - Treat any nonpositive sliding_window as disabled in pa_decode and plan_pa_decode instead of rejecting values below -1. Co-authored-by: who who who <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
… the gfx950 head-256 PA decode pipe (#5949) * [FlyDSL] Add the NHD page-64 layout to the gfx950 head-256 PA decode pipe A 4D key_cache selects NHD: K and V are [num_blocks, 64, num_kv_heads, 256] views with a contiguous head axis and arbitrary other strides, such as both halves of one token row. The pipe reads K with NHD addressing and copies V into LDS with nontemporal buffer-to-LDS DMA, read back with transposed LDS reads. Two V buffers overlap the next tile's copy with PV; a grid wider than the CU count uses one when two single-buffered CTAs fit in LDS. Hardware out-of-bounds zero-fill covers partial-page tails. NHD supports per-tensor and per-token scales and positive sliding windows. It requires gfx950, FP8 KV, head 256, page 64, and at most 32 query rows; other shapes, including page 16, raise NotImplementedError. Strides must be 16-byte multiples and fit int32, and wide addressing is chosen from the highest byte either view reaches. Tuning reads KV heads and page size from NHD caches and keys results by layout. NHD folds the softmax scale into exp2 rather than scaling scores before masking, which is up to 8% faster on its attention kernel at long context. Packed caches keep main's code paths and timings. Co-authored-by: fsx950223 <[email protected]> Co-authored-by: Cursor <[email protected]> * [FlyDSL] Default dense page-64 head-256 PA decode plans to one CTA per CU A prepare_pa_decode_plan cache miss used a 2*CU workgroup budget for every shape. On the gfx950 FP8 head-256 pipe with page 64 and no sliding window, a CU-count budget is as fast or faster at every measured batch and context: up to 12% faster for packed per-token caches at query length 4 and up to 16% for NHD. Batch 1 plans are identical. Page 16 and windowed shapes are as fast or slightly faster at 2*CU, so they and every other path keep it. The tuning search adds the CU count to its candidates, and the pa_decode docstring and tuning README describe the per-shape default. Co-authored-by: Cursor <[email protected]> * [FlyDSL] Simplify NHD validation and the PA decode default budget Check NHD support once, early in pa_decode, with a shared page-64 pipe predicate that the default budget also uses. Validate NHD strides in one block and pass the validated strides to the kernel, instead of computing them again after the plan checks. Skip the NHD LDS footprint for packed caches. The default budget takes the autotune key directly, maps the KV dtype the same way pa_decode does, and rejects a non-integer sliding window. The pre-PV V-DMA wait is constant for single-tile plans, and its comment notes that later loads only make the wait stricter. Tests read named trait fields instead of cache-key positions, poison K as well as V tails, add a two-KV-head case with every head in one token row, and use aiter.dtypes. Co-authored-by: Cursor <[email protected]> * [FlyDSL] Add a public NHD-support capability API for downstream callers Downstream integrations had to probe private symbols and inspect pa_decode's signature to learn whether this build serves the NHD layout (4D K/V caches, selected by key_cache.dim() == 4 / trans_k=False). Export a small documented surface from aiter.ops.flydsl.pa_decode and aiter.ops.flydsl: - pa_decode_nhd_supported(): whether pa_decode can serve an NHD call for an architecture, KV dtype, head dim, page size, query length, GQA group and sliding window. - PA_DECODE_NHD_MAX_QUERY_ROWS: the query_length * query_group_size limit. - PA_DECODE_NHD_MIN_FLYDSL_VERSION: the FlyDSL release NHD requires. - pa_decode_default_workgroup_budget(): the budget prepare_pa_decode_plan uses on a tuning-cache miss (one workgroup per CU for dense page-64 head-256 FP8 pipe shapes, 2*CU otherwise). The predicate, pa_decode and PaDecodeSchedule share one validation (require_nhd_pipe plus the FlyDSL version gate), and the tuning module reuses the public budget function, so none of them can drift from the kernel's behavior. Co-authored-by: Cursor <[email protected]> * [FlyDSL] Narrow the PA decode NHD capability API Callers need the longest NHD query length and the untuned work budget, not a per-query boolean plus version and row-limit constants. Both functions take the device, and plan_pa_decode and PADecodePlan are exported from aiter.ops.flydsl. Co-authored-by: Cursor <[email protected]> * [FlyDSL] Keep the gfx1250 PA decode launch unchanged by the NHD strides The NHD strides were inserted positionally in PaDecodeContext and always appended to the launch arguments, so the gfx1250 kernel's 21-value context call and its 19-parameter launcher no longer bound. Make the six strides keyword-only context arguments that default to None, pass them by keyword from the gfx942/gfx950 tile task, and leave them out of the gfx1250 launch. NHD stays gfx950-only and the gfx1250 kernel is untouched. Co-authored-by: Cursor <[email protected]> * [FlyDSL] Reject a non-positive or non-finite PA decode softmax_scale Paths that apply the scale after masking, including NHD and the generic per-tensor path, give masked tokens weight for a negative or zero scale and return wrong values or NaN. pa_decode now raises ValueError unless softmax_scale is finite and positive, before any kernel is compiled. Co-authored-by: Cursor <[email protected]> * [FlyDSL] Use get_gfx_runtime in the PA decode capability API pa_decode_nhd_max_query_length and pa_decode_default_workgroup_budget read the architecture from gcnArchName, while pa_decode and plan preparation use get_gfx_runtime. Use the shared helper so the API cannot disagree with dispatch; the device still supplies the CU count. Co-authored-by: Cursor <[email protected]> * [FlyDSL] Match the PA decode capability API to pa_decode's FP8 dtype #7077 made pa_decode require dtypes.fp8 for FP8 KV instead of a per-arch dtype table. The capability and default-budget helpers still used that table, so they could accept a dtype pa_decode rejects. Compare against dtypes.fp8 there too. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [FlyDSL] Keep pa_decode exported as the function after sibling imports Loading a lazy export from aiter.ops.flydsl.pa_decode or pa_decode_tuning imports the pa_decode submodule, and Python binds it on the package under the same name as the pa_decode export. `from aiter.ops.flydsl import plan_pa_decode, pa_decode` then returned the module. Drop such bindings after each lazy load so the export resolves instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [FlyDSL] Skip the PA decode import-order test when FlyDSL is missing The subprocess imports aiter.ops.flydsl, which imports flydsl, so without FlyDSL it failed instead of skipping like the rest of the module. Co-Authored-By: Claude Code <[email protected]> * [FlyDSL] Skip the V tail masking for NHD layouts NHD V is loaded by an LDS DMA that already zero-fills past the context, so the mask_unowned_kv V byte masks are redundant there and cost time at the 2xCU budget. K/V scale masking is unchanged. Co-Authored-By: Claude Code <[email protected]> * [FlyDSL] Tolerate concurrent lazy imports when dropping shadow bindings Two threads resolving exports at once could both see the submodule binding, and the second delete raised KeyError. Use get and pop so the cleanup is idempotent. Co-Authored-By: Claude Code <[email protected]> * [FlyDSL] Reject zero KV heads before computing the PA decode group size prepare_pa_decode_plan divided the query heads by the cache's KV head count before the planner validated it, so a zero-head cache raised ZeroDivisionError instead of ValueError. Co-authored-by: Copilot <[email protected]> * Fix FlyDSL formatting checks Co-authored-by: samremes <[email protected]> * [FlyDSL] Reject non-positive host K/V scales in pa_decode Per-tensor FP8 paths, including NHD, mask scores before applying the scale, so a negative or zero scale corrupts the row max. Reject non-finite or non-positive host-scalar key_scale/value_scale; device tensors are not read back, to avoid a sync, and are documented as requiring positive values. Co-authored-by: Copilot <[email protected]> * [FlyDSL] Check the K/V scale rejection in the softmax_scale test Pass each rejected value as a host-scalar key_scale in the existing softmax_scale rejection test instead of a separate test. Co-authored-by: Copilot <[email protected]> * [FlyDSL] Use packed caches in the scale rejection test NHD caches raise NotImplementedError on gfx942 and gfx1250 before the K/V scale check runs. Packed caches reach scale validation on every arch. Co-authored-by: Copilot <[email protected]> * [FlyDSL] Mask scores on multi-tile NHD q=1 partial tails Co-authored-by: Copilot <[email protected]> * [FlyDSL] Use plan_pa_decode in NHD partial-tile zero-logit test Co-authored-by: Copilot <[email protected]> * [FlyDSL] Reject negative stepped NHD strides in pa_decode Co-authored-by: Copilot <[email protected]> * [FlyDSL] Remove unconstructible negative-stride as_strided test case Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: fsx950223 <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: samremes <[email protected]> Co-authored-by: Copilot <[email protected]>
Motivation
Cleanups in the FlyDSL PA decode wrapper and kernels. The reducer launcher took two partition limits where one is enough, and several spots duplicated helpers that aiter or FlyDSL already provide.
Changes
launch_pa_decode_ps_reducetakes a singlemax_partitions, which is the tight per-call bound.pa_decodecomputes it from the plan cap, plan capacity, context tiles and the sliding-window cap, and the separatepartition_boundargument is removed.max_partitions. With a non-default plan cap that isn't a power of two, the compiled bound can round past it (for example 100 → 128). This is safe because the reducer's per-sequence buffer bound zero-fills partitions beyond the live count.pa_decodeusesdtypes.fp8instead of its own arch → FP8 dtype table. The supported-arch check stays.tensor_shim._FX_ELEMinstead of a local_DTYPE_MAP, and still accepts onlyf32,f16andbf16.fx.as_ir_valueinstead oftensor_shim._to_raw.Gfx1250Traits.BLOCK_THREADS(NWARP * WAVE= 128) replaces the hardcoded 128 inknown_block_size, the launch block, the direct-output copy loop andstage_vector_dma. It's a class constant, not a dataclass field, so traits cache keys don't change.sliding_window:pa_decodeandplan_pa_decodetreat any nonpositive value as disabled instead of raising for values below -1. The docstrings say so.Test
op_tests/test_flydsl_pa_decode.pyon gfx1250 with FlyDSL 0.4.0: 119 passed, 5 skipped.plan_pa_decode(..., sliding_window=-5)builds the same plan as-1.dtypes.fp8and_FX_ELEMchanges also apply there.blackandruffpass.🤖 Generated with Claude Code