Skip to content

[Triton/Gluon] Support Muse QK norm scale in fused RoPE cache op - #6290

Merged
vgokhale merged 8 commits into
mainfrom
vinayak/rope_muse_fusion
Oct 13, 2026
Merged

vgokhale merged 8 commits into
mainfrom
vinayak/rope_muse_fusion

Conversation

@vgokhale

@vgokhale vgokhale commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Muse Glimmer scales BF16-rounded, weightless RMSNorm queries before RoPE. The existing fused QKV norm/RoPE/cache operator did not reproduce that arithmetic, so Muse could not use the fusion.

This adds an optional q_scale while keeping q_scale=1 on the existing arithmetic path. The wrapper allocates and returns Q/K/V outputs internally and writes K/V into the supplied paged caches; it does not accept caller-provided Q/K/V output buffers.

Changes

  • Round normalized Q to BF16, apply q_scale, round again, then use BF16-rounded RoPE products for the scaled path.
  • Select 4-token and 16-token tiles for gfx950 scaled-Q decode and prefill, respectively. This is a small fixed dispatch heuristic, with block_t available for an explicit override.
  • Include Q_SCALE in the kernel trace name and sanitize non-integral float values into valid Triton identifiers.
  • Extend the existing parameterized fused RoPE/cache test with weightless, scaled-Q cases at 1, 64, and 1024 tokens. The 1024-token case exercises the T > 128 tile.

Validation

  • pytest -q op_tests/triton_tests/rope/test_fused_qkv_split_qk_rope.py -k with_cache on gfx950: 771 passed, 256 skipped. The three scaled-Q cases passed.
  • Black checks, py_compile, and git diff --check passed for the changed files.
  • Isolated BF16 Muse shape (QH=32, KVH=2, D=128, NHD page-16 cache), versus compiled QK norm/scale/RoPE plus cache update on gfx950:
Tokens Baseline Fused Speedup
64 6.735 µs 2.313 µs 2.91×
1024 13.816 µs 6.735 µs 2.05×
8192 62.189 µs 36.001 µs 1.73×

At 8192 tokens, the maximum absolute difference from the compiled BF16 baseline was 0.25 for Q and 0.03125 for K/cache; V and cached V matched exactly. Model-level lm-eval and a vLLM A/B isolating this fusion have not been run. vLLM integration is separate from this library PR.

@vgokhale
vgokhale requested a review from a team October 8, 2026 22:58
@github-actions

github-actions Bot commented Oct 8, 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: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: 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 6290 --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.

@github-actions github-actions Bot changed the title [Triton] Support Muse QK norm scale in fused RoPE cache op [Triton/Gluon] Support Muse QK norm scale in fused RoPE cache op Oct 8, 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

Caller-provided outputs remain unimplemented, and the hardcoded tuning and coverage gaps should be addressed.

4 open findings
What changed in this PR

Extends the fused QKV norm/RoPE/cache Triton path with Muse-compatible query scaling and BF16 rounding.

Changes:

  • Adds q_scale and gfx950 token-tile selection.
  • Implements scaled Q and rounded Q/K RoPE arithmetic.
  • Adds focused Muse correctness tests.
File Description
aiter/​ops/​triton/​rope/​fused_qkv_split_qk_norm_rope_cache.py Adds scaling API and tile selection.
aiter/​ops/​triton/​_triton_kernels/​rope/​fused_qkv_split_qk_norm_rope_cache.py Implements scaling and rounded RoPE products.
op_tests/​triton_tests/​rope/​test_fused_qkv_split_qk_rope.py Tests Muse BF16 behavior and cache writes.

🧠 Review effort: Balanced


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

@zufayu
zufayu requested review from a team and azaidy October 9, 2026 01:54

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

Can you add a benchmark as well?

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

@vgokhale
vgokhale merged commit 8a21075 into main Oct 13, 2026
@vgokhale
vgokhale deleted the vinayak/rope_muse_fusion branch October 13, 2026 18:14
reger-men added a commit to reger-men/aiter that referenced this pull request Oct 15, 2026
- _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]>
azaidy pushed a commit that referenced this pull request Oct 28, 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]>
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.

3 participants