Skip to content

attention: unified_attention and paged_attention_decode contracts - #79

Closed
fanxingran wants to merge 1 commit into
mainfrom
fanxingran/muse-spark-attention-contracts
Closed

fanxingran wants to merge 1 commit into
mainfrom
fanxingran/muse-spark-attention-contracts

Conversation

@fanxingran

Copy link
Copy Markdown
Collaborator

Why

Muse Spark's decode attention on vLLM's ROCM_AITER_FA backend runs aiter's Triton unified_attention
for multi-token decode (DSpark verify, q=8; drafter, q=7) and aiter's paged_attention_v1 for
one-token decode, and AKLR has a contract for neither. This adds both contracts and their baselines,
which call aiter as that backend does. Kernels follow in their own PRs.

Scope

  • [email protected] and [email protected]: contract, baseline, reference, and Muse
    (16 heads, 2 KV heads, head_dim 64, block 16) definition schemas: unified_attention q=8 global,
    q=8 window (2047, 0), and paged_attention_decode, batch 1..64 each.
  • aklr/core: an attr value may be a tuple of ints (window_size is the attr (-1, -1) or
    (2047, 0), as vLLM passes it); new layouts KvSplitPages (vLLM's kv_cache.transpose(1, 2) .split(head_dim) views) and StridedRows (the query sliced from the fused qkv buffer).

Tradeoffs

  • window_size as one tuple attr rather than an attr per element: vLLM passes the tuple, and only
    the two tuples it passes are in the contract.
  • softcap and q/k/v_descale have no default in aiter, so they are a scalar (values=(0.0,)) and
    optional inputs that must be absent: vLLM main passes None descales for an unquantized cache
    (rocm_aiter_fa.py _get_kv_cache_descales).

Verification

Environment: head 5b278d4 (main 3db8ca2), MI355X (pit2-p03-g29),
lmsysorg/sglang:v0.5.22-rocm10-mi35x (sha256:1438dd8b), torch 2.11.0+rocm10.0.0, FlyDSL 0.3.2,
Triton 3.8.0, AITER dbd8bf5bd (AKLR_BASELINE_AITER)
Gate overrides: none

Contracts

Workloads from Muse Spark's decode on vLLM (16/2/64/16, block tables up to 2048 blocks, DSpark
verify q=8 and one-token decode at batch 1..64).

$ python -m aklr export check; echo rc=$?
rc=0

Code

python -m pytest tests: 701 passed, 113 skipped. New: the two contracts' cases and schema names in
tests/ops (cases.py, names.txt; these exercise the tuple attr), and kv_split_pages pages in
tests/core/contract/test_fastkey.py. No schema or measurement version changes; no existing kernel
changes result (an attr that is not a tuple takes the old path).

Not run

  • CI validation of every schema (the aklr/core change): left to this PR's CI run.
  • Muse Spark end-to-end: Muse is not among the e2e scenarios and its vLLM model is not on vLLM main yet.

Risk

Affects: the aklr/core attr change touches every contract's attr parsing; the new ops have no
kernel, so aklr.ops.unified_attention / aklr.ops.paged_attention_decode run AITER.
If wrong: a contract whose attrs no longer parse, or a CI failure.
Undo: git revert.

…contracts

[email protected] is one-token paged decode on vLLM's kv_split_pages
cache, timed against aiter's paged_attention_v1; [email protected] is the
multi-token decode vLLM's ROCM_AITER_FA backend runs, timed against aiter's
Triton unified_attention. Both baselines call aiter as that backend does. An
attr value may now be a tuple of ints, so window_size is the attr (-1, -1) or
(2047, 0) as vLLM passes it; softcap is a scalar and the descales optional
inputs that must be absent. Adds the KvSplitPages and StridedRows layouts and
Muse (16/2/64/16) definition schemas for both.
@fanxingran fanxingran added ci:gpu and removed ci:gpu labels Nov 9, 2026
@fanxingran fanxingran added ci:gpu and removed ci:gpu labels Nov 9, 2026
@fanxingran

Copy link
Copy Markdown
Collaborator Author

CI run 42678258130: code-lint, unittest and the audit passed; validation's bench failed on one finding only, a schema of main this PR does not touch: aklr/plugins/sglang/models/deepseek_v2/impls/triton/deepseek_v2_mxfp4_moe_shuffled_16x16_model_dim6144_n_routed256_inter_dim512/2422a87b3b814299.json (one workload, no graph/baseline lower bound above 1.02). It sits at the threshold: 1.01x in #114's first run, 1.05x in #112's (passed). The previous attempt failed on another schema of main (qwen2_moe_fp8_router_experts_..._inter_dim128/2b97bf9b, "Incomplete Kineto trace", 2.76x – 2.92x in #112 and #114). #114 carries this PR's code and passed validation on every schema (run 42598331209).

