Skip to content

[FlyDSL] [gfx950] Kimi-K3 KDA gated RMSNorm backward - #8741

Draft
huizzhan wants to merge 4 commits into
mainfrom
cursor/kda-gated-rmsnorm-bwd-b8b6
Draft

huizzhan wants to merge 4 commits into
mainfrom
cursor/kda-gated-rmsnorm-bwd-b8b6

Conversation

@huizzhan

@huizzhan huizzhan commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Standalone gated RMSNorm backward for the KDA output norm, out = o * rsqrt(mean(o^2, -1) + eps) * w * sigmoid(gp) (o: [B, T, H, 128] or any [..., V]). main has no gated RMSNorm backward: the existing gated RMSNorm ops are forward/quant only, and the Triton rmsnorm backward has no gate.

The kernel started as the one from #8739 commit 31f1d2e (removed there in 7b5df91), so there is one canonical copy. It has since been optimized:

  • aiter/ops/flydsl/kernels/gated_rmsnorm_bwd.py: create_gated_rmsnorm_bwd_kernel.
    • It reads o, gp, dy and w in their own dtype (bf16, fp16 or fp32) with 128-bit buffer loads, so bf16 inputs no longer go through fp32 cast copies.
    • It writes do and dgp as fp32 with 128-bit buffer stores.
    • Each lane owns 8 contiguous elements, so a D=128 row takes 16 lanes and its reductions are 16-lane xor shuffles.
    • A 256-thread block handles 16 rows per pass. It runs 4 passes, or 8 when the input has at least 131072 rows, and issues every pass's loads before any math.
    • dweight is reduced in two stages and uses no atomics. Each block sums its rows through registers and LDS and writes one partial, then the wrapper sums the per-block partials.
  • aiter/ops/flydsl/gated_rmsnorm_bwd.py: gated_rmsnorm_bwd(o, gp, w, dy, eps=1e-6) -> (do, dgp, dw) with fp32 outputs, plus the gated_rmsnorm_bwd_torch autograd reference.
  • op_tests/test_flydsl_gated_rmsnorm_bwd.py: checks accuracy against torch and measures perf for bf16, T=1000/1001/2048, H=96/48, D=128. T=1001 covers a partial last block. TB/s counts 3 input reads plus 2 fp32 writes.

This matches #8739's hook contract, so it plugs in like this:

from aiter.ops.flydsl.gated_rmsnorm_bwd import gated_rmsnorm_bwd
register_gated_rmsnorm_bwd(gated_rmsnorm_bwd)

Measured on MI350X at 737336b (accuracy passes 18/18): T=2048 H=96 runs in 101 us at 3.48 TB/s (was 242 us), and T=1000 H=96 runs in 60 us at 2.9 TB/s.

Follow-up 1dc49b6, not yet measured:

  • Each block issues the loads of all its passes before any math, so more bytes are in flight.
  • w is read in the input dtype, which removes a separate fp32 cast launch.
  • Inputs with at least 131072 rows use 8 passes per block (145 VGPRs) instead of 4 (94 VGPRs). Neither uses scratch.

The dw partial sum is still a torch sum(0) over n_blocks x V. Folding it into the kernel needs a grid-wide counter (atomics plus fences, so that the last block can sum the partials) or a second launch, so it is left as is.

Limits:

  • V/8 must be a power of two up to 64, so V is between 8 and 512.
  • Mixed or other input dtypes go through fp32.
  • numel*4 must be below 2^31 (32-bit buffer offsets).
  • dgp is the gradient with respect to the gate pre-activation.
Open in Web Open in Cursor 

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 8741 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

cursor Bot pushed a commit that referenced this pull request Nov 26, 2026
@cursor cursor Bot mentioned this pull request Nov 26, 2026
12 of 19 tasks
cursor Bot pushed a commit that referenced this pull request Nov 26, 2026
…-import, FlyDSL GEMMs for g_proj bwd

Co-authored-by: Sealeen Zhang <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 26, 2026
…ir constraints and fall back to torch with the reason in LAST_PIECES

Co-authored-by: Sealeen Zhang <[email protected]>
@huizzhan huizzhan changed the title Kimi-K3 KDA gated RMSNorm backward (FlyDSL) [FlyDSL] [gfx950] Kimi-K3 KDA gated RMSNorm backward Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants