Skip to content

Merge Kimi BF16 MoE front and combine its reductions - #3637

Open
whx-sjtu wants to merge 2 commits into
mainfrom
task-695-moe-compute-main
Open

whx-sjtu wants to merge 2 commits into
mainfrom
task-695-moe-compute-main

Conversation

@whx-sjtu

@whx-sjtu whx-sjtu commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes https://github.com/wuhuikx/LLM-Booster/issues/695, closes https://github.com/wuhuikx/LLM-Booster/issues/696, and closes https://github.com/wuhuikx/LLM-Booster/issues/702. Ready for human review; hold landing.

Kimi's eligible BF16 shared-front, router and latent-down projections share one GEMM and one weight allocation. Routed/shared partials share one reduction before routed normalization; supported MXFP4 consumers receive the latent input view directly.

Dev record

  • Found: current main has eager MoE dispatch and shared-expert combine receivers beyond the donor implementation.
  • Decided: preserve those receivers and the existing op; add a void destination-writing op, with shape/dtype/layout and overlap checks. Unsupported methods copy their returned result. Original checkpoint parameter names and identities remain.
  • Surprised: none.
  • Left undone: remaining performance, memory and integration acceptance. #3587 and #3628 remain merge-order dependencies; their unlanded implementations are excluded from this main-based diff.

Named result

CPU paths preserve values/storage with one front call and one reduction. The GPU selected-kernel witness qualifies inline BF16 views at 16/32 rows only; 128 rows use the intended contiguous-FP4 fallback. The full packet remains inconclusive. The native plain TP8/DCP8 accuracy result is recorded below; complete decode/verify/prefill timing and temporary/steady-state memory attribution remain open.

Testing

Native plain Kimi-K3.1-Pro passed full GSM8K 3-shot: 1275/1319 = 0.9666413949962093 for both strict-match and flexible-extract, above the unchanged 0.96 threshold. The run used TP8/DCP8, default level 3/FULL graphs and mono, with no eager override or DSpark. Independent verification covered all 2,638 physical JSONL records, scoring, inputs, source/runtime/model bindings and final GPU cleanup. Reviewable evidence.

Source, runtime and qualification limits

Executed tree fa7ea15c7d5aaae0f7d2ec12fb2d07aaddace99c is the prospective integration of this PR's cb6f1af7 with main 6180dbcff9. All 3,929 source files match that Git tree canonically: 3,555 after CRLF-to-LF normalization and 374 as raw bytes. Runtime: 4aff image base, AITER ga5927ba8f, Torch 2.10.0/ROCm7.2.4. Data: fixed GSM8K revision 740312, full 1,319 documents, three-shot, unchanged seeds and 65 concurrent requests.

The model input was an explicit 80aff content-reuse view: 15 small files verified by content and 96 weights bound by official LFS IDs, existing download metadata and file identities. It was not claimed as a native HF snapshot; weight payloads were not fully rehashed and the original 6d directory was unchanged. Startup/capture logs witness all-eight mono installation and FULL capture, not a per-request kernel trace.

The earlier 0/1319 result at dcedefc8, e1 image/AITER5c remains a real historical failure. The source/runtime and recorded input provenance differ; this pass does not establish its root cause or a causal fix. It qualifies this recorded native configuration, not all Category A acceptance. The selected-stage1 strided-view question, remaining full-path timing/memory evidence, dependencies and formal reviewer disposition retain their separate scopes.

Gates

cb6f1af7fc7e3c9f8722750419c09c9b6b966790: maintained CPU CI passed 15208 cases, with 1548 skips and 3 xfails; Black/Ruff/catalog passed. Focused CPU: 157 passed, 5 GPU skips. Independent repository review found no source/CPU blocker. The new native plain result is scoped above; other declared acceptance requirements and dependencies retain hold landing.

Evidence and limits

Base: main ecec81921da0c27a088d542fcefad51fe83e4d5a. This is one category PR, covering all three issue checklists.

The supervised November 20 GPU run used this unchanged head with existing AITER b9e08daca8c45dd758f4fa1fbb7d0da027f399c9, one gfx950 GPU, generated weights and TP8 per-rank dimensions. Independent artifact audit verified the 16/32-row launch pointers, 12032-byte versus 7168-byte strides, actual raw cat=kernel events and whole rank-local MoE relative-L2 errors 0.0062340/0.0060198, below the upstream 0.02 bound. The 128-row selected callable instead received contiguous FP4; its numerical observations do not qualify inline BF16 copy elimination. Exit 2/inconclusive and original artifacts are preserved. This is kernel-scope evidence, with no model, timing or landing pass.