zhenhuang12 pushed a commit that referenced this pull request Nov 11, 2026
…ion (#114)

* feat(attention): paged_attention_decode and unified_attention decode contracts

[email protected] is one-token paged decode on vLLM's kv_split_pages
cache, timed against aiter's paged_attention_v1; [email protected] is the
multi-token decode vLLM's ROCM_AITER_FA backend runs, timed against aiter's
Triton unified_attention. Both baselines call aiter as that backend does. An
attr value may now be a tuple of ints, so window_size is the attr (-1, -1) or
(2047, 0) as vLLM passes it; softcap is a scalar and the descales optional
inputs that must be absent. Adds the KvSplitPages and StridedRows layouts and
Muse (16/2/64/16) definition schemas for both.

* feat(plugins): vLLM plugin with GEMM and MoE routes

AKLR_VLLM_PLUGIN=1 hooks, in each vLLM worker once its device is bound, the
aiter functions vLLM's opaque custom ops look up at run time: tgemm.mm
(rocm_unquantized_gemm) and fused_moe (rocm_aiter_fused_moe). Each wrapper
asks the AKLR op and falls back to aiter on a FallbackReason, and always
inside a compiled region. Tested on vLLM 0.33.0rc1.dev910.

* feat(plugins): warm the AKLR kernels vLLM's warmup does not reach

An AKLR kernel compiles at its first eager call. vLLM runs each CUDA graph
size eagerly once, so steps past the graph sizes and the LM head (outside
the graphs) first reached their kernels while serving: c64 ITL p99 went
157 ms on a fresh server vs 122 ms once warm. After vLLM's warmup, run one
eager dummy step per served GEMM token count past the graph sizes and the
LM head at each served size (about 8 s per rank for Muse).

* fix(plugins): run each vLLM step from a frame chunk of its own

The routes' frames move CPython's frame-chunk boundary onto aiter's MoE
launch calls: each then maps and unmaps a chunk, 7% of a c128 step's host
time. Each step now runs from a 64 KiB chunk with room for the whole step.

* feat(plugins): routes from the model files vLLM runs uncompiled

A model vLLM runs without torch.compile (@ignore_torch_compile, as Muse
Spark) runs its Python at every eager call and CUDA graph capture, so a
route can replace any function it looks up, not only aiter's inside an
opaque custom op. The plugin now imports plugins.vllm.models, which mirrors
vLLM's models package; models/muse_spark holds no route yet.

* feat(plugins): route vLLM's skinny GEMM to gemm

vLLM on gfx950 sends 10 to 128 token unquantized GEMMs to its own
wvSplitKrc ahead of aiter's tgemm.mm, so the gemm route missed them there
(qkv and o_proj at most decode steps); route wvSplitKrc too.

* fix(plugins): the vLLM entry point is the plugin's; warm up only where routes installed

pyproject's vllm.general_plugins entry point still named dispatch's
register_vllm_plugin, so an installed AKLR started without the routes;
it now names aklr.plugins.vllm:register, which starts AKLR the same way
first, and installs nothing more without AKLR_VLLM_PLUGIN=1.

AKLR's warmup drives vLLM's model runner through its private API
(_dummy_run), as of the vLLM releases the routes were tested on; on any
other release no route installs, and the warmup now leaves vLLM alone too.
A pipeline stage without the LM head (a placeholder without weight) warms
no LM head. The plugins README lists the plugin's modules.

* feat(plugins): route vLLM's ROCM_AITER_FA attention to unified_attention

AiterFlashAttentionImpl.forward reaches aiter's triton unified_attention;
the route serves it with AKLR's unified_attention (#79's contract) and falls
back to aiter on a FallbackReason. Tested on vLLM 0.33.0rc1.dev910.

---------

Co-authored-by: Cursor <[email protected]>
@fanxingran

Copy link
Copy Markdown
Collaborator Author

Closing: the [email protected] and [email protected] contracts and their definition schemas reached main in #114. The two kernel PRs stacked on this one, #80 (unified_attention) and #81 (paged_attention_decode), now target main directly.

@fanxingran fanxingran closed this Nov 16, 2026

This branch was previously deployed

1 inactive deployment
gpu-trusted — 5b278d4f Deployed Nov 9, 2026 by fanxingran via prepare-gpu / prepare #481
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.

1 participant