Repository navigation
[Triton/Gluon] [Feature] unified_attention: support causal=False for bidirectional draft verify - #7244
[Triton/Gluon] [Feature] unified_attention: support causal=False for bidirectional draft verify#7244yuychang wants to merge 1 commit into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
Non-causal decode can silently truncate attention to the last 256 keys, while non-positive sliding-window values cause the benchmark to pass arguments the wrapper rejects.
2 open issues
What changed in this PR
Adds non-causal attention to the Triton unified_attention path so draft-model verification can attend to the full block and cached prefix. This feature builds on the length-aware KV splitting in #7088.
Changes:
- Adds causal-mode controls to the Triton 2D and 3D kernels.
- Updates wrapper validation and dispatch while keeping Gluon paths causal-only.
- Adds non-causal tests and a benchmark flag with matching reference checks and work estimates.
| File | Description |
|---|---|
op_tests/triton_tests/attention/test_unified_attention.py |
Adds non-causal correctness and rejection tests; includes stacked split-KV coverage. |
op_tests/op_benchmarks/triton/bench_unified_attention.py |
Adds non-causal benchmarking and reference checks. |
aiter/ops/triton/utils/unified_attention_utils.py |
Derives length-aware segment limits for the stacked optimization. |
aiter/ops/triton/configs/gfx950/triton/attention/unified_attention/DEFAULT.json |
Adds gfx950 length-aware split settings from #7088. |
aiter/ops/triton/attention/unified_attention.py |
Validates and dispatches non-causal calls to Triton. |
aiter/ops/triton/_triton_kernels/attention/unified_attention.py |
Adds full-sequence key bounds and masks alongside stacked split-KV support. |
Review effort: Balanced
7d78cff to
29699c7
Compare
29699c7 to
4757462
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Reported GPU results cover only gfx950, leaving correctness, causal-regression, and performance validation for gfx942 and gfx1250 unresolved because this source-only review cannot run GPU checks.
1 open issue
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The non-causal GPU masks and backend routing lack head-matched runtime validation evidence, leaving correctness, performance, and unverified gfx1250 coverage for human review.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The new non-causal dispatch reaches unvalidated gfx1250/RDNA paths, including a gfx1250 Triton 3D path with a documented reference mismatch, without exact-head validation or the ability to rerun GPU correctness and performance checks.
No open issues 🎉
Review effort: Balanced
- Add a CAUSAL constexpr (default True) to the Triton 2D and 3D kernels using shared key_* helpers. - Route non-causal calls to Triton while keeping causal kernels (and Gluon when available) for decode. - Raise ValueError for non-causal sliding window (left >= 0 or right > 0), ALiBi, qq_bias, fp4 Q/K/V, or gfx1250. - Document unified_attention parameters and non-causal limits, and add -non_causal to bench_unified_attention.py. - Add non-causal verify, prefill, decode, feature, backend-fallback, and validation tests in test_unified_attention.py.



