Skip to content

[Triton/Gluon] add block_cat_fused fused op - #3269

Merged
azaidy merged 4 commits into
ROCm:mainfrom
reger-men:aiter-block-cat-split-pattern
Oct 28, 2026
Merged

azaidy merged 4 commits into
ROCm:mainfrom
reger-men:aiter-block-cat-split-pattern

Conversation

@reger-men

@reger-men reger-men commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds block_cat_fused(l12, l4, slope, l1_width), which computes

cat([leaky_relu(l12[..., :W1], slope), l12[..., W1:] * l4], dim=-1)

as one op with a fused backward. Its exported as aiter.ops.triton.fusions.block_cat_fused. The two custom ops underneath are torch.ops.aiter.block_cat_fused_fwd and torch.ops.aiter.block_cat_fused_bwd (registered through torch_compile_guard), and autograd goes through a torch.autograd.Function. Since AOTAutograd sees one node, the backward writes grad_l12 and grad_l4 in a single kernel instead of decomposing into per-half pointwise passes that each read the activation from HBM again.

Files follow the other fusion ops:

  • kernels: aiter/ops/triton/_triton_kernels/fusions/block_cat_fused.py
  • wrapper and custom ops: aiter/ops/triton/fusions/block_cat_fused.py
  • launch configs: aiter/ops/triton/configs/{gfx942,gfx950,gfx1250}/triton/fusions/block_cat_fused/DEFAULT.json, same values on all three for now
  • tests: op_tests/triton_tests/fusions/test_block_cat_fused.py
  • bench: op_tests/op_benchmarks/triton/bench_block_cat_fused.py

fp16/bf16 CUDA inputs run the Triton kernels (fp32 math, stored in the input dtype). fp32 and CPU inputs dont hit Triton, they take the eager torch path. l4 has to match l12 in device, dtype and leading shape. The fake impls return contiguous tensors, same as the real fwd and bwd.

Test plan: pytest op_tests/triton_tests/fusions/test_block_cat_fused.py, 28 tests. They cover fwd/bwd vs eager for fp16 and bf16 with a random upstream grad, non-contiguous inputs, fake vs real output layout, torch.compile fullgraph, 3-D input, empty input, the fp32 fallback on cpu and cuda, and the input asserts. All 28 pass on MI355X.

@reger-men
reger-men requested a review from a team May 19, 2026 14:12
@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 3269 --add-label <label>

@reger-men
reger-men force-pushed the aiter-block-cat-split-pattern branch 2 times, most recently from e41e246 to 09223e3 Compare May 21, 2026 09:22
@amd-zcai
amd-zcai requested a review from valarLip June 2, 2026 07:20
@valarLip

valarLip commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

i will reject this one as it is not pure kernel, and introduce torch inductor which is not our focus domain yet

@reger-men
reger-men force-pushed the aiter-block-cat-split-pattern branch from 09223e3 to c36e615 Compare June 11, 2026 20:03
@reger-men reger-men changed the title add block_cat_fused custom op + inductor pre-grad matcher add block_cat_fused fused op Jun 11, 2026
@reger-men

Copy link
Copy Markdown
Contributor Author

Split this down to the kernel only per your scope point: it now adds just thetorch.ops.aiter.block_cat_fusedop (fused forward + fused backward) plus its op tests, with the inductor matcher removed.

valarLip
valarLip previously approved these changes Jun 18, 2026
@zufayu
zufayu self-requested a review June 26, 2026 08:56
@zufayu

zufayu commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@reger-men The CI ran on June 11 and 12 out of 17 shards failed (both MI300X and MI35X), while the same shards all pass on main from the same period — so these are regressions introduced by this PR. The logs have expired so the exact error is unknown, but the breadth of failure across all shards suggests an import or registration issue with the new op. Please rebase onto main and re-run CI so we can see the current error.

@zufayu

zufayu commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Hi @reger-men — thanks for splitting this down to the pure kernel op earlier per @valarLip's scope point; the op itself is approved. There's one blocker left before it can merge.

