Skip to content

model: Kimi-K3 (kimi_linear + kimi_k3) decode/prefill + K3 MXFP4 kernels + tests - #315

Closed
Andrewxu313 wants to merge 3 commits into
k3-core-prfrom
k3-model-pr
Closed

Andrewxu313 wants to merge 3 commits into
k3-core-prfrom
k3-model-pr

Conversation

@Andrewxu313

Copy link
Copy Markdown
Contributor

Description

Kimi-K3 model + kernels + tests (models/moonshotai/kimi_linear + kimi_k3, batchgen_kernels/**, tests/**). Stacked on #314 (k3-core-pr) — review/merge that first.

Motivation

Model-layer half of K3 day-0 support: whole-model decode CUDA graph, MoE graph segments, DeepEP-vs-NCCL exchange wiring + planner, PSM prewarm, Triton kernels (situ, row_gather, rmsnorm int64, kda_conv, attn_residual), vocab-parallel embed/lm_head, distributed-weight-store client, K3 MXFP4 layout + tensor map, tokenizer; K3 MXFP4/INT4 WGMMA + marlin grouped GEMM + kda_fused_decode kernels. GLM-5 excluded (rode this branch; goes via the GLM line — the decode-MoE AllReduce change is already on release/v1.0.10-glm5-cudagraph).

Type of Change

  • model — add/extend model support (models/** + registration seam + model kernels + tests)

File changes

Full list vs the core PR base (k3-core-pr):

 batchgen/models/moonshotai/kimi_k3/MODULE.md       |    6 +-
 batchgen/models/moonshotai/kimi_k3/model.py        |    6 +-
 batchgen/models/moonshotai/kimi_k3/tokenizer.py    |    4 +-
 .../kimi_linear/Parallel_Strategy_Manager.py       | 1435 +++++-
 .../moonshotai/kimi_linear/attn_residual_triton.py |  281 ++
 .../moonshotai/kimi_linear/block_residual.py       |  169 +-
 .../moonshotai/kimi_linear/cuda_graph_segments.py  | 1196 ++++-
 .../kimi_linear/distributed_weight_store.py        |  107 +
 .../moonshotai/kimi_linear/k3/mxfp4_expert.py      |  126 +-
 .../moonshotai/kimi_linear/k3/mxfp4_layout.py      |   10 +
 .../models/moonshotai/kimi_linear/k3/tensor_map.py |    3 +-
 .../moonshotai/kimi_linear/kda_conv_triton.py      |  302 ++
 .../moonshotai/kimi_linear/kimi_initializer.py     |   72 +-
 .../kimi_linear/kimi_parameter_server.py           |   11 +-
 batchgen/models/moonshotai/kimi_linear/model.py    |  386 +-
 .../kimi_linear/moe_cuda_graph_segments.py         | 1025 +++++
 .../moonshotai/kimi_linear/moe_tp_reshard.py       |  295 ++
 batchgen/models/moonshotai/kimi_linear/planner.py  |  428 +-
 .../moonshotai/kimi_linear/rmsnorm_triton.py       |   65 +
 .../moonshotai/kimi_linear/row_gather_triton.py    |   99 +
 .../moonshotai/kimi_linear/serving_modules.py      |  692 ++-
 .../models/moonshotai/kimi_linear/situ_triton.py   |   71 +
 .../moonshotai/kimi_linear/tp_weight_sharding.py   |   62 +
 .../moonshotai/kimi_linear/vocab_parallel.py       |   79 +
 .../kimi_linear/whole_model_cuda_graph_segments.py |  503 ++
 batchgen/models/moonshotai/kimi_linear/wrappers.py |   91 +-
 batchgen_kernels/__init__.py                       |   32 +-
 batchgen_kernels/_jit_registry.py                  |   19 +-
 batchgen_kernels/_version.py                       |   10 +-
 batchgen_kernels/attention/dsa/fast_topk_cuda.py   |   22 +-
 batchgen_kernels/attention/kda_fused_decode.py     |  200 +
 batchgen_kernels/setup.py                          |   13 +
 batchgen_kernels/src/attention/kda_fused_decode.cu |  612 +++
 batchgen_kernels/src/attention/qkv_wgmma.cu        |    6 -
 batchgen_kernels/src/moe/dispatch_scatter_3d.cu    |   82 +
 batchgen_kernels/src/moe/expert_mxfp4_wgmma.cu     |    6 -
 .../src/moe/fused_int4_wgmma_grouped.cu            |    6 -
 batchgen_kernels/src/moe/grouped_int4_wgmma.cu     |    7 +-
 batchgen_kernels/src/moe/grouped_int4_wgmma_ext.cu |    7 +-
 batchgen_kernels/src/moe/grouped_mxfp4_wgmma.cu    |   10 +-
 batchgen_kernels/src/moe/marlin_grouped_gemm.cu    |   81 +-
 .../src/moe/routing/gate_sigmoid_topk.cu           |  207 +-
 .../src/moe/routing/routing_extension.cc           |   34 +-
 batchgen_kernels/src/moe/routing/routing_ops.h     |   17 +-
 .../src/moe/single_expert_int4_wgmma.cu            |    7 +-
 tests/gpu/kimi_linear_tp_weight_parity.py          |  186 +
 tests/gpu/mxfp4_resident_ep_world2_parity.py       |  253 +
 tests/gpu/run_kimi_k3_kda_instance1.sh             |   35 +
 tests/gpu/streamed_sp8_mxfp4_world8_parity.py      |  542 +++
 tests/gpu/test_gate_sigmoid_topk_k16.py            |  369 ++
 tests/gpu/test_kimi_k3_attn_residual_triton.py     |  182 +
 tests/gpu/test_kimi_k3_dequant_once_prefill.py     |  123 +
 .../gpu/test_kimi_k3_kda_batched_segment_parity.py |   52 +
 tests/gpu/test_kimi_k3_kda_conv_triton.py          |  105 +
 tests/gpu/test_kimi_k3_kda_fla_parity.py           |   21 +-
 tests/gpu/test_kimi_k3_kda_fused_decode_parity.py  |  160 +
 tests/gpu/test_kimi_k3_kda_head_parallel_parity.py |  273 ++
 tests/gpu/test_kimi_linear_latent_moe_serving.py   |    4 +-
 .../test_kimi_linear_mxfp4_latent_moe_serving.py   |  495 ++
 tests/gpu/verify_k3_mxfp4_expert.py                |   52 +-
 .../paged_kv/test_host_kv_copy_stream_ordering.py  |  194 +
 tests/kimi_k3_harness.py                           |  118 +-
 tests/kimi_k3_oracle_assets/__init__.py            |    5 +-
 .../test_block_residual_segment_capture.py         |  308 ++
 tests/kimi_linear/test_conv1d_layout_cpu.py        |   12 +-
 tests/kimi_linear/test_conv1d_std.py               |   12 +-
 tests/kimi_linear/test_decode_graph_adapter.py     |   28 +-
 tests/kimi_linear/test_fused_moe_std.py            |   12 +-
 tests/kimi_linear/test_kda_manager_graphready.py   |   12 +-
 tests/kimi_linear/test_kda_segment_capture.py      |   14 +-
 tests/moe/gpu_parity_mxfp4_marlin.py               |   27 +-
 tests/moe/test_mxfp4_marlin_repack.py              |    2 +-
 tests/test_batch_scheduler_pool_failure.py         |   48 +
 tests/test_batchgen_model_config.py                |    5 +-
 tests/test_core_signal_handler_source.py           |   18 +
 tests/test_decode_host_kv_stream_order.py          |  183 +
 tests/test_dsa_valid_token_kernels.py              |   21 -
 tests/test_glm5_planner.py                         |   17 -
 tests/test_gpu_page_table_stability.py             |   23 +
 tests/test_grouped_fp8_blockwise_moe.py            |   28 -
 tests/test_jit_extension_name_uniqueness.py        |   52 +
 tests/test_kimi_k3_block_residual_prealloc.py      |  189 +-
 tests/test_kimi_k3_deepep_ll_graph.py              |  299 ++
 tests/test_kimi_k3_distributed_weight_config.py    |  260 ++
 tests/test_kimi_k3_empty_decode_batch_view.py      |  130 +
 tests/test_kimi_k3_empty_rank_whole_graph.py       |   56 +
 tests/test_kimi_k3_gpu_kv_compaction.py            |  124 +
 tests/test_kimi_k3_kda_scratch_reservation.py      |   27 +
 tests/test_kimi_k3_kda_segmented.py                |   40 +-
 tests/test_kimi_k3_kda_slot_planner.py             |  248 +
 tests/test_kimi_k3_model.py                        |    2 +-
 tests/test_kimi_k3_prefill_offload_tracking.py     |  131 +
 tests/test_kimi_k3_prefill_profile_scope.py        |   70 +
 tests/test_kimi_k3_resident_prefill_control.py     | 4831 ++++++++++++++++++++
 tests/test_kimi_k3_resident_prefill_handoff.py     |  264 ++
 tests/test_kimi_k3_row_gather_triton.py            |   24 +
 tests/test_kimi_k3_server_startup_init.py          |  930 ++++
 tests/test_kimi_k3_situ_triton.py                  |   49 +
 tests/test_kimi_k3_tensor_map.py                   |    9 +-
 tests/test_kimi_k3_tokenizer.py                    |    6 +-
 tests/test_kimi_k3_vocab_parallel.py               |   65 +
 tests/test_kimi_linear_block_residual_serving.py   |   55 +-
 tests/test_kimi_linear_ffn_chunk.py                |   82 +-
 .../test_kimi_linear_flashmla_metadata_contract.py |  106 +
 tests/test_kimi_linear_kda_projection_fusion.py    |   93 +
 tests/test_kimi_linear_m2a_alog_head_shard.py      |   95 +
 tests/test_kimi_linear_m2b_boundary_validator.py   |  191 +
 tests/test_kimi_linear_m2b_decode_dp_group.py      |  493 ++
 tests/test_kimi_linear_m2b_moe_scatter_gather.py   |  266 ++
 tests/test_kimi_linear_moe_cuda_graph_contract.py  |  897 ++++
 tests/test_kimi_linear_rmsnorm_chunk.py            |   57 +
 tests/test_kimi_linear_shared_expert_tp.py         |  125 +
 tests/test_pool_output_parsing.py                  |   96 +
 tests/test_resident_ep_latent_tp_layout.py         |  110 +
 tests/test_server_args.py                          |   90 +
 tests/test_server_worker_readiness.py              |   53 +
 tests/test_worker_fatal_propagation.py             |  182 +
 tests/test_worker_host_kv_append_completion.py     |   47 +
 tests/unit/test_query_book_pool_grow_rebind.py     |  272 --
 tests/worker/test_boundary.py                      |   63 +-
 tests/worker/test_decode.py                        |   43 +-
 tests/worker/test_kv_manager.py                    |   14 +
 tests/worker/test_prefill.py                       |  135 +-

Kernel tests were moved out of the runtime package into top-level tests/kimi_linear/ (matches vLLM/SGLang; not shipped in the wheel).

Checklist

  • Read CONTRIBUTING + PR Merge Policy.
  • Tests: K3 unit/gpu/kernel tests under tests/ (runtime tests to run on the H200 pods — dev-machine is CPU-only).
  • Docs: MODULE.md updated; README News/Roadmap is a separate docs PR.

PR Merge Policy Contract — pre-merge checklist

  • Diff reviewed vs base; every file is model/kernel/test (§3.1).
  • Exactly one Type (model); all files within the model allowlist — no scaffolding edits (§2.5/2.6).
  • File-changes list matches the diff (above).
  • No debug_*/scratch_*/tmp_* scripts (§1.1).
  • §1.2 fixed — the 7 kimi_linear kernel tests relocated from batchgen_kernels/tests/ to top-level tests/kimi_linear/; no test_*.py inside the runtime package.
  • §1.3 — deferred (POIS-approved): BATCHGEN_KIMI_ATTENTION_GROUP_SIZE (kimi_initializer.py) + BATCHGEN_SKIP_KV_CALLBACK (wrappers.py) kept for the interim release; documented in batchgen_design/model_support/kimi_k3/ENV_KNOBS.md (→ server-arg / batchgen_debug next pass). CI hygiene is report-only.
  • No leftover print() / commented-out code in changed non-test files (§1.4–1.5).
  • No logs/traces/checkpoints/wheels staged (§1.6).
  • MODULE.md updated (§2.2).
  • One concern (K3 model+kernels); surgical (§3).
  • Commit trailers clean per §4.
  • CI green — to confirm.

…els + tests

Model-layer slice on top of the core PR (PR_MERGE_POLICY: models/** + batchgen_kernels/** + tests/**):
- models/moonshotai/kimi_linear/** + kimi_k3/**: whole-model decode graph, MoE graph segments,
  DeepEP exchange wiring + planner (--k3-moe-exchange honoring), PSM prewarm, Triton kernels
  (situ, row_gather, rmsnorm int64, kda_conv, attn_residual), vocab_parallel, distributed_weight_store,
  tp_weight_sharding, moe_tp_reshard, k3/mxfp4_{expert,layout}, tensor_map, tokenizer.
- batchgen_kernels/**: grouped mxfp4/int4 wgmma, marlin_grouped_gemm, kda_fused_decode, qkv_wgmma,
  dispatch_scatter_3d, routing gate_sigmoid_topk, JIT registry.
- tests/**: kimi_linear/kimi_k3 unit + gpu + worker + moe (2 stale tests removed).
Excludes GLM-5 (models/glm/glm5/*) — separate effort.
…top-level tests/ (matches vLLM/SGLang; drops from wheel; clears §1.2)
…/ with K3 content (remove in-package duplicates; clears §1.2)
@Andrewxu313
Andrewxu313 deleted the branch k3-core-pr September 11, 2026 12:08
@Andrewxu313
Andrewxu313 deleted the k3-model-pr branch September 11, 2026 12:08
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