The scoped review record passed seven repository gates and non-author refutation. It independently reproduced the focused CPU checks and eleven controls, including the actual AOT owner-copy failure after bypassing the schema assertion. Review covers source and CPU scope; the outstanding runtime and integration requirements retain hold landing.

CI checkout 6cca75cb98dc1e5cb5c7a17b18ed79b3d6372190 has the same tree as the PR head: 04c3f357b7bdc0b2cf4f11e1c4765f361c5adc27. Its JUnit report confirms all 52 new cases executed without skips, including CPU AOT functionalization and compiled row-view storage identity. CI uses Torch 2.15.0+cpu; the focused Windows environment uses Torch 2.10.0+cpu. A separate full production-block CPU AOT check also passed, including flat reduction-buffer writes. These checks do not qualify GPU lowering.

Real Kimi/FusedMoE constructors, native/plugin load wrappers, checkpoint parameter loaders, routed/shared consumers, destination fallbacks, and the production MXFP4 apply method run on small CPU tensors. External GPU kernels are substituted. The repository's normal test fixtures are loaded; Windows uses the established import-only process stand-ins and cannot qualify Linux or GPU execution.

The public AITER fused_moe implementation was inspected at afc300d7fee1b38cd805da517414c42114b35968, blob 645974ac3620079854191386d3ce368605666c4d. ATOM retains aligned BF16 row views only for direct MXFP4. AITER validates the selected inline-sort configuration and copies views on unsupported kernel fallbacks; other ATOM backends retain contiguous inputs. No donor timing is attributed to this head.

Negative control Passed / failed
Exact main parent model 0 / 9
Rolled slices; copied parameter storage 0 / 9 each
Omitted or doubled combined reduction 3 / 3 each
Omitted fallback destination copy 1 / 7
Omitted native destination 0 / 5
Restored latent input copy 0 / 1
Ignored base alignment 4 / 1
Allowed output/input overlap 3 / 2
Declared read-only input mutated 0 / 2

All controls were restored before the positive run. The new output op mutates only its destination; declaring its input mutated made AOT clone the input view's owner. Modular receivers pass inplace=False, and SP and ordinary receivers write separate outputs.

Scope: 247 changed production lines and 590 test lines, 837 total. Dependency integration and final landing-tree checks remain outstanding.

@whx-sjtu whx-sjtu added the agent-team/hold-landing Holds landing only; development and review go on label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Gate checks are published on every PR so required checks do not stay missing
  • ✅ Expensive jobs run only after the PR is approved, or when a matching ci:* label is present
  • ✅ Pre Checkin must pass before approved heavy jobs continue
  • ✅ Without a matching label, expensive jobs also require a relevant path
  • ✅ A matching ci:* label is an explicit request and can open the gate even when paths would otherwise skip it

Path scope:

  • Native ATOM, vLLM, and SGLang use ignore lists: docs/markdown and unrelated plugin or Mesh paths are skipped
  • ATOMesh uses an include list: Mesh code, ATOMesh scripts/workflows/catalogs, OpenAI entrypoints, and Slurm helpers
  • Relevant path alone does not start expensive jobs; approval still opens the automatic path-scoped gate
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, SGLang, and ATOMesh
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests
ci:mesh Run ATOMesh accuracy/benchmark gates for Mesh-related changes

Without a matching ci:* label, heavy jobs are skipped when the path is not relevant or the PR is not approved.
Add labels via the sidebar or gh pr edit 3637 --add-label <label>

@whx-sjtu whx-sjtu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATOM PR #3637 — Merge Kimi BF16 MoE front and combine its reductions

Merges eligible Kimi projections into one BF16 GEMM, reduces routed/shared partials together, and preserves supported latent input views through an explicit output destination.

Review: ✅ LGTM for source and CPU scope at cb6f1af7fc7e3c9f8722750419c09c9b6b966790; one grouped Category A PR, with landing held.
Coverage: 2 files / 235 added lines -- within one review pass
Validation (advisory): Independent Windows CPU: 157 passed, 5 GPU skipped; eleven in-memory controls rejected their defects, including a direct AOT owner-copy witness — one run, this box, unverified by the deterministic validator. Maintained Linux CI: 15,208 passed, 1,548 skipped, 3 xfailed; all 52 new CPU cases executed. CI merge 6cca75cb98 has the same tree as this head. GPU numerical/compiled execution, native/plugin accuracy, complete decode/verify/prefill timing, temporary and steady-state memory, #3587/#3628 integration and final landing-tree checks remain outstanding. No landing approval.