CI regression is still open. As noted on 6/29: the 6/11 run had 12 of 17 Standard Tests shards failing on both MI300X and MI35X, while the same shards passed on main from the same period — so these look like regressions introduced by this PR, not flaky infra. The current head still shows the same broad failures.

Could you rebase onto the latest origin/main and re-trigger CI, then look at the failing shards? Since you're actively pushing other PRs, a quick pass here would likely get it over the line — it's already approved, this is the only thing holding it back.

One more thing worth double-checking while you're in there: the fp16 path. The dispatch gate accepts l12.dtype in (bf16, fp16), but please confirm the kernel stores in the input dtype rather than hardcoding tl.bfloat16 — if fp16 inputs get written as bf16, that's a silent precision drop, and the tests only seem to cover bf16. Adding an fp16 case (or narrowing the gate to bf16 only) would close that gap.

Once CI is green after rebase, I'm happy to merge.

@reger-men

Copy link
Copy Markdown
Contributor Author

@zufayu rebased onto current main and fixed the fp16 store you flagged: the kernel was hardcoding tl.bfloat16 on its stores while the op accepts fp16, so fp16 was silently downcast. It now stores in the output pointer's dtype, so fp16 is bitwise-correct (0.0 error vs 1.56e-2 before) and bf16 is unchanged, and I added fp16 fwd/bwd tests. The old red shards were a stale June artifact-download timeout rather than a code regression, so this fresh push should give a clean CI run. The force-push dismissed valarLip's approval as expected. Could you re-review once CI is green?

@reger-men

Copy link
Copy Markdown
Contributor Author

@zufayu the four red shards here (Standard Tests MI35X 3+4, MI300X 3+4) aren't from this PR. The failing tests are test_aiter_add.py and test_aiter_addInp.py, and they die in torch's kineto profiler (_parse_kineto_results hits a UnicodeDecodeError on a non-utf-8 event name out of prof.key_averages().table()), nothing to do with block_cat. This PR only adds two new files, import aiter doesn't load block_cat (its dormant until the op is called), and those two tests are byte-identical to main and only do import aiter. I ran both on an MI35X box with the exact CI image and torch build and they pass. So this looks like a flaky runner/profiler condition, not a regression from the change. Could you or CI/CD run a consistency check or re-run those shards so we can confirm it's the environment and not this PR?

@zufayu

zufayu commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

xnumel/xoffset/xindex/xmask/XBLOCK appear nowhere else in aiter (which uses BLOCK_M/BLOCK_SIZE_N throughout) — this is Inductor codegen. Removing the pattern matcher didn't remove the Inductor dependency. @valarLip's scope objection stands; the review carrying it was cleared by a force-push, not withdrawn.

@zufayu

zufayu commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Advisory review (static + hand-run; not a merge gate). Validation/Perf ran no GPU stage — reasons are on their lines below. Findings tagged [verified] are traced to code/repro.

Registers a new custom op torch.ops.aiter.block_cat_fused that fuses cat([leaky_relu(l12[..., :W1], slope), l12[..., W1:] * l4]) into one Triton forward kernel plus a single Triton backward kernel emitting grad_l12 and grad_l4 together, with an eager CPU/fp32 fallback and op_tests coverage.

Review (advisory): 🔴 HIGH RISK — elevated AI-code risk (two structural checks fired); recommend thorough manual verification of the dispatch logic and test coverage
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-run disabled; the target op_tests/test_block_cat_fused.py exists and pytest collects it). Hand-run on MI300X (gfx942, torch 2.9.1, triton 3.7.0): 6/6 tests pass, and the fused backward is confirmed to launch as a single kernel under torch.compile with bitwise fwd/bwd match vs compiled eager
Perf (advisory): MEASURED — stated workload shape M=960,000 x W12=576 bf16 on MI300X, 20 samples, medians, same box back to back; base = the eager cat/leaky_relu/mul chain the op replaces (new op, no base-branch counterpart): fwd+bwd 9.84 ms vs 3.57 ms (2.75x) at W1=128/W4=448, 8.63 ms vs 3.36 ms (2.57x) at W1=512/W4=64; forward-only 3.86 ms vs 1.33 ms (2.90x)

