Skip to content

[Triton/Gluon] batched_gemm_a16wfp4: ragged-K regression test and operand shape validation - #4685

Merged
azaidy merged 2 commits into
ROCm:mainfrom
lijinpei-amd:lijinpei/batched-gemm-a16wfp4-oob-fix
Oct 16, 2026
Merged

azaidy merged 2 commits into
ROCm:mainfrom
lijinpei-amd:lijinpei/batched-gemm-a16wfp4-oob-fix

Conversation

@lijinpei-amd

Copy link
Copy Markdown
Contributor

No description provided.

@lijinpei-amd
lijinpei-amd requested a review from a team August 11, 2026 15:42
@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 4685 --add-label <label>

vgokhale
vgokhale previously approved these changes Sep 3, 2026
Copilot AI lite review requested due to automatic review settings September 3, 2026 20:07

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.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@github-actions github-actions Bot changed the title [triton][gemm] batched_gemm_a16wfp4: fix two OOB reads when EVEN_K is false [Triton/Gluon] [gemm] batched_gemm_a16wfp4: fix two OOB reads when EVEN_K is false Sep 3, 2026
Copilot AI review requested due to automatic review settings September 9, 2026 02:36
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/batched-gemm-a16wfp4-oob-fix branch from b496a0a to 15d7ce8 Compare September 9, 2026 02:36
@lijinpei-amd

Copy link
Copy Markdown
Contributor Author

fix merged in #4181, rebase to only contain test and host side assert.

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 wrapper’s new K alignment assert is implemented on an implicitly overwritten K value without enforcing x.K == 2*w.K, and the new test imports internal _triton_kernels config helpers instead of using the public config loader.

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

Review details

Suppressed comments (1)

op_tests/triton_tests/gemm/batched/test_batched_gemm_a16wfp4.py:214

  • After switching to get_gemm_config, update the config fetch here to avoid calling the internal _get_config. The wrapper ultimately resolves configs by name with the unpacked K (2*packed K), so pass K directly (this test's K is already unpacked).
    config, _ = _get_config(M, N, K // 2)
  • 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 02:51
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/batched-gemm-a16wfp4-oob-fix branch from 15d7ce8 to 117df53 Compare September 9, 2026 02:51

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

Input validation is still incomplete for w_scales shape (remaining OOB risk), and the new regression test is brittle against future tuning changes without pinning/sanitizing split-K behavior.

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

Review details
  • 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:14
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/batched-gemm-a16wfp4-oob-fix branch from 117df53 to 60614a7 Compare September 9, 2026 03:14

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 new regression test currently relies on overriding tuning parameters via config=, which is brittle and should be adjusted to exercise the desired path without hardcoding tuning behavior.

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

Review details
  • 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:39
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/batched-gemm-a16wfp4-oob-fix branch from 60614a7 to c8f6fec Compare September 9, 2026 03:39
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/batched-gemm-a16wfp4-oob-fix branch from c8f6fec to 6bad281 Compare September 9, 2026 03:41
@Boss2002n
Boss2002n requested a balanced review from Copilot and removed request for Copilot September 9, 2026 03:52

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

Safety-critical validations use assertions that disappear under optimized Python, allowing out-of-bounds accesses.

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

Review details

Suppressed comments (1)

aiter/ops/triton/gemm/batched/batched_gemm_a16wfp4.py:120

  • This is the safety check intended to prevent the scale-buffer OOB read, but optimized Python removes it. An undersized w_scales tensor would then still be launched. Make this an unconditional runtime check rather than an assertion.
    assert w_scales.shape == (
        Bw,
        N,
        K_unpacked // 32,
    ), f"w_scales must have shape {(Bw, N, K_unpacked // 32)}, got {tuple(w_scales.shape)}"
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

nsusanto
nsusanto previously approved these changes Sep 29, 2026
Copilot AI balanced review requested due to automatic review settings September 30, 2026 16:08
@nsusanto
nsusanto force-pushed the lijinpei/batched-gemm-a16wfp4-oob-fix branch from 612aa8a to 0850418 Compare September 30, 2026 16:08

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.

Copilot review overview

🟡 Changes recommended

The new validation branches lack negative tests for malformed operand shapes.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Copilot AI balanced review requested due to automatic review settings October 1, 2026 04:11

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.

Copilot review overview

🔵 Needs a closer look

The newly added validation branches need negative test coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Copilot AI balanced review requested due to automatic review settings October 1, 2026 15:27
@nsusanto
nsusanto force-pushed the lijinpei/batched-gemm-a16wfp4-oob-fix branch from c3e584c to 4006823 Compare October 1, 2026 15: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.

Copilot review overview

🟡 Changes recommended

The new validation remains untested for malformed batch, K, alignment, and scale shapes.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@nsusanto

nsusanto commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

@lijinpei-amd do we need the additional test cases? can't we merge it into existing unit tests?

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

Please address comment from @nsusanto

azaidy
azaidy previously requested changes Oct 13, 2026
The kernel-side fixes for the EVEN_K == False path landed separately in
ROCm#4181, so only the guards and the regression coverage remain here. The
coverage goes into the existing test rather than a test of its own.

ROCm#4181 fixed two bugs, which were not the same kind. A's mask compared
unpacked offsets against the packed K, so it was too tight and silently
dropped valid activations. The w_scales load was unmasked and genuinely
read off the end of the scale tensor. The existing K=192 shape only
caught the second one by luck, whenever the bytes past the allocation
happened to be 0xFF. generate_batched_gemm_a16wfp4_inputs now places
w_scales at the head of a 0xFF-filled buffer, which is NaN in e8m0 and
which dot_scaled propagates even where the masked-off data is zero, so
every shape in the file fails loudly on an out-of-bounds scale read.

K=192 also hits the tail in the first and only K iteration. Add two
K=1120 shapes, which tuned configs run as four full iterations and a
ragged fifth. 1120 is 35 * 32, so it leaves a tail under any
BLOCK_SIZE_K >= 64, and no config override is needed to keep a re-tune
from moving these shapes onto EVEN_K == True. Re-injecting either ROCm#4181
bug fails all 24 ragged-K cases.

In the wrapper, x's K was read and then immediately shadowed by w's, so
nothing checked that the two operands agreed on K. Name them apart and
assert x.K == 2 * w.K explicitly. Hang the mxfp4 multiple-of-32 check
off the unpacked K rather than off an implicit contract, and check the
w_scales shape too: the kernel bounds those loads from K rather than
from the tensor, so an undersized scale tensor reads out of bounds
instead of failing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 15:17
@lijinpei-amd
lijinpei-amd force-pushed the lijinpei/batched-gemm-a16wfp4-oob-fix branch from 4006823 to e421f4c Compare October 14, 2026 15:17
@lijinpei-amd

Copy link
Copy Markdown
Contributor Author

@lijinpei-amd do we need the additional test cases? can't we merge it into existing unit tests?

Merged into test_batched_gemm_a16wfp4

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 focused changes match the operand contract, with no blocking issues identified in static review.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 17:15

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.

🔵 Needs a closer look

GPU regression results remain unverified and need human confirmation.

0 open findings

🧠 Review effort: Balanced

@nsusanto nsusanto 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 2cc8c75 into ROCm:main Oct 16, 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.

6 participants