Repository navigation
[OPUS] Define Latent MoE grouped-GEMM backward for Kimi-K3/K3.1 - #8464
minmengdie wants to merge 1 commit into
Conversation
Signed-off-by: minmengdie <222133928+minmengdie@users.noreply.github.com>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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
NotImplementedErrorafter its input checks. The OPUS kernels will follow on this branch.Proposed interface
For a local expert shard,
weight[E,N,K]uses ordinary linear-layer layout.x[R,K]anddy[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) anddw_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.Implementation milestones
PR Self-Review
Reviewed revision
c8d9c5aaedd677e6ee416adad13d784eefef8211Behavior 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 andgit diff --cached --checkalso 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.pycompares 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.