🔴 [verified] aiter/ops/block_cat_fused.py block_cat_fused_bw allocates the backward outputs from the original inputs — grad_l12 = torch.empty_like(l12), grad_l4 = torch.empty_like(l4) — and torch.empty_like preserves strides for dense-but-permuted tensors, while the Triton kernel writes both flat-contiguous (grad_l12_out_ptr + xindex). Repro on MI300X: l12 (64, 96) bf16 contiguous with l4 supplied as a transpose view (w.t()) gives a bitwise-correct forward but grad_l4 max diff 7.9 vs eager autograd; with both inputs transposed, 15930/16384 grad elements are wrong and the returned grad_l12 equals the correct gradient transposed. The failure is silent (no error, forward stays correct) and corrupts weight updates in training; the forward wrapper does this right (cat_out = empty_like(l12.contiguous())). Author must allocate the backward outputs contiguous (empty_like on the contiguous copies, or memory_format=torch.contiguous_format) and add a non-contiguous-input backward test.

⚠️ [verified] op_tests/test_block_cat_fused.py drives all three backward tests with out.sum().backward(), so the upstream gradient is all ones — a backward kernel that drops the grad_cat factor entirely passes the whole suite. Mutation-verified on MI300X: replacing gc * l4 with l4, gc * l12 with l12 and where(x > 0, gc, gc * slope) with where(x > 0, 1, slope) in _block_cat_fused_bw still passes 6/6 tests. The kernel itself is correct under random upstream gradients (bitwise match vs eager on 6 shapes including W1=1, W4=1 and odd widths), so this is a test-coverage gap, not a kernel bug. Author must add a backward case with a random upstream gradient (out.backward(torch.randn_like(out))).

⚠️ [verified] aiter/ops/block_cat_fused.py _launch_fw/_launch_bw do flat int32 index arithmetic (xoffset = pid * XBLOCK, l4_idx = row * W4 + col_l4) with no guard on xnumel, and it overflows at M * W12 >= 2^31. Repro on MI300X: M=3,728,272 x W12=576 (2,147,484,672 elements) aborts the process with a GPU memory access fault, while M=3,728,270 (2,147,483,520 elements) is correct. The stated workload (M~960k x W12=576 = 553M elements) sits 3.9x below the limit and nothing in the op bounds M, so a scale-up crashes with an opaque GPU fault instead of a Python error. Author must assert xnumel < 2^31 (or index in int64) so the failure mode is a clear error.

