Skip to content

[Triton/Gluon] fix(gluon): harden paged MQA logits prefetch masks (context_length + block-table capacity bounds) - #5600

Merged
k50112113 merged 2 commits into
ROCm:mainfrom
fallow5:fix/gluon-pa-mqa-two-step-addressing
Oct 5, 2026
Merged

k50112113 merged 2 commits into
ROCm:mainfrom
fallow5:fix/gluon-pa-mqa-two-step-addressing

Conversation

@fallow5

@fallow5 fallow5 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The two-step addressing (pool coord → block column + offset) this PR originally carried is already on main via #5749, together with 64-bit addressing, the negative-prologue clamp and the preshuffle tail store — so after rebasing onto main this PR keeps only the mask hardening that #5749 does not have:

  1. Prologue prefetch masks bound BOTH directions. [Triton/Gluon] [Bugfix] [Perf] Support page size 8 in paged MQA logits on both layouts, and fix large KV offsets #5749 only guards the lower bound (>= 0); a first split shorter than ChunkK can prefetch past the row's valid kv_indices columns. Added context_length and the block-table row capacity (max_block_len * KVBlockSize pools) as upper bounds.
  2. In-loop prefetch masks + out-of-window lanes forced to block 0. [Triton/Gluon] [Bugfix] [Perf] Support page size 8 in paged MQA logits on both layouts, and fix large KV offsets #5749's in-loop buffer_load is unmasked and relies solely on the loop bound; with the masks, an out-of-contract context_length (which the wrapper does not validate) can only ever read block 0 — never a garbage block id dereferenced into KV_buffer.

In-contract the window tops out at split_context_length, so the new bounds never mask a valid lane; they only fire for out-of-contract callers. The capacity bound (pool < max_block_len * KVBlockSize ⇒ block_col < max_block_len) also answers the Copilot review's block_col bound finding.

Why this is a follow-up, not a duplicate

this PR (rebased) #5749 (on main)
two-step addressing (3 load sites) — dropped, covered ✅
negative-prologue clamp — covered (gl.maximum(logical, 0)) ✅
64-bit addressing (> 2 GiB KV) — out of scope ✅
preshuffle tail store bound — out of scope ✅
page size 8 — out of scope ✅
prologue mask upper bounds ✅ ❌ lower bound only
in-loop prefetch masks + zeroing ✅ ❌ unmasked
block-table capacity bound ✅ ❌

