Skip to content

[AMD] Fix AITER unified decode page table for page size one - #40410

Open
vorapolsiloai wants to merge 2 commits into
sgl-project:mainfrom
vorapolsiloai:fix/aiter-page1-cuda-graph-table
Open

vorapolsiloai wants to merge 2 commits into
sgl-project:mainfrom
vorapolsiloai:fix/aiter-page1-cuda-graph-table

Conversation

@vorapolsiloai

@vorapolsiloai vorapolsiloai commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

With AITER unified attention, page size 1 and CUDA graphs, decode reads a page table that graph replay never filled, so the output is wrong. _apply_cuda_graph_metadata() skipped page_size == 1; eager decode builds the table for every page size.

MI355X: the new test fails on main (all 6 checked page-table entries differ) and passes with it; Qwen3.8-27B MXFP4 GPQA 48.48%, same as the BF16-query reference. Not claimed: any performance change.

Modifications

  • Always copy the page indices into cuda_graph_page_table; convert with _transform_table_1_to_real only when page_size > 1.
  • Add test_cuda_graph_decode_copies_page_size_one_table.
Motivation and modifications in full

With AITER unified attention (SGLANG_USE_AITER_UNIFIED_ATTN=1), page size 1 (the default), and CUDA graphs enabled, decode reads a page table that was never filled in, so the output is wrong.

Before each CUDA graph replay, AiterAttnBackend._apply_cuda_graph_metadata() copies the request-to-token indices into the persistent cuda_graph_page_table. It did this for the sliding-window KV pool and for page_size > 1. It skipped page_size == 1, so the replay read the table's initial or stale contents. Eager decode (init_forward_metadata) builds this table for every page size, so only graph replay is affected. Query and KV dtypes do not matter.

I found this while validating #39998. The bug is in the existing decode metadata path, so the fix is a separate PR.

  • In the CUDA graph decode metadata path, always copy the page indices into cuda_graph_page_table. Convert them with _transform_table_1_to_real only when page_size > 1. This matches the eager path.
  • Add test_cuda_graph_decode_copies_page_size_one_table. It calls _apply_cuda_graph_metadata() with page_size=1 and checks that the graph page table holds the req_to_token rows.

Accuracy Tests

Accuracy detail
  • The new test fails without the fix (all 6 checked page-table entries differ) and passes with it on MI355X.
  • test/registered/attention/test_aiter_fp8_q_unified_attention.py passes on MI355X.
  • Re-validated post-rebase on AMD Instinct MI355X (ROCm 10, AITER): test_cuda_graph_decode_copies_page_size_one_table and all 4 unit tests in test/registered/attention/test_aiter_fp8_q_unified_attention.py pass cleanly.
  • End-to-end check: Qwen3.8-27B MXFP4, MI355X, TP1, FP8 KV cache, AITER prefill and decode, CUDA graphs on. This stack also included [Perf] [AMD] aiter: Quantize unified prefill Q to FP8 when the KV cache is FP8 #39998.

Speed Tests and Profiling

Correctness fix, one device-to-device copy per graph replay; not meant to change performance.

Checklist

  • Format code with pre-commit.
  • Add unit tests.
  • Provide accuracy results.

CI States

Latest PR Test (Base): ❌ Run #41333427316
Latest PR Test (Extra): ❌ Run #41333427253
Latest PR Test (AMD ROCm 10): ❌ Run #41333427179

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

Unified decode reuses a capture-stable page table during CUDA graph replay, but the page-size-one path never populated it. Copy the request-to-token indices into that table just as the paged paths do.

- Populate generic unified-decode metadata for page size one
- Add a regression that fails with the zero-initialized graph table
@vorapolsiloai
vorapolsiloai force-pushed the fix/aiter-page1-cuda-graph-table branch from 42ff68a to ee754ea Compare October 26, 2026 23:21
@github-actions

This comment has been minimized.

…ph test

The test builds AiterAttnBackend without __init__, and
_apply_cuda_graph_metadata now reads decode_uses_page_table on the decode
path, so the test raised AttributeError. Set it as __init__ does for
unified attention.
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Required checks failed on 93079c4; this PR cannot be merged until they pass.

PR title (run)

PR title must use "[Type] scope: title" or "[Type] [Hardware] scope: title". Type must be one of: Feat, Fix, Refactor, Perf, Doc, Test, CI, Chore, Misc. Scope is required and may be any module or model name, with unrestricted letter case (letters, numbers, dots, underscores, slashes, or hyphens). Hardware is optional; use a single tag without spaces. Use uppercase hardware tags (AMD, NVIDIA, NPU, MI300X), except for exactly these four spellings: Intel, Apple, Huawei, Ascend. Reverts must use GitHub's default format: Revert "original title". Use one space between fields and after the colon, with a non-empty title and no leading or trailing whitespace. Examples: "[Fix] attention: Fix KV cache indexing", "[Feat] qwen3: Add model support", "[Perf] [AMD] flash-attn: Optimize decode performance".
Edit the title; the check reruns on its own.

This branch has not been deployed

No deployments
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.

1 participant