📝 [verified] The op is dormant: the from .ops.X import * list in aiter/init.py and aiter/ops/init.py (license header only) never import aiter/ops/block_cat_fused.py, so torch.ops.aiter.block_cat_fused does not exist after import aiter — every consumer must import the module by hand, and no consumer PR is mentioned. (It also means the expired June red shards in test_aiter_add.py cannot be this file's doing, since import aiter never loads it — but only a fresh CI run settles that.) Reviewer should ask who imports aiter.ops.block_cat_fused and whether it belongs in the aiter namespace export list.

📝 [verified] The GPU gate in aiter/ops/block_cat_fused.py checks only l12 (l12.is_cuda and l12.dtype in (bf16, fp16)) — l4's dtype and device are neither asserted nor checked. Repro on MI300X: l12 bf16 + l4 fp32 on CUDA silently returns a bf16 tensor where the eager chain it replaces promotes to fp32 (max value diff 1.5e-2); cross-device input at least fails loudly in Triton. Reviewer should ask whether to assert l4.dtype == l12.dtype and same device at the op boundary.

@reger-men
reger-men force-pushed the aiter-block-cat-split-pattern branch from 87799b2 to 663aa46 Compare September 28, 2026 16:52
@reger-men

Copy link
Copy Markdown
Contributor Author

@zufayu thanks for the review. The earlier all-red CI was a stale-branch issue (the branch predated the ensure_zstd CI step), I rebased onto current main so the suite runs properly now, and the backward-contiguity fix, the int64 index guard, and the random-grad + non-contiguous backward tests you flagged are all in. Could you take another look when you get a chance?

@reger-men

Copy link
Copy Markdown
Contributor Author

@zufayu CI is green now on 663aa46, Aiter Test and Standard Test Results both pass: https://github.com/ROCm/aiter/actions/runs/36454114970

One thing I never answered from August is the xnumel/XBLOCK naming. I'm fine renaming those to the BLOCK_SIZE style used in the rest of aiter, and if the scope question from valarLip is the real blocker please tell me and I'll rework it. Could you take another look when you get a chance?

@zufayu

zufayu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for addressing the previously reported correctness issues: the non-contiguous backward outputs, random upstream-gradient coverage, fp16 stores, and int64 indexing are now fixed, and the latest CI on this head is green.

The remaining blocker is that this still does not follow the current AITER Triton structure. The Triton kernels, Python wrapper, and custom-op registration are all mixed into aiter/ops/block_cat_fused.py, while the test is placed at the top level of op_tests. The implementation also retains the Inductor-codegen-style xnumel/xoffset/xindex/XBLOCK builders rather than using the established AITER Triton organization.

Please restructure it consistently with the existing AITER fusion ops:

  • kernel implementation under aiter/ops/triton/_triton_kernels/fusions/;
  • public wrapper/custom-op integration under aiter/ops/triton/fusions/;
  • actual Triton correctness coverage under op_tests/triton_tests/fusions/;
  • use the normal Triton test discovery/CI path rather than a top-level test exception.

Two API/compile issues also remain:

  • The GPU gate validates only l12; it must explicitly require l4 to be on the same device and have the same dtype. Otherwise mixed BF16/FP32 inputs silently differ from the eager dtype-promotion semantics.
  • The fake implementations return empty_like(input) and therefore preserve non-contiguous input strides, while the real GPU forward and backward return contiguous tensors. Since this op is intended for torch.compile/AOTAutograd, fake metadata must match the runtime output layout.

This branch is also 165 commits behind current main. Please rebase, perform the structural rework above, and run fresh CI afterward.

@zufayu

zufayu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

@Dewei-Wang-sh Could you please review this PR as the Triton code owner? It adds a Triton fused forward/backward custom op, and the remaining blocker is aligning both the implementation and tests with the current AITER Triton fusion structure. Your review and sign-off would be valuable after the author completes that rework.

@zufayu
zufayu requested a review from Dewei-Wang-sh October 10, 2026 09:07
@reger-men
reger-men force-pushed the aiter-block-cat-split-pattern branch from 663aa46 to d85f931 Compare October 12, 2026 16:35
@github-actions github-actions Bot changed the title add block_cat_fused fused op [Triton/Gluon] add block_cat_fused fused op Oct 12, 2026
@reger-men

Copy link
Copy Markdown
Contributor Author

@zufayu thanks for the detailed review. I reworked it along those lines and rebased on current main, new head is d85f931.

  • Layout: kernels are now in aiter/ops/triton/_triton_kernels/fusions/block_cat_fused.py, the wrapper and custom ops in aiter/ops/triton/fusions/block_cat_fused.py (exported from aiter.ops.triton.fusions). The test moved to op_tests/triton_tests/fusions/test_block_cat_fused.py, so it goes through the normal triton test discovery with no top-level exception. I also added bench_block_cat_fused.py.
  • The xnumel/XBLOCK builders are gone. It's two plain @triton.jit kernels with make_kernel_repr and BLOCK_SIZE_N, and launch params come from configs/<arch>/triton/fusions/block_cat_fused/DEFAULT.json through _get_config like the other fusion ops. That should also cover the naming point from August.
  • l4 has to match l12 device and dtype (and shape) on every path now, so mixed bf16/fp32 asserts instead of silently going a different way than eager promotion. There's a test for each case.
  • both fake impls return contiguous tensors. I added a test that compares fake vs real strides under FakeTensorMode with transposed inputs.

Kernel math didnt change. I compared old vs new on MI355X and fwd out, grad_l12 and grad_l4 are bitwise identical in all 68 cases (fp16, bf16, fp32, contiguous and transposed inputs, the test shapes plus 960000x576 at W1=128 and 512, and 3-D). Perf on an idle MI355X with the clock locked at 960000x576 is within 0.2% of the old kernel for fwd and bwd at both W1. All 28 tests pass, black and ruff report no issues, and fresh CI is running on the new head.

I kept the bounds mask on even when N divides the block. I tried a mask-free variant, it was slower in 3 of the 4 fwd/bwd cells at that shape (up to 7%), so I dropped it.

@Dewei-Wang-sh could you review this when you get a chance?

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 can be disabled, benchmark bandwidth is miscalculated, and kernel trace representations omit specialization settings.

5 open findings
What changed in this PR

Adds a fused Triton operation combining block-wise leaky ReLU, multiplication, concatenation, and backward computation.

Changes:

  • Adds fused forward/backward kernels and public autograd wrapper.
  • Adds architecture-specific launch configurations.
  • Adds correctness tests and a performance benchmark.
File Description
aiter/​ops/​triton/​fusions/​block_cat_fused.py Implements validation, dispatch, custom ops, and autograd.
aiter/​ops/​triton/​fusions/​__init__.py Exports the new operation.
aiter/​ops/​triton/​_triton_kernels/​fusions/​block_cat_fused.py Defines fused forward and backward kernels.
aiter/​ops/​triton/​configs/​gfx942/​triton/​fusions/​block_cat_fused/​DEFAULT.json Adds gfx942 launch settings.
aiter/​ops/​triton/​configs/​gfx950/​triton/​fusions/​block_cat_fused/​DEFAULT.json Adds gfx950 launch settings.
aiter/​ops/​triton/​configs/​gfx1250/​triton/​fusions/​block_cat_fused/​DEFAULT.json Adds gfx1250 launch settings.
op_tests/​triton_tests/​fusions/​test_block_cat_fused.py Tests numerical, layout, compile, and fallback behavior.
op_tests/​op_benchmarks/​triton/​bench_block_cat_fused.py Benchmarks fused and eager implementations.

🧠 Review effort: Balanced


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

@azaidy azaidy self-assigned this Oct 12, 2026
Adds torch.ops.aiter.block_cat_fused, which packs
cat([leaky_relu(l12[..., :W1], slope), l12[..., W1:] * l4], dim=-1)
into one custom op. Forward runs a single fused Triton kernel on the
bf16/fp16 GPU path with an eager torch fallback for CPU/fp32. The
kernels store their result in the input dtype (via the output pointer's
element type) so an fp16 input stays fp16 with no silent bf16 downcast.
The registered backward is a second fused Triton kernel that produces
grad_l12 and grad_l4 together, so AOTAutograd dispatches one fused
backward target instead of decomposing into per-half pointwise grads.

Op-level forward/backward correctness tests cover the CPU fp32 fallback
and the GPU bf16 and fp16 Triton paths against an eager reference.

Signed-off-by: adlashab <[email protected]>
…, int64 index guard

Three fixes on the block_cat_fused op:

- backward allocated grad_l12/grad_l4 with torch.empty_like, which keeps a
  non-contiguous (e.g. transposed) input's strides while the kernel writes
  flat-contiguous. A permuted l12/l4 then got the flat writes scattered under
  the wrong strides and silently wrong grads. Allocate the grad outputs with
  contiguous_format so they match what the kernel writes.

- the flat index math (pid * XBLOCK, row * W4 + col) is int32 and wraps into an
  out-of-bounds fault once M * W12 >= 2^31. Promote the offset to int64 in both
  the forward and backward kernels.

- the backward tests only used out.sum().backward(), i.e. an all-ones upstream
  grad, so a kernel that drops the grad_cat factor still passed. Add a backward
  test with a random upstream grad and a non-contiguous-input backward test,
  both compared against eager autograd.

Signed-off-by: adlashab <[email protected]>
Kernels go to aiter/ops/triton/_triton_kernels/fusions/block_cat_fused.py,
wrapper and custom ops to aiter/ops/triton/fusions/block_cat_fused.py, test to
op_tests/triton_tests/fusions/, plus bench_block_cat_fused.py, same as the
other fusion ops. The xnumel/XBLOCK builders are replaced by module level
kernels with make_kernel_repr. Kernel math is unchanged, launch configs moved
to configs/<arch>/triton/fusions/block_cat_fused/DEFAULT.json with the same
values as before. The gfx1250 DEFAULT.json is a byte-identical copy of gfx950.

Review fixes on top:
- l4 has to match l12's device and dtype on every path, so mixed bf16/fp32
  asserts instead of silently differing from eager type promotion
- fake impls return contiguous tensors like the real fwd and bwd do
- the fwd/bwd custom ops register through torch_compile_guard and autograd
  goes through a torch.autograd.Function; block_cat_fused is exported from
  aiter.ops.triton.fusions

Signed-off-by: adlashab <[email protected]>
- _check_inputs raises ValueError instead of assert, so python -O can't
  let a short l4 through to the kernel
- the fwd and bwd kernel repr now carry W1/W12/W4/SLOPE next to
  BLOCK_SIZE_N (SLOPE needs the float handling from ROCm#6290)
- the bench counts the grad_l12 write in the fwd_bwd bytes (3*W12 + 2*W4)
- the empty-input test runs the backward too

Signed-off-by: adlashab <[email protected]>
@reger-men
reger-men force-pushed the aiter-block-cat-split-pattern branch from d85f931 to fd5a389 Compare October 15, 2026 17:42
@reger-men

Copy link
Copy Markdown
Contributor Author

@Dewei-Wang-sh @zufayu I went through the review bot points and rebased onto current main again (e8bdaf8), new head fd5a389.

  • the input checks raise ValueError now instead of assert, so python -O cant let a short l4 reach the kernel. Under -O an (8, 63) l4 for W12=96, W1=32 raises.
  • both kernel reprs carry W1/W12/W4/SLOPE next to BLOCK_SIZE_N, so a compiled name looks like _block_cat_fused_fwd_kernel_W1_128_W12_576_W4_448_SLOPE_0_01_BLOCK_SIZE_N_2048. SLOPE needs the float handling [Triton/Gluon] Support Muse QK norm scale in fused RoPE cache op #6290 added to make_kernel_repr, thats the reason for the rebase. I left num_warps / num_stages out: they arent in specialization.constants on this triton and only come out as NONE.
  • the bench counts the grad_l12 write in the fwd_bwd bytes (3W12 + 2W4)
  • the empty-input test runs the backward too

On MI355X (torch 2.14.0, triton 3.8.0 CI wheel): test_block_cat_fused.py 28 passed, test_fused_sigmoid_mul.py 130 passed, black and ruff clean. Could one of you take a look?

@reger-men

Copy link
Copy Markdown
Contributor Author

@zufayu @Dewei-Wang-sh the red on fd5a389 is Triton Tests (MI35X) / Shard 4 (Triton Test Results is red only because of it), and its not from this PR. The shard died with a segfault, exit 139, in op_tests/triton_tests/attention/test_mla_v4_triton.py::test_pa_decode_sparse_vs_reference[False-False-True-136-512-16-1]. The main thread was inside inspect._signature_from_callable, no assert failed. This PR only touches the block_cat_fused files, and test_block_cat_fused.py wasnt in that shard.

On MI355X (rocm/pytorch latest, triton 3.8.0 CI wheel) that test passes 20 of 20 on this head and on main 033e8bd, and the whole test_mla_v4_triton.py file is 114 passed / 10 skipped on both. I also went through the failed Triton Test shard jobs since 10-12 (92 of them): this segfault shows up only in this run, other runs have one-off "Fatal Python error: Aborted" crashes in other shards, main b7f2fca included.

Could someone re-run the failed jobs of run 38779511856? gh run rerun --failed is refused on my side.

@zufayu

zufayu commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@Dewei-Wang-sh I re-reviewed the current head. The Triton layout rework and the correctness/API issues from the previous review have been addressed, and all 28 block_cat_fused tests pass on both MI35X and MI300X. The remaining red Triton shard is an unrelated segfault in test_mla_v4_triton.py; the block_cat_fused suite ran in shard 2 and passed.

Could you please provide the final Triton-owner review/sign-off when you have a chance? This is the remaining review dependency.

@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 bc7011f into ROCm:main Oct 28, 2026
solinzby1 pushed a commit that referenced this pull request Nov 2, 2026
* add block_cat_fused fused op

Adds torch.ops.aiter.block_cat_fused, which packs
cat([leaky_relu(l12[..., :W1], slope), l12[..., W1:] * l4], dim=-1)
into one custom op. Forward runs a single fused Triton kernel on the
bf16/fp16 GPU path with an eager torch fallback for CPU/fp32. The
kernels store their result in the input dtype (via the output pointer's
element type) so an fp16 input stays fp16 with no silent bf16 downcast.
The registered backward is a second fused Triton kernel that produces
grad_l12 and grad_l4 together, so AOTAutograd dispatches one fused
backward target instead of decomposing into per-half pointwise grads.

Op-level forward/backward correctness tests cover the CPU fp32 fallback
and the GPU bf16 and fp16 Triton paths against an eager reference.

Signed-off-by: adlashab <[email protected]>

* block_cat_fused: fix backward stride corruption, add random-grad test, int64 index guard

Three fixes on the block_cat_fused op:

- backward allocated grad_l12/grad_l4 with torch.empty_like, which keeps a
  non-contiguous (e.g. transposed) input's strides while the kernel writes
  flat-contiguous. A permuted l12/l4 then got the flat writes scattered under
  the wrong strides and silently wrong grads. Allocate the grad outputs with
  contiguous_format so they match what the kernel writes.

- the flat index math (pid * XBLOCK, row * W4 + col) is int32 and wraps into an
  out-of-bounds fault once M * W12 >= 2^31. Promote the offset to int64 in both
  the forward and backward kernels.

- the backward tests only used out.sum().backward(), i.e. an all-ones upstream
  grad, so a kernel that drops the grad_cat factor still passed. Add a backward
  test with a random upstream grad and a non-contiguous-input backward test,
  both compared against eager autograd.

Signed-off-by: adlashab <[email protected]>

* block_cat_fused: move into the triton fusions layout

Kernels go to aiter/ops/triton/_triton_kernels/fusions/block_cat_fused.py,
wrapper and custom ops to aiter/ops/triton/fusions/block_cat_fused.py, test to
op_tests/triton_tests/fusions/, plus bench_block_cat_fused.py, same as the
other fusion ops. The xnumel/XBLOCK builders are replaced by module level
kernels with make_kernel_repr. Kernel math is unchanged, launch configs moved
to configs/<arch>/triton/fusions/block_cat_fused/DEFAULT.json with the same
values as before. The gfx1250 DEFAULT.json is a byte-identical copy of gfx950.

Review fixes on top:
- l4 has to match l12's device and dtype on every path, so mixed bf16/fp32
  asserts instead of silently differing from eager type promotion
- fake impls return contiguous tensors like the real fwd and bwd do
- the fwd/bwd custom ops register through torch_compile_guard and autograd
  goes through a torch.autograd.Function; block_cat_fused is exported from
  aiter.ops.triton.fusions

Signed-off-by: adlashab <[email protected]>

* block_cat_fused: raise on bad inputs, full kernel repr, bwd byte count

- _check_inputs raises ValueError instead of assert, so python -O can't
  let a short l4 through to the kernel
- the fwd and bwd kernel repr now carry W1/W12/W4/SLOPE next to
  BLOCK_SIZE_N (SLOPE needs the float handling from #6290)
- the bench counts the grad_l12 write in the fwd_bwd bytes (3*W12 + 2*W4)
- the empty-input test runs the backward too

Signed-off-by: adlashab <[email protected]>

---------

Signed-off-by: adlashab <[email protected]>
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.

5 participants