Summary
unified_attention(causal=False)runs on the Triton 2D and 3D kernelsgit merge-treeon main075695e89and [Triton/Gluon] [Perf] unified_attention: split KV by actual sequence lengths under CUDA graphs (gfx950, head 64, bf16 Q / fp8 KV) #7088d9661320c: both merge orders conflict-free, same treea0f1175f4, [Triton/Gluon] [Perf] unified_attention: split KV by actual sequence lengths under CUDA graphs (gfx950, head 64, bf16 Q / fp8 KV) #70884456f7450)020b6987f)Motivation
ENCODER_ONLYunified_attentionassertedcausal, so sglang's aiter backend could not run themextend_attention_fwd, has no split-KV for a non-causal blockChanges
CAUSALconstexpr in the Triton 2D and 3D kernels, defaultTrueCAUSAL=Falsethe key bound, key mask and 2D unmasked loop useseq_lenkey_prefix_len/key_unmasked_len/key_maskcausalto both kernelsmax_seqlen_q == 1) keeps the causal kernelsValueErrorfor:(-1, 0)and(-1, -1)are acceptedpython -Otl.static_assert(CAUSAL or SLIDING_WINDOW <= 0)backend="gluon", also on an arch without Gluon) run Tritonmax_seqlen_q > 1raisesValueErrorunified_attentiondocstring states these limitsbench_unified_attention.py-non_causalflag (rejects-testand-sliding_window)-sliding_window <= 0means no windowPerformance (if applicable)
bench_unified_attention.py -b <batch> -sk <keys> -hq 8 -hk 2 -sq 4 -d 64 -block_size 128 -fp8_kv -equal_seqlens [-non_causal] --metric time3c93fb773vs main075695e89e00afd224(the PR branch, not merged into main) vs main4ba20eba9be98131411vs main95c9ab3aa, median of 35c1489c24vs heade266d32bf, one MI355Xbench_unified_attention.py --backend triton --metric time -equal_seqlens, 3 roundse00afd224(main50bfa78d0for the causal baseline)bench_unified_attention.py -b 4 -hq 32 -hk 8 -sq 512 -sk 4096 -d 128 --backend triton --metric time -equal_seqlens [-non_causal]Testing
Unit tests added or updated
Performance benchmarks run
Tested on MI250X
Tested on MI300X
op_tests/triton_tests/attention/test_unified_attention.py(run by CI)e266d32bfvalidate-kernel-prPASS, repo tests 2958 run / 0 failed-k causal224 passed, 126 skipped3c93fb773-k non_causal224 passed / 126 skipped-k "not non_causal"2642 passed on both PR and main075695e89; 0 failedtest_triton_unified_attn_qq_bias_padded_query_rows[num_heads1-4-4096]e98131411-k non_causal206 passed;-k "not non_causal"1130 passed; 0 failedHistorical (before
dce729cf4, which made the benchmark reject-non_causal -test)bench_unified_attention.py -b 4 -hq 32 -hk 8 -sq 512 -sk 4096 -d 128 -test --backend triton-non_causal,-non_causal -fp8,-non_causal -decode 0.5and causal-non_causal -sliding_window 128raisesNot tested: MI250X, gfx1250, RDNA
Documentation
Docstrings updated
User guide updated
Performance guide updated
No documentation change is needed, with the reason stated below
The user and performance guides do not document
unified_attentionargumentsDependencies
Breaking Changes
causal=Falseused to raiseAssertionErrorPR Self-Review
Reviewed revision
a0f1175f4e18216b230a72b6ed1b774b6e294923e00afd224only shortens a test docstring; runs ate266d32bfand ate00afd224are labelled belowdce729cf4and the next commit:causalflag (non-causal decode no longer asserts without Gluon)-non_causal -testcausal=Falsec8d0b5b55:ValueErrorbuild_aiter_wheelson42fe8c82dfailed pulling the Docker image (infra), which failedAiter Test GateBehavior and intent
causal=Falseattends each query token to all keys of its sequence on the Triton 2D and 3D kernelscausal, so a bidirectional draft block could not use the split-KV kernelsCAUSALis a constexpr defaulting toTrueCAUSALbranch: it is not validatedseq_len < query_lenleaves 3D partials unwrittenValidation and unverified scope
validate-kernel-prPASSe266d32bfvs5c1489c24(MI355X, Triton 3.8.0; S1 grid 1118 run, 0 failed)3c93fb773vs075695e89(MI355X)e98131411vs95c9ab3aa(MI300X)a0f1175f4(MI355X gfx950, GPU 0, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, Triton 3.8.0)pytest -q op_tests/triton_tests/attention/test_unified_attention.py7244-r3.log)e00afd224, MI355X (gfx950), GPU 0, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, Triton 3.8.0pytest -k non_causal op_tests/triton_tests/attention/test_unified_attention.py: 224 passed, 126 skippedvalidate-kernel-prontest_unified_attn_non_causal(--no-perf) over main4ba20eba9b: INCONCLUSIVEq_block_local_idx * BLOCK_Q, 2 sites)c8d0b5b55(same host, GPU 0)pytest -q op_tests/triton_tests/attention/test_unified_attention.py -k non_causal7244-triage.log)git merge-treeof this head with main95f38f953is conflict-freePR-specific question
attn_3d D_LEQ_128.Q_GEQ_4([Triton/Gluon] [gfx950] unified_attention: split-KV 3D configs for head_size <= 128 keyed on max_seqlen_q #6983)CAUSAL=Falsekernel branch runs only forcausal=Falsewithmax_seqlen_q > 1Changed op tests
op_tests/triton_tests/attention/test_unified_attention.pytest_unified_attn_non_causalref_paged_attn(causal=0)with per-request rel L2 (0.02 bf16 Q, 0.05 fp8 Q)test_unified_attn_non_causal_features: sinks, softcap, shuffled KV; on gfx950 asserts 2D vs 3Dtest_unified_attn_non_causal_rejects_unsupportedtest_unified_attn_non_causal_ignores_gluon_requestbackend="gluon"withcausal=Falseruns Triton when Gluon is unavailablecausal=Truestill assertsoutputfirst, so an unwritten row cannot passtest_unified_attn_non_causal_no_window:(-1, -1)and(-1, 0)match the referencetest_unified_attn_non_causal_rejected_on_gfx1250query_len1) is also covereda0f1175f4the whole file gives 2965 passed, 3089 skipped, 0 failedcausal=Falseop_tests/op_benchmarks/triton/bench_unified_attention.py-non_causaltimescausal=False-test(accuracy lives in pytest)sq * skpairs in FLOPs🤖 Generated with Claude Code