@whx-sjtu
whx-sjtu marked this pull request as ready for review November 20, 2026 09:49

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes needed..

gpu evidence that aiter's selected mxfp4 stage-1 kernel accepts the row-strided view and matches the contiguous path?

ci green.

@whx-sjtu

whx-sjtu commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Part of the selected-stage1 question: the selected GEMM1 consumes the original row view at 16/32 rows; paired complete FusedMoE outputs satisfy the original relative-L2 bound of 0.02. No separate GEMM1 intermediate output was saved.

Executed boundary and numerical scope

The operator uses cb6f1af7, AITER b9e08daca8c45dd758f4fa1fbb7d0da027f399c9, gfx950, identical inputs/weights/routes. At the actual selected-port launch, the view retains its pointer and 12032-byte row stride; the dense control has a separate pointer and 7168-byte stride. Four raw GPU traces cover both paths and shapes.

View/dense relative L2 is 0.00623400698/0.00601975403 at 16/32 rows. These are complete rank-local FusedMoE comparisons with generated weights. The 128-row selection uses contiguous FP4 fallback; the original packet's overall inconclusive result remains.

The separate 9b9c8706 A4W4 native FULL model binds 91 eligible GEMM1 calls per step to the same view pointers/strides and live graph replay on all eight ranks, with no preceding BF16 input-copy nodes. The last layer retains fallback. Default A16W4 still copies. The operator's STAGE2_FP8=1 and model's unset flag retain separate attribution; the selected 16/32-row first-stage and atomic-GEMM2 contract matches.

whx-sjtu pushed a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
The token-graph hunks of ROCm#3636's integration commit 80ae966
("Integrate Kimi prefill graphs and explicit residual storage contracts"),
verbatim:

- `_KimiMLAGDNCommon.supports_token_graph` also accepts a target MLA layer
  that is sparse and carries a bound unscaled BF16 query layout
  (`TokenGraphQueryLayout`), so Kimi-K3.1 at DP1/PCP1 records its prefill
  buckets. Quantized or unknown query layouts keep eager execution.
- The layout check moves from `_attention` into `_attention_region`, so a
  plain eager call never enters the token-graph helper.
- docs: ATOM_TOKEN_GRAPH_SIZES names the K3.1 regions.
- tests: the gate's accept/refuse cases and the plain-call bypass.

Left out, because this head has none of the code they integrate with:
the row tail's in-graph guard and the KDA in_proj split on buckets
(ROCm#3587), ColumnTail materialization at tensor-only boundaries
(ROCm#3637/ROCm#3638), and the native eager residual's absent addends (the ROCm#3317
part, which exists only on a row-sharded step). Whoever merges those
stacks with this one needs those hunks of 80ae966 too.

Co-authored-by: Cursor <cursoragent@cursor.com>
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
(cherry picked from commit c24b52a)
Conflict in atom/models/kimi_k3/model.py (this commit was written against
main without ROCm#3637) resolved as in upstream merge 931b22b ("Merge Category A
interfaces for local tail integration") of ROCm#3638.

Ported from ROCm#3638.

Co-authored-by: Cursor <cursoragent@cursor.com>
whx-sjtu pushed a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
…ROCm#3637 ROCm#3638) k31-opt2/PT4@2c68a46f

Conflicts resolved as ROCm#3636 does for PT3 (ROCm#3577/ROCm#3582/ROCm#3587) + PT4:
- kimi_k3/attention_residual.py: PT4's kernel with PT3's num_blocks bound;
  PT3's int64 bank offsets (71a6aba) moved into PT4's _mix_tile and kernel.
- model.py: column tail first (decode, 1-64 tokens), then PT3's dispatch op;
  row tail (>= ATOM_KIMI_K3_MOE_ROW_SHARD_MIN_TOKENS) before PT4's one-AR
  split; aggregate materializes column pendings; per-phase token_graph.
@valarLip valarLip removed the ci:atom label Nov 25, 2026
@valar-cop

Copy link
Copy Markdown

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

agent-team/hold-landing Holds landing only; development and review go on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants