Skip to content

[Triton] fp8_mqa_logits: add a deterministic option - #7471

Draft
aarnetalman wants to merge 2 commits into
ROCm:mainfrom
aarnetalman:fp8-mqa-logits-deterministic
Draft

aarnetalman wants to merge 2 commits into
ROCm:mainfrom
aarnetalman:fp8-mqa-logits-deterministic

Conversation

@aarnetalman

@aarnetalman aarnetalman commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

fp8_mqa_logits(..., deterministic=True) keeps one kernel configuration for every number of query rows, so a row's logits are bitwise the same whichever rows share the call. The default is unchanged.

Motivation

fp8_mqa_logits computes the indexer logits of DeepSeek-style sparse attention (DeepSeek-V3.2, GLM-5). It picks its configuration from seq_len, the number of query rows in the call: on gfx950 the row tile (block_m 1 or 2) and a single-warp variant above 4,096 rows, on the non-Gluon path the MFMA shape (16 up to 1,024 rows, otherwise 32). These change the order of the reduction over heads, so the same row gets slightly different logits depending on how many rows share the call. On MI350X at GLM-5.3's indexer shape (32 heads x 128, fp8), a row's logits from calls of up to about 1,500 rows differ from the same row in a 4,096-row call (largest difference 1.5e-5); calls of 2,048 rows and more agree.

The differences are small, but the logits feed a top-k, and near-tied keys can be picked differently. Inference engines call this kernel per chunk of rows, and the chunking follows the batch (and, in SGLang, free device memory), so in deterministic inference the same prompt can attend to different keys depending on its batchmates or from run to run. We saw GLM-5.3 give different tokens from run to run this way under memory pressure.

