Skip to content

[OPUS] Define Latent MoE grouped-GEMM backward for Kimi-K3/K3.1 - #8464

Draft
minmengdie wants to merge 1 commit into
ROCm:mainfrom
minmengdie:draft/kimi-latent-moe-grouped-gemm-bwd
Draft

minmengdie wants to merge 1 commit into
ROCm:mainfrom
minmengdie:draft/kimi-latent-moe-grouped-gemm-bwd

Conversation

@minmengdie

Copy link
Copy Markdown
Contributor

Summary

Propose a BF16 grouped linear backward for the routed experts in Kimi-K3 and Kimi-K3.1. This is the P0 “Latent MoE grouped-GEMM backward” item in Lumen #35, section 1.4. Following aiter #8377, this first commit puts the API, reference math and tests up for review. The entry point raises NotImplementedError after its input checks. The OPUS kernels will follow on this branch.

Proposed interface

from aiter.ops.opus.latent_moe_grouped_gemm_bwd import latent_moe_grouped_gemm_bwd

dx, dw = latent_moe_grouped_gemm_bwd(x, weight, dy, expert_offsets)

For a local expert shard, weight[E,N,K] uses ordinary linear-layer layout. x[R,K] and dy[R,N] are aligned rows already grouped by expert. R counts routed assignments after dispatch. The contiguous int32 offset vector has E+1 entries, runs from 0 to R and permits repeated boundaries for empty experts. The caller owns this value invariant. Inputs reside on one device.

For each expert interval, compute dx_e = dy_e @ W_e (return BF16) and dw_e = dy_e.T @ x_e (return FP32). Empty experts contribute a zero weight gradient. An EP rank supplies only its local experts. Kimi selects 16 of 896 routed experts globally.

  • Gate (w1) and up (w3) each use (K, N) = (3584, 3072). The caller supplies the two derivatives from SiTU-GLU and adds the two input-gradient contributions.
  • Down (w2) uses (K, N) = (3072, 3584) with the saved post-activation expert input.
  • Routing, scatter/combine, shared experts, latent projections, SiTU differentiation and quantized training are separate items in the Lumen tracker.

Implementation milestones

  • Proposed tensor contract and metadata checks, per-expert FP32 oracle, and gradient tests
  • Implement gfx950 grouped dgrad and wgrad, including zero-row experts and uneven group lengths
  • Run both real-width projections on gfx950 against the FP32 oracle and benchmark representative top-16 expert loads
  • Validate the grouped linear gradients in the Tiny-L13 BF16 MoE layer with Lumen

PR Self-Review

Reviewed revision

c8d9c5aaedd677e6ee416adad13d784eefef8211

Behavior and intent

Adds an opt-in module for reviewing the routed linear backward contract before integrating a kernel or a training caller.

Validation and unverified scope

Windows CPU, PyTorch 2.10.0, AITER_TRITON_ONLY=1 python -m pytest -q op_tests/test_latent_moe_grouped_gemm_bwd.py — 5 passed, 2 skipped. Four autograd comparisons and the input contract passed. The two real-width cases require gfx950. Python syntax and git diff --cached --check also passed. GPU kernel accuracy, timing and Lumen integration remain pending.

PR-specific question

The caller partitions rows by local expert before the GEMMs. Empty expert intervals produce zero dW. Review feedback is particularly welcome on the offset format and FP32 weight-gradient return type before wiring the gfx950 launcher.

Changed op tests

op_tests/test_latent_moe_grouped_gemm_bwd.py compares a per-expert FP32 backward with autograd over a separate per-assignment forward, including entirely empty batches and imbalanced groups. It checks shape and dtype errors and provides gfx950 parity cases at both Kimi widths. The GPU cases skip while the draft kernel is pending.

Signed-off-by: minmengdie <222133928+minmengdie@users.noreply.github.com>
@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 8464 --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.

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.

1 participant