Reproduction context (original bug, now fixed by #5749)

GLM-5.3-Flash, 8× MI308X (gfx942), TP4, fp8 e4m3 KV, page 64, index_kpool=4: any request with KV length > 16384 tokens faulted deterministically on the first decode step after prefill (4-rank Memory access fault), pinned to _gluon_deepgemm_fp8_paged_mqa_logits via AMD_LOG_LEVEL=3 + HIP_LAUNCH_BLOCKING=1. The addressing fix for that is #5749's; what this PR adds on top is defense-in-depth for the mask path.

Notes for reviewers

@fallow5
fallow5 requested a review from a team September 16, 2026 18:24
@github-actions github-actions Bot changed the title fix(gluon): two-step addressing in paged MQA logits kernel (pool coord -> block column + offset) [Triton/Gluon] fix(gluon): two-step addressing in paged MQA logits kernel (pool coord -> block column + offset) Sep 16, 2026
@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: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; main branch always runs both MI35X and MI300X
multigpu 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: 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 5600 --add-label <label>

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 opt this PR out.

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

Two critical safety findings and missing regression coverage remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes non-preshuffle Gluon paged MQA logits addressing for block-sized KV caches.

Changes:

  • Converts pool positions into block-table columns and offsets.
  • Adds bounds masking for KV and scale prefetches.
  • Updates KV and scale addressing logic.
File summaries
File Description Findings
aiter/ops/triton/gluon/pa_mqa_logits.py Updates Gluon paged-MQA addressing and prefetch masking. Critical (2 votes): Guard negative prologue offsets before dereferences. Critical (1 vote): Enforce block_col < max_block_len. Nit (3 votes): Add non-preshuffle regression coverage.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/ops/triton/gluon/pa_mqa_logits.py Resolved
Comment thread aiter/ops/triton/gluon/pa_mqa_logits.py Resolved
Comment thread aiter/ops/triton/gluon/pa_mqa_logits.py Resolved

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

Hi @fallow5
#5749
seems to be addressing this issue, can you resolve conflict and take a look if the solution is already in or you have more things to cover in this PR?

@fallow5
fallow5 force-pushed the fix/gluon-pa-mqa-two-step-addressing branch from d052db1 to 6afc358 Compare September 28, 2026 02:52
@fallow5 fallow5 changed the title [Triton/Gluon] fix(gluon): two-step addressing in paged MQA logits kernel (pool coord -> block column + offset) [Triton/Gluon] fix(gluon): harden paged MQA logits prefetch masks (context_length + block-table capacity bounds) Sep 28, 2026
@fallow5

fallow5 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for pointing me at #5749! Rebased onto main — the two-step addressing (pool coord → block column + offset) is indeed fully covered there, and more thoroughly (64-bit addressing, negative-prologue clamp, preshuffle tail store, page size 8), so I dropped my duplicate implementation of it.

What remains in this PR is the mask hardening that #5749 does not have:

  1. Prologue prefetch masks bound both directions (>= 0 && < context_length && < max_block_len * KVBlockSize) — [Triton/Gluon] [Bugfix] [Perf] Support page size 8 in paged MQA logits on both layouts, and fix large KV offsets #5749 only guards the lower bound, so a first split shorter than ChunkK can prefetch past the row's valid kv_indices columns.
  2. In-loop prefetch masks + out-of-window lanes forced to block 0 — [Triton/Gluon] [Bugfix] [Perf] Support page size 8 in paged MQA logits on both layouts, and fix large KV offsets #5749's in-loop buffer_load is unmasked and relies solely on the loop bound; with the masks, an out-of-contract context_length (which the wrapper does not validate) can only ever read block 0, never a garbage block id dereferenced into KV_buffer.
  3. The block-table capacity bound also answers the Copilot review's block_col < max_block_len finding — neither [Triton/Gluon] [Bugfix] [Perf] Support page size 8 in paged MQA logits on both layouts, and fix large KV offsets #5749 nor the wrapper validates the context_length vs block-table-capacity relationship.

In-contract the window tops out at split_context_length, so the new bounds never mask a valid lane. Also happy to extend op_tests/test_pa_mqa_logits_offset.py (the harness #5749 introduced) with an out-of-contract context_length case if you'd like regression coverage for the masks specifically — shout if you'd rather see any of this folded differently.

@k50112113

Copy link
Copy Markdown
Contributor

I think the formatting is off, can you fix?

…block-table capacity bounds)

The two-step addressing (pool coord -> block column + offset) that this
branch originally carried is already on main via ROCm#5749, together with
64-bit addressing, the negative-prologue clamp and the preshuffle tail
store -- so this commit drops the duplicate and keeps only the mask
hardening that ROCm#5749 does not have:

1. Prologue prefetch masks bound BOTH directions: the existing >= 0
   lower bound, plus context_length and the block-table row capacity
   (max_block_len * KVBlockSize pools) as upper bounds. ROCm#5749 only
   guards the lower bound, so a first split shorter than ChunkK can
   prefetch past the row's valid kv_indices columns.

2. In-loop prefetch masks + out-of-window lanes forced to block 0.
   ROCm#5749's in-loop buffer_load is unmasked and relies solely on the
   loop bound; with the masks, an out-of-contract context_length (which
   the wrapper does not validate) can only ever read block 0, never a
   garbage block id dereferenced into KV_buffer.

In-contract the window tops out at split_context_length, so the new
bounds never mask a valid lane; they only fire for out-of-contract
callers. This also answers the Copilot review's block_col bound finding.
@fallow5
fallow5 force-pushed the fix/gluon-pa-mqa-two-step-addressing branch from 6afc358 to 254aeb3 Compare September 29, 2026 08:27
@fallow5

fallow5 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Fixed — 254aeb3 reformats the prologue masks to Black's preferred parenthesized & chain (the rest of the file was already Black-clean; only the two new mask_kv_next / mask_kv_scale_next expressions were off). Local run with black==26.5.1 (same version as the psf/black@stable action pins) now passes, as does ruff check. Apologies for the churn — the loop-side masks were already Black-clean, so this is a formatting-only change with no semantic delta.

@k50112113
k50112113 self-requested a review October 5, 2026 13:57
@k50112113
k50112113 merged commit 474fc6b into ROCm:main Oct 5, 2026
68 of 70 checks passed
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