Changes

  • aiter/ops/triton/attention/fp8_mqa_logits.py: new deterministic=False argument. When True: on gfx950 always block_m 1 with two warps (no 2-row tile, no single-warp variant above 4,096 rows); on the non-Gluon path always the 32-wide MFMA shape. The KV split still follows the shape (it only divides the keys among workgroups and does not change a logit's arithmetic). Other architectures' Gluon path already walks one row per program with a fixed configuration and is unchanged.
  • op_tests/triton_tests/attention/test_fp8_mqa_logits.py: test_fp8_mqa_logits_deterministic_rows.
  • Default (deterministic=False): unchanged.

Performance (if applicable)

MI350X, GLM-5.3's indexer shape (32 heads x 128, fp8), median of 20 calls (ms):

Hardware Workload/configuration Before (default) After (deterministic=True) Change
MI350X 1 row x 8k / 32k / 64k keys 0.063 / 0.091 / 0.090 0.062 / 0.090 / 0.091 -2% / -1% / 0%
MI350X 64 rows x 8k / 32k / 64k keys 0.066 / 0.110 / 0.112 0.063 / 0.108 / 0.110 -4% / -2% / -1%
MI350X 1,024 rows x 8k / 32k / 64k keys 0.091 / 0.259 / 0.422 0.088 / 0.248 / 0.493 -3% / -4% / +17%
MI350X 4,096 rows x 8k / 32k / 64k keys 0.230 / 0.714 / 1.473 0.232 / 0.900 / 1.814 +1% / +26% / +23%
MI350X 8,192 rows x 8k / 32k keys 0.378 / 1.507 0.430 / 1.823 +14% / +21%
MI350X 16,384 rows x 8k keys 0.744 0.893 +20%

The extra time is on large prefill calls, where the default uses the 2-row tile. Only callers that pass deterministic=True are affected.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. The new argument defaults to the current behaviour.

PR Self-Review

Reviewed revision

660a4d0

Behavior and intent

With deterministic=True, a query row's logits no longer depend on the number of rows in the call, so callers that chunk the rows (by batch or by memory) get reproducible logits and top-k picks. Without it, nothing changes.

Validation and unverified scope

MI350X (gfx950), ROCm 7.2.4, rocm/sgl-dev:v0.5.23-rocm724-mi35x-20261030 with this file:

python3 -m pytest -q op_tests/triton_tests/attention/test_fp8_mqa_logits.py

166 passed (all existing tests, and the 8 cases of test_fp8_mqa_logits_deterministic_rows on the Gluon and non-Gluon paths). On main the new test fails (no deterministic argument). With the default configuration, sub-calls of up to about 1,500 rows differ bitwise from a 4,096-row call (6-9 of 14 row ranges at 8k / 32k / 64k keys); with deterministic=True none differ, also against calls of 16,384 (8k keys), 16,383 (32k) and 8,191 rows (64k).

End to end (SGLang, GLM-5.3-Flash TP2, deterministic inference, --mem-fraction-static 0.9, 32,768- / 60,000-token prompts alone twice and among batchmates): with the free-memory chunking left as is, 0 / 6 identical; with fixed chunking plus this configuration, 6 / 6.

Unverified: gfx942 and gfx1250 (their Gluon path has no seq_len-dependent choice; the non-Gluon change is tested on gfx950 by disabling the Gluon kernel), and accuracy beyond the comparison with the default (the test requires a cosine-style difference below 1e-6 against the default; the deterministic configuration is one the default already uses for smaller inputs).

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

test_fp8_mqa_logits_deterministic_rows fails before this PR in two ways. On main all 8 cases raise TypeError, because fp8_mqa_logits has no deterministic argument. Run against the default configuration, the same check fails because calls of up to about 1,500 rows use a different tile and warp count: it recomputes row ranges of an 8,192-row call as separate calls and compares them bitwise, and on MI350X 6-9 of 14 row ranges differ at 8k-64k keys. No existing test covers this. The canonical tests compare each call against a reference with a tolerance, and never compare the same rows across calls with different row counts.

Changed op tests

op_tests/triton_tests/attention/test_fp8_mqa_logits.py: adds test_fp8_mqa_logits_deterministic_rows (8k / 32k keys, 32 / 64 heads, Gluon and non-Gluon): with deterministic=True, 12 row ranges of an 8,192-row call (1 row to 8,185 rows, crossing every seq_len threshold the default uses) are bitwise equal to the same rows of the full call, run to run equal, and as accurate as the default. Not redundant: the existing tests compare against a reference with a tolerance and never compare calls with different row counts.

fp8_mqa_logits picks its kernel configuration from seq_len: on gfx950 the
row tile (block_m 1 or 2) and a single-warp variant above 4,096 rows, on
the non-Gluon path the MFMA shape (16 up to 1,024 rows, else 32). These
change the order of the head reduction, so a query row's logits depend on
how many rows share the call. Callers that split the rows into chunks (the
DSA k-pool indexer sizes its chunks from free device memory) then get
logits that change with the chunking, and a top-k over near-tied logits can
pick different keys.

deterministic=True keeps one configuration for every seq_len: block_m 1
with two warps on gfx950, the 32-wide MFMA shape on the non-Gluon path.
The default is unchanged.

The op test checks that rows are bitwise equal across 12 sub-calls of an
8,192-row call on both paths, and that the result matches the default's
accuracy.
@github-actions

github-actions Bot commented Nov 4, 2026

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 7471 --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.

@aiter-bot

aiter-bot commented Nov 4, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 660a4d01fe5d · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

With `deterministic=True`, a query row's logits no longer depend on the number of rows in the call, so callers that chunk the rows (by batch or by memory) get reproducible logits and top-k picks. Without it, nothing changes.

Validation and unverified scope

MI350X (gfx950), ROCm 7.2.4, `rocm/sgl-dev:v0.5.23-rocm724-mi35x-20261030` with this file:

```bash
python3 -m pytest -q op_tests/triton_tests/attention/test_fp8_mqa_logits.py
```

166 passed (all existing tests, and the 8 cases of `test_fp8_mqa_logits_deterministic_rows` on the Gluon and non-Gluon paths). On main the new test fails (no `deterministic` argument). With the default configuration, sub-calls of up to about 1,500 rows differ bitwise from a 4,096-row call (6-9 of 14 row ranges at 8k / 32k / 64k keys); with `deterministic=True` none differ, also against calls of 16,384 (8k keys), 16,383 (32k) and 8,191 rows (64k).

End to end (SGLang, GLM-5.3-Flash TP2, deterministic inference, `--mem-fraction-static 0.9`, 32,768- / 60,000-token prompts alone twice and among batchmates): with the free-memory chunking left as is, 0 / 6 identical; with fixed chunking plus this configuration, 6 / 6.

Unverified: gfx942 and gfx1250 (their Gluon path has no `seq_len`-dependent choice; the non-Gluon change is tested on gfx950 by disabling the Gluon kernel), and accuracy beyond the comparison with the default (the test requires a cosine-style difference below 1e-6 against the default; the deterministic configuration is one the default already uses for smaller inputs).

PR-specific question

*What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?*

`test_fp8_mqa_logits_deterministic_rows` fails before this PR in two ways. On main all 8 cases raise `TypeError`, because `fp8_mqa_logits` has no `deterministic` argument. Run against the default configuration, the same check fails because calls of up to about 1,500 rows use a different tile and warp count: it recomputes row ranges of an 8,192-row call as separate calls and compares them bitwise, and on MI350X 6-9 of 14 row ranges differ at 8k-64k keys. No existing test covers this. The canonical tests compare each call against a reference with a tolerance, and never compare the same rows across calls with different row counts.

Changed op tests

`op_tests/triton_tests/attention/test_fp8_mqa_logits.py`: adds `test_fp8_mqa_logits_deterministic_rows` (8k / 32k keys, 32 / 64 heads, Gluon and non-Gluon): with `deterministic=True`, 12 row ranges of an 8,192-row call (1 row to 8,185 rows, crossing every `seq_len` threshold the default uses) are bitwise equal to the same rows of the full call, run to run equal, and as accurate as the default. Not redundant: the existing tests compare against a reference with a tolerance and never compare calls with different row counts.

PR state

  • WAIT — pull request is still a draft

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@vpietila-amd
vpietila-amd self-requested a review November 5, 2026 12:41
vpietila-amd
vpietila-amd previously approved these changes Nov 5, 2026

@vpietila-amd vpietila-amd 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.

Looks good to me. This is safe change as it is opt in. Consider extending the test cases and the possible performance improvement.

@@ -250,3 +251,58 @@ def test_fp8_mqa_logits_nonzero_cu_start(
logits = logits.masked_fill(neginf_mask, 0)
diff = calc_diff(logits, ref_logits)
assert diff < 1e-4, f"{diff=}"


@pytest.mark.parametrize("s_k", [8192, 32768])

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.

We probably should add the s_k=32768 case to cover also the KV-splitting path. There is MIN_SPLIT_KV = 16384 value used in method _gfx950_kv_splits.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it's already there: s_k is parametrized over 8,192 and 32,768. At 32,768 keys, calls of up to 4,096 rows get 2 KV splits from _gfx950_kv_splits, and the full 8,192-row call gets 1, so the row ranges in the test compare split and unsplit calls.

Looking at the split path more closely did turn up a problem at 16 heads, which the test doesn't cover yet (it runs 32 and 64). I'll push a fix with a 16-head case shortly.

@@ -243,7 +248,8 @@ def fp8_mqa_logits(
seq_len, seq_len_kv, 2, num_warps, waves_per_eu
)
if (
num_heads <= 32
not deterministic

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.

If performance is concern for the deterministic mode, you could remove here the condition not deterministic to allow block_m = 2 and set later num_chains = 1 for the deterministic case. I tested that this combination has better perf in the H <= 32 case and it passes the determinism test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I tried it: with one head-sum chain, BLOCK_M 1 and 2 give the same logits and every test passes (I applied it only above 16 heads, where the head sum is folded). At 32 heads on MI350X it is 4-18% faster at 8,192 rows with 32k-64k keys, but 12-14% slower at 512-2,048 rows with 8k or 64k keys, and the same elsewhere. Since it's mixed, I'd keep this PR as is and leave the BLOCK_M=2 choice for a follow-up with a better crossover. Happy to add it here if you prefer.

…e folded head reduction

On gfx950, a call split over KV is not repeatable at 16 heads or fewer (no
folded head reduction): the logits next to the split boundary change from run
to run (2,048 rows, 32k / 64k keys: 19 of 20 calls differ). Deterministic mode
now runs those calls unsplit; with the folded reduction (more than 16 heads)
the split is repeatable and stays. The row-invariance test also covers 16 heads.
@aarnetalman

Copy link
Copy Markdown
Member Author

@vpietila-amd Pushed a fix for the 16-head problem I mentioned: on gfx950, a call that is split over KV is not repeatable at 16 heads or fewer, where there is no folded head reduction. The logits next to the split boundary change from run to run (2,048 rows, 32k or 64k keys: 19 of 20 calls differ). The default configuration was repeatable in every case I ran. Deterministic mode now runs those calls without the split. With more than 16 heads the split is repeatable and stays. The row-invariance test now covers 16 heads as well, and all 170 tests in the file pass on MI350X.

The cost is only at 16 heads, with long KV and few rows: for example 1 row with 65,536 keys goes from 65 to 305 µs. 32 and 64 heads are unchanged.

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.

3 participants