Skip to content

[FlyDSL] Optimize PA partition reduction (split from #5949) - #6619

Merged
coderfeli merged 2 commits into
mainfrom
perf/flydsl-pa-reducer
Oct 16, 2026
Merged

coderfeli merged 2 commits into
mainfrom
perf/flydsl-pa-reducer

Conversation

@fsx950223

@fsx950223 fsx950223 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Main's FlyDSL PA reducer spends unnecessary work on a large partition cap, and reduction becomes expensive for long contexts. Extract the rewritten partition reducer from #5949 (179193716f3e7b6136e9f98f85c8f3c0292a963b; reducer introduced in 9bcb97c9d) into a separate change based on main 42c2b1427.

The reducer uses exact register specializations through 64 partitions, a runtime register ladder for up to 32 live partitions under larger bounds, and LDS partition groups for larger live counts. BF16/FP16 paired loads, launch-shape-based group selection, and XCD-aware CTA order reduce work and scheduling overhead. The host bounds specialization by context tiles, plan capacity and sliding-window tiles while retaining reusable plan/scratch buffers.

Scope is the reducer kernel and its host dispatch/call site. Attention tile compilation/launch, attention pipeline, planner, tuning defaults and NHD support are unchanged. The reducer kernel matches #5949 verbatim. Credits to @samremes for the reducer implementation.

Performance

MI355X/gfx950, 256 CUs, FlyDSL 0.4.0, PyTorch 2.12.0+rocm7.14.0, HIP 7.14.60850. These are fresh measurements of this extracted branch against main, using warm CUDA graphs and medians across three independent processes. All times are microseconds.

Reducer-only: D256, BF16 partials/output, QL4, GQA8, Hkv1. Both columns retain compile-time partition cap 256, including the low-live-count rows. Same packed scratch and input tensors; 100 reducer calls per graph, seven timing rounds with rotating implementation order.

Batch Live partitions Main This PR Latency change
6 1 2.525 1.842 -27.0%
6 4 2.822 1.969 -30.2%
6 8 3.237 2.058 -36.4%
6 16 4.039 2.303 -43.0%
6 64 8.814 2.897 -67.1%
6 256 29.668 4.260 -85.6%
32 1 2.884 1.884 -34.7%
128 1 5.605 2.738 -51.2%
32 16 4.624 2.511 -45.7%
128 32 23.740 11.789 -50.3%

These high-cap cases also cover the earlier regression reported in #5949: none regresses versus main. A tighter valid host bound can further reduce short-count latency.

Full PA uses main's existing attention implementation in both columns. Each graph contains 50 steps, including GPU plan refresh, attention and reduce, with planner defaults max_partitions=256, workgroup_budget=512. FP8 KV with per-token scales, BF16 Q/output, D256, GQA8, Hkv1; host context bound equals live context. The reduction timing is measured separately on attention-produced scratch.

Context Page QL Batch Main reduce / full step This PR reduce / full step
256 16 4 6 2.504 / 13.419 1.725 / 12.407
256 16 4 32 2.882 / 13.408 1.791 / 12.374
256 16 4 128 5.523 / 16.998 2.549 / 14.173
65536 64 1 1 29.203 / 79.477 3.773 / 15.017
65536 64 1 4 15.696 / 61.010 3.121 / 29.424

The full PA improvement comes from reduction and its specialization bound; attention code is unchanged. Isolated reducer numbers are warm-scratch measurements; each full step writes scratch again in attention. In particular, main's long-context reducer has a substantially higher latency inside the full step than when repeatedly reducing the same scratch. Do not subtract isolated reducer time from full-step time to infer attention latency.

Profiling the long-context 50-step graphs corroborates that attribution. Attention kernel time stays essentially equal while the reducer accounts for the full-step improvement. Per-process medians of three profiler captures, then medians across three processes:

Context Batch Main attention This PR attention Main reduce This PR reduce
65536 1 7.797 7.757 68.764 4.626
65536 4 22.402 22.390 35.500 4.064

Validation

  • Existing op_tests/test_flydsl_pa_decode.py suite: 106 passed on MI355X/gfx950 and 106 passed on MI308X/gfx942 (80 CUs).
  • Full PA benchmarks pass an independent FP32 causal-attention reference.
  • Black, Ruff 0.16.0, Python compilation and git diff --check pass.

GPU suites run with AITER_AOT_IMPORT=1 and equivalent pure-Torch quantization helpers injected into the existing test harness to avoid unrelated C++/CK builds. PA implementation and test assertions are unchanged by that harness.

Use host-bounded register ladders and a dual register/LDS reducer, with paired loads, launch-shape partition groups and XCD-aware CTA order. Preserve the existing main attention implementation and reusable planner scratch.

Add FP32-oracle tests for mixed and empty partition counts, sinks, poisoned scratch and graph replay across the supported head sizes and output dtypes.

Co-authored-by: Sami Remes <samremes@amd.com>
@fsx950223
fsx950223 requested review from a team and a balanced review from Copilot October 16, 2026 09:47

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 reached their quota limit.

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

Copilot AI balanced review requested due to automatic review settings October 16, 2026 09: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 reached their quota limit.

samremes added a commit that referenced this pull request Oct 16, 2026
The rewritten reducer now lives in #6619. This branch keeps the gfx950 head-256 pipe, including per-token scales.

Co-authored-by: Cursor <cursoragent@cursor.com>
@samremes

Copy link
Copy Markdown
Contributor

#5949 no longer carries the rewritten reducer (8cf11692f9 restores main's). This PR is the one to merge for it. The reducer kernel here still matches the version that was on #5949 at 179193716f.

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.

4 participants