Skip to content

[Triton/Gluon] [gfx1250] fp8_mqa_logits: fix epilogue store masks for cu_start != 0 - #4687

Merged
azaidy merged 2 commits into
ROCm:mainfrom
lijinpei-amd:lijinpei/fp8-mqa-logits-cu-start-fix
Oct 20, 2026
Merged

azaidy merged 2 commits into
ROCm:mainfrom
lijinpei-amd:lijinpei/fp8-mqa-logits-cu-start-fix

Conversation

@lijinpei-amd

Copy link
Copy Markdown
Contributor

No description provided.

@lijinpei-amd
lijinpei-amd requested review from a team and cagrikymk August 11, 2026 17:19
@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:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 4687 --add-label <label>

@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/fp8-mqa-logits-cu-start-fix branch from 99c2e68 to f8a88f6 Compare August 12, 2026 06:08
cagrikymk
cagrikymk previously approved these changes Aug 13, 2026

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

LGTM!

@zufayu
zufayu requested a review from Dewei-Wang-sh August 14, 2026 01:32
Copilot AI lite review requested due to automatic review settings September 9, 2026 02:43
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/fp8-mqa-logits-cu-start-fix branch from f8a88f6 to 26a34e7 Compare September 9, 2026 02:43
@github-actions github-actions Bot changed the title [triton][gfx1250] fp8_mqa_logits: fix epilogue store masks for cu_start != 0 [Triton/Gluon] [gfx1250] fp8_mqa_logits: fix epilogue store masks for cu_start != 0 Sep 9, 2026

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.

🟡 Changes recommended

The updated/new tests re-quantize kv after dequantization, overwriting kv_fp8/scales and making the kernel inputs inconsistent with the KV used by the reference computation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes a gfx1250 Gluon fp8_mqa_logits masking bug when the per-row KV window starts at a non-zero column (cu_start != 0), and extends the test suite to cover this regression scenario.

Changes:

  • Correct epilogue mask KV-position computation in the gfx1250 Gluon kernel so start_ind is not incorrectly scaled by BLOCK_KV.
  • Tighten the main fp8_mqa_logits correctness threshold and align the reference q with the fp8-quantized input.
  • Add a regression test covering non-zero cu_start windows (vLLM-style packed prefill).
File summaries
File Description
op_tests/triton_tests/attention/test_fp8_mqa_logits.py Adds non-zero cu_start regression coverage and ref/input alignment for tighter correctness checks.
aiter/ops/triton/_gluon_kernels/gfx1250/attention/fp8_mqa_logits.py Fixes epilogue store mask KV index computation for non-zero start offsets.
Review details

Suppressed comments (1)

op_tests/triton_tests/attention/test_fp8_mqa_logits.py:248

  • This re-quantizes kv after it was already quantized/dequantized above, overwriting kv_fp8/scales and making the kernel inputs inconsistent with the kv used in ref_fp8_mqa_logits. The regression test should use the same kv_fp8/scales pair that kv was derived from to avoid comparing against a different effective KV.
    kv_fp8, scales = per_custom_dims_cast_to_fp8(kv, (0,), False)
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/fp8-mqa-logits-cu-start-fix branch from 26a34e7 to f7f8f87 Compare September 9, 2026 03:09
Copilot AI review requested due to automatic review settings September 9, 2026 03:09

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.

🟢 Approval recommended

The kernel fix is straightforward and the added/updated tests cover the reported regression, with only minor test-reference precision/doc nits noted.

Review details

Suppressed comments (2)

op_tests/triton_tests/attention/test_fp8_mqa_logits.py:250

  • This comment says kv is an "exact dequantization" of (kv_fp8, scales), but the code currently casts kv to bfloat16, which is not exact. Please update the comment to match the intended dtype/behavior (or keep kv in fp32 as above).
    # kv_fp8/scales above are the kernel inputs and kv is their exact
    # dequantization; re-quantizing kv here would hand the kernel a slightly
    # different KV than the reference sees.

op_tests/triton_tests/attention/test_fp8_mqa_logits.py:246

  • Same as kv: converting Q from fp8 -> fp32 -> bf16 adds an avoidable rounding step before the reference. Keeping q in fp32 makes the reference use the exact dequantized fp8 values.
    q = q_fp8.to(torch.float32).to(torch.bfloat16)
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 9, 2026 03:26
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/fp8-mqa-logits-cu-start-fix branch from f7f8f87 to b050c38 Compare September 9, 2026 03:26
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/fp8-mqa-logits-cu-start-fix branch from b050c38 to 1bdaa25 Compare September 9, 2026 03:27

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.

🟢 Approval recommended

The kernel fix is narrowly scoped, logically consistent with surrounding indexing, and is backed by a targeted regression test that exercises the previously failing non-zero cu_start cases.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 9, 2026 03:28

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.

🟢 Approval recommended

The kernel fix is a targeted correctness change and is backed by a new regression test that exercises the previously failing nonzero-cu_start scenario.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 9, 2026 03:58
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/fp8-mqa-logits-cu-start-fix branch from 1bdaa25 to 7662453 Compare September 9, 2026 03:58

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.

🟢 Approval recommended

The kernel fix is localized and consistent with how start_ind/end_ind are used elsewhere, and the added regression test directly covers the reported nonzero-cu_start failure mode.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@cagrikymk

Copy link
Copy Markdown
Contributor

@lijinpei-amd Could you resolve conflicts?

@cagrikymk

Copy link
Copy Markdown
Contributor

@lijinpei-amd pinging again so we can get this merged.

@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Oct 17, 2026
lijinpei-amd and others added 2 commits October 19, 2026 09:38
… tolerance

The reference was fed the pre-quantization q while the kernel got q_fp8, so
the comparison carried an e4m3 rounding error that the tolerance had to
absorb. Round-trip q through e4m3 for the reference instead.

kv had the mirror problem from the other side: it was quantized, dequantized
into the reference input, then quantized a second time into the kernel input.
That second cast is not exactly idempotent -- the reciprocal scale and the
bf16 dequant move elements sitting near an e4m3 rounding boundary -- so the
kernel saw a slightly different KV than the reference. Drop it and reuse the
pair kv was dequantized from.

Dequantize both to fp32 rather than back to bf16 as well. bf16 holds every
e4m3 value exactly, so it costs q nothing, but kv is a product of an e4m3
value and an fp32 scale and bf16 rounds it away from what the kernel sees.

With both inputs matched, tighten the tolerance to 1e-4.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings October 19, 2026 01:46
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/fp8-mqa-logits-cu-start-fix branch from 7662453 to 8e61164 Compare October 19, 2026 01:46
@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Oct 19, 2026

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.

🟢 Approval recommended

No blocking issues were identified; remaining feedback is a minor consistency nit.

No open issues 🎉

Review effort: Lite

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

LGTM!

@azaidy
azaidy merged commit bf4c3b6 into ROCm:main Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants