Skip to content

[FlyDSL] [Bugfix] Fix PA decode scaling and merge alignment - #7147

Merged
zhiding512 merged 2 commits into
ROCm:zhiding512/gfx1250-pa-merge-partitionsfrom
fsx950223:fix/pr7079-pa-decode-correctness
Oct 30, 2026
Merged

zhiding512 merged 2 commits into
ROCm:zhiding512/gfx1250-pa-merge-partitionsfrom
fsx950223:fix/pr7079-pa-decode-correctness

Conversation

@fsx950223

Copy link
Copy Markdown
Contributor

Summary

Finite FP8 inputs can produce NaNs or lose V normalization in #7079's gfx1250 per-wave path when per-token K scales or logits are large. Offset scratch can also select a last-arriver merge with misaligned 64-bit atomics, while the cluster merge declares vector alignment that offset scratch and odd output strides do not guarantee.

This follow-up targets zhiding512/gfx1250-pa-merge-partitions, the branch behind #7079. Merging it updates that PR.

Changes

  • Apply query scaling before per-token K scaling, then subtract the softmax maximum before adding log2(vnorm) to the exponent.
  • Require eight-byte partial-scratch alignment when selecting the last-arriver merge. Offset views use the existing cluster merge or reducer fallback.
  • Declare element alignment for cluster partial loads and output stores, retaining the vector accesses.
  • Document the atomic alignment requirement and add 12 merge-alignment regressions covering BF16/FP16, offset scratch, odd strides, fallback selection and reset arrival counters.
  • Skip positive BF16-cache/FP16-query cases outside gfx1250, while preserving invalid-input rejection checks. Add four simulated gfx942/gfx950 policy checks.
  • Remove the standalone test_pa_decode_plan and test_pa_decode_graph_plan_refresh functions.

Performance

These are correctness fixes. A fixed eight-partition FP8 dense-verify measurement (H16/KV1/D128, page128, three requests with four causal queries each) shows their cost relative to the original #7079 head 007cc391b:

Context Original #7079 With fixes Latency increase
8K 11.149 µs 11.834 µs 6.2%
32K 32.223 µs 35.125 µs 9.0%

Separately, the fixed #7079 branch remains 1.27× faster geometrically across 28 dense decode/verify, sparse decode/verify/prefill and ATOM-plan workloads than latest main 269675dead7aa919c9c5eae09cb42e83a35c6567 (BF16 1.29×, FP8 1.26×). That comparison measures the whole #7079 branch plus these fixes. The one-partition ATOM prefill path is effectively unchanged.

Measurements used gfx1250 (256 CUs), physical GPU 1, PyTorch 2.11 ROCm 10.1, HIP 7.16 and FlyDSL 0.4.1, with GPU jobs serialized. The latest-main comparison uses identical seeded inputs and plans, five ten-call CUDA graphs with five timed replays each, and the median of three alternating rounds. Timings include decode and reduction, excluding planning, compilation and allocations. Three short dense decode cases had round spans above 10%; their exact ratios are less stable. Bandwidth and roofline counters were not collected.

Testing

  • Full final suite on gfx1250: python -m pytest -q op_tests/test_flydsl_pa_decode.py — 209 passed, 5 skipped.
  • Repository pre-commit hook, Black, Ruff and git diff --check passed on the five changed files.
  • All 28 benchmark cases produced finite outputs after graph replay and passed sampled FP32 reference checks. Inputs, plan capacities and partition counts match main; 22 outputs match bit for bit. Maximum relative L2 output difference: 0.00321. Maximum change in relative L2 reference error: 0.0000183.
  • Cluster IR uses element-aligned vector loads/stores (align 2); offset numerical checks match the reference.
  • gfx942/gfx950 validation covers simulated test-policy behavior. Physical kernel validation was performed on gfx1250.

@zufayu
zufayu requested a review from coderfeli October 30, 2026 01:26
@zufayu
zufayu removed the request for review from coderfeli October 30, 2026 01:54
Keep the merge-alignment changes, but restore the fused exponent of
unmasked per-token FP8 pages, which folds the query scale and log2(vnorm)
into one FMA. Splitting it added two VALU operations per score: the
unmasked page loop traded 32 v_pk_fma_f32 for 32 v_pk_mul_f32 and 64
v_pk_add_f32. Finite inputs with large per-token K scales or logits can
again overflow or lose the V normalization.

FP8 dense verify on gfx1250 (H16/KV1/D128, page 128, three requests with
four causal queries, eight partitions), median of ten alternating rounds:

  context  007cc39  8f7fc89          this commit
  8K       11.053 us  11.716 us (+6.0%)  11.046 us (-0.1%)
  32K      31.763 us  34.623 us (+9.0%)  31.761 us (0.0%)

The merge-alignment changes leave this shape's FP8 and BF16 tile-kernel
ISA unchanged.

Co-authored-by: Cursor <[email protected]>
@zhiding512
zhiding512 merged commit 56badf9 into ROCm:zhiding512/gfx1250-pa-merge-partitions Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants