Kimi K2: Open Agentic Intelligence
Paper: arXiv:2507.20534 Code: MoonshotAI/Kimi-K2 Code reference:
main@1b4022bb(2025-10-31) Related code: MoonshotAI/checkpoint-engine,main@b8516e34(2026-02-28)
1. Motivation (研究动机)
Kimi K2 要解决的不是单一 benchmark 的刷分问题,而是“开放权重 LLM 如何从静态模仿模型转成能在环境中感知、规划、调用工具、执行并修正错误的 agentic 模型”。论文把核心瓶颈拆成两条线:第一,pre-training 阶段高质量 token 供给越来越稀缺,继续扩大训练量如果只是重复自然语料,会迅速碰到 token utility 和过拟合问题;第二,post-training 阶段真正的 agentic 行为——多步工具调用、长期规划、环境反馈、失败恢复、软件工程任务——在自然数据中很稀有,靠人工标注很难规模化覆盖。
这篇报告的动机可以理解为三个“规模化约束”的交集。其一是优化器与稳定性约束:Kimi K2 是 1.04T total / 32B activated 的超稀疏 MoE;作者希望使用 token-efficient 的 Muon optimizer,但 Muon 在放大到 MoE 规模时更容易出现 attention logits 爆炸,导致 loss spike 或 divergence。其二是数据约束:高质量知识、数学、代码、工具使用数据都不是无限的;论文需要证明合成重写、合成工具库和真实 sandbox 能在不明显损害 factuality 的情况下提高每个 token 的学习价值。其三是系统约束:如果 post-training 要在 1T MoE 上做 on-policy RL 和多轮 agentic rollout,那么训练引擎、推理引擎、checkpoint engine、环境执行服务必须在可接受的切换时间内协同,否则 RL 的样本效率会被系统开销吃掉。
Figure 1 解读:这张主结果图把 Kimi K2 的定位说得很清楚:作者强调的是 non-thinking setting 下的 agentic、coding、tool-use、math/STEM 综合能力,而不是依赖长链推理或 test-time compute 的 reasoning model。图中 SWE-bench Verified、SWE-bench Multilingual、LiveCodeBench v6、OJBench、Tau2-bench、ACEBench、AIME 2025、GPQA-Diamond 八个维度覆盖真实代码修复、竞赛编程、多轮工具调用、数学与科学问答;Kimi-K2-Instruct 在多个开放模型对比中领先,并在部分任务上逼近 Claude/GPT/Gemini 的 non-thinking API。
为什么这个问题值得研究?因为 agentic intelligence 的上限不只取决于模型会不会回答问题,还取决于模型能否把任务拆解成可执行动作、在工具反馈中持续校正、在长上下文中维持状态,并在软件工程等有客观验证信号的任务中闭环学习。开放权重模型如果能在这个方向上接近闭源 frontier model,就能降低 agentic application 的部署门槛,让研究者直接研究 MoE pre-training、tool calling、RL infrastructure、安全与可控性,而不是只能通过黑盒 API 观察行为。
2. Idea (核心思想)
Kimi K2 的核心思想是:把“agentic model”看成一个 pre-training efficiency、synthetic interaction data、large-scale RL system 三者共同决定的工程—算法闭环,而不是只在 SFT 阶段加入工具调用样例。它先用 MuonClip 稳住 1T MoE 的 token-efficient pre-training,再用结构化合成工具库和真实执行环境生成 agentic trajectories,最后用 verifiable rewards + self-critique rubric reward 的 joint RL 把可验证任务中的能力迁移到更主观、更开放的任务。
与 DeepSeek-V3 这类以 MoE 架构和高效训练为主线的 technical report 相比,Kimi K2 的差异在于:它保留 MLA + ultra-sparse MoE 的大模型架构优势,但把训练目标明确转向 tool-use / software engineering / agentic rollout。与只靠 SFT tool traces 的方法相比,K2 不把工具调用当成静态格式模仿,而是构造了 tool repository、agent/task/rubric、trajectory generator、tool simulator/real sandbox,再通过 RL 和 self-critic 对多域行为做进一步优化。
更具体地说,论文的创新不是某一个孤立模块,而是四个互相支撑的设计:
- MuonClip:在 Muon 更新后按 attention head 对 Q/K 投影做 clipping,用很小的干预约束 ,换取 15.5T token pre-training 的零 loss spike。
- Token utility 数据增强:用知识重写、数学 learning-note 重写和跨语言翻译等方法提高高质量语料利用率,避免简单 multi-epoch 重复。
- Agentic synthetic data + real execution:用 3000+ real MCP tools 和 20,000+ synthetic tools 构造工具空间,再生成 agents、tasks、rubrics、trajectories,并用 LLM judge 和真实 sandbox 过滤。
- General RL:将 verifiable rewards、self-critique rubric reward、budget control、PTX loss、temperature decay、colocated RL infrastructure 合并,兼顾客观任务、主观偏好、长度成本和系统吞吐。
3. Method (方法)
3.1 Overall framework:从 stable pre-training 到 agentic post-training
Kimi K2 的整体 pipeline 可以按三层理解。底层是 MoE pre-training:模型采用 61 层 ultra-sparse MoE Transformer,MLA attention,384 routed experts,每 token 激活 8 个 experts;训练 15.5T tokens 后再做 annealing 和 long-context activation,把上下文扩展到 128K。中层是 agentic SFT data construction:模型先通过 instruction tuning 获得高质量回答和工具调用格式,再通过大规模工具合成 pipeline 学习多步工具使用。上层是 RL and system loop:模型在 verifiable tasks、subjective preference tasks、coding/software engineering sandboxes 中 roll out,训练端和推理端通过 checkpoint engine 更新参数,形成 on-policy learning。
这套设计的直觉是:agentic 能力需要模型同时具备“知道什么”“怎么调用”“如何从反馈中调整”三类能力。Pre-training 解决广义知识和代码/数学 priors;SFT 给出工具调用的语法、交互模式和成功轨迹;RL 用真实或可模拟环境反馈修正模型策略。单独强化任何一层都会有短板:没有稳定 pre-training,1T MoE 无法可靠收敛;没有高覆盖工具数据,模型只能在少数 API 上模仿;没有 RL 和系统支持,模型难以从失败执行中持续提升。
3.2 MuonClip:用 QK-Clip 控制 attention logits 爆炸
论文首先指出 Muon 在 token efficiency 上优于 AdamW,但在大规模 MoE 上更容易让 attention logits 爆炸。给定输入表示 ,第 个 attention head 的投影为: 对应输出为: 作者定义 batch 内第 个 head 的 max logit: 当 时,QK-Clip 令 ,然后在 Muon optimizer step 之后缩放 Q/K 相关权重。普通 MHA 可以直接缩放 和 ;Kimi K2 使用 MLA,因此只动 unshared head components: 与 各乘 , 乘 ,共享 rotary key 不动,避免对多个 head 产生耦合影响。
Figure 2 解读:左图展示 mid-scale MoE 使用 vanilla Muon 时 max attention logits 很快超过 1000,说明不加约束会出现数值不稳定风险;右图展示 Kimi K2 用 MuonClip 和 后,max logits 初期被压在 100 附近,训练约 30% 进度后自然回落到稳定区间。这个现象支持作者的“minimal intervention”观点:QK-Clip 不是永久改变 attention 行为,而是在最危险的早期阶段防止权重谱范数放大造成 logits 爆炸。
Figure 3 解读:训练 loss curve 没有 smoothing 或 sub-sampling,论文强调整段 pre-training 未出现 loss spike。对于 1T MoE,这个结果是 MuonClip 方法成立的关键证据:如果 optimizer 只提升 token efficiency 但引入频繁 instability,系统成本和 checkpoint recovery 会抵消收益;K2 的曲线说明 QK-Clip 足以把 Muon 放大到 trillion-parameter sparse setting。
论文附录进一步解释为什么 Muon 更容易触发 logit explosion:Muon 的 msign / Newton-Schulz 更新具有更高 effective rank,更新矩阵的 singular values 更均匀;Adam 的更新谱更偏低秩。若 或 的 spectral norm 增长,由于 attention logits 含有 的双线性项,谱范数增长会被乘法放大。因此 QK-Clip 直接约束 Q/K 权重,比只在 softmax 前做 logit soft-cap 更贴近根因。
Figure 11 解读:附录中的小规模 ablation 使用 0.5B activated / 3B total MoE,并把 threshold 设到较激进的 ;loss 曲线几乎不受影响。这说明 QK-Clip 的主要功能是限制异常 head,而不是给所有 attention heads 增加强正则。论文还报告 K2 初始 70,000 steps 中有 12.7% heads 至少触发过 QK-Clip,之后所有 heads 都曾降到 ,因此 QK-Clip 后期自动失效。
import torch
@torch.no_grad()
def muonclip_step(params, grads, state, lr, weight_decay=0.1, momentum=0.95, tau=100.0):
"""Paper-faithful pseudocode for MuonClip; training implementation is not released."""
for W, G in zip(params.matrix_weights, grads.matrix_grads):
M = state.momentum.setdefault(W, torch.zeros_like(W))
M.mul_(momentum).add_(G)
O = newton_schulz_orthogonalize(M) * (max(W.shape) ** 0.5) * 0.2
W.add_(O + weight_decay * W, alpha=-lr)
for layer in params.attention_layers:
for h, s_max in enumerate(layer.cached_max_logits_per_head):
if s_max <= tau:
continue
gamma = tau / float(s_max)
layer.W_qc[h].mul_(gamma ** 0.5)
layer.W_kc[h].mul_(gamma ** 0.5)
layer.W_qr[h].mul_(gamma)
# W_kr is shared in MLA, so Kimi K2 leaves it untouched.3.3 Pre-training data:用 rephrasing 提高 token utility
Kimi K2 的 pre-training corpus 是 15.5T curated high-quality tokens,覆盖 Web Text、Code、Mathematics、Knowledge 四类。多数清洗流程沿用 Kimi K1.5,但 K2 额外强调 synthetic data generation,以提高 token utility。知识数据的核心问题是:单 epoch 可能吸收不充分,简单重复多 epoch 又容易收益递减和过拟合;因此作者用多风格、多视角 prompt 生成 faithful rephrasing,再做 chunk-wise autoregressive rewriting,最后通过 fidelity verification 检查语义一致性。
Figure 4 解读:长文档先被切成 chunks,每个 chunk 在保留上下文的条件下顺序改写,最后拼接成完整 rewritten passage。这个设计主要解决 LLM 重写长文本时的输出长度限制和全局 coherence 问题;如果直接对长文档一次性重写,后半段信息容易被压缩或丢失。论文的 SimpleQA 实验显示:raw wiki-text 重复 10 epochs 得到 23.76 accuracy;1 次 rephrasing 再重复 10 epochs 为 27.39;10 次 rephrasing 且每个只训练 1 epoch 为 28.94。该表明多样化重写比简单重复更能提升知识吸收。
数学数据方面,作者将高质量数学文档改写成 learning-note style,并把其他语言的数学材料翻译到 English 以增加多样性。论文也明确承认 synthetic data 的继续扩展仍有风险,包括跨域泛化、factual accuracy、hallucination、toxicity 和大规模生产的一致性,因此没有把 rephrasing 描述成万能数据扩容手段。
def rephrase_long_document(document, rewriter, verifier, chunk_size=2048):
"""Paper-derived pseudocode for K2 knowledge rephrasing pipeline."""
rewritten_chunks, context = [], ""
for chunk in split_into_chunks(document, chunk_size):
prompt = build_diverse_rewrite_prompt(chunk, context=context)
candidate = rewriter.generate(prompt)
if verifier.semantic_match(source=chunk, rewrite=candidate):
rewritten_chunks.append(candidate)
context = update_context(context, source=chunk, rewrite=candidate)
else:
rewritten_chunks.append(chunk)
return concatenate(rewritten_chunks)3.4 Model architecture:更稀疏的 1T MoE 与更少 attention heads
Kimi K2 是 1.04T total parameters、32.6B activated parameters 的 MoE Transformer。与 DeepSeek-V3 的 671B total / 37B activated 相比,K2 增加总专家数但减少 active compute;二者都是 61 layers、每 token active experts=8、shared experts=1。K2 的关键参数包括 hidden dimension 7168、expert hidden dimension 2048、384 total experts、64 attention heads、1 dense layer。
HuggingFace moonshotai/Kimi-K2-Instruct 的 config.json 与论文基本一致:model_type="kimi_k2"、architectures=["DeepseekV3ForCausalLM"]、num_hidden_layers=61、hidden_size=7168、moe_intermediate_size=2048、n_routed_experts=384、num_experts_per_tok=8、num_attention_heads=64、vocab_size=163840、max_position_embeddings=131072、rope_scaling.type="yarn" 且 original_max_position_embeddings=4096。
| Architecture item | DeepSeek-V3 | Kimi K2 | 设计含义 |
|---|---|---|---|
| Layers | 61 | 61 | 深度不变,方便控制变量 |
| Total Parameters | 671B | 1.04T | 总容量增加 54% |
| Activated Parameters | 37B | 32.6B | 每 token compute 降低约 13% |
| Experts total | 256 | 384 | 稀疏度更高 |
| Experts active / token | 8 | 8 | active routing 成本保持 |
| Attention heads | 128 | 64 | 长上下文 inference FLOPs 降低 |
| Dense layers | 3 | 1 | 更多层交给 sparse MoE |
| Expert grouping | Yes | No | 简化 expert routing / system constraints |
Figure 5 解读:左侧 sparsity scaling law 固定 active experts=8 和 shared experts=1,只增加 total experts;结果显示更高 sparsity 在相同 activated FLOPs 下能降低 training/validation loss。论文给出一个具体结论:在达到 validation loss 1.5 时,sparsity 48 相比 sparsity 8、16、32 分别减少 1.69×、1.39×、1.15× FLOPs。右侧 attention head 对比说明,把 heads 从 64 加到 128 只带来约 0.5%–1.2% validation loss 改善,但 128K sequence length 下 FLOPs 会增加 83%,所以 K2 选择 64 heads。
3.5 Training infrastructure 与 recipe
Kimi K2 在 NVIDIA H800 cluster 上训练,每个节点 8 GPUs,节点内 NVLink/NVSwitch,节点间 Gbps RoCE。并行策略是 16-way Pipeline Parallelism with virtual stages、16-way Expert Parallelism、ZeRO-1 Data Parallelism。BF16 参数和 FP32 gradient accumulation buffer 在 256-GPU model-parallel group 上约需 6 TB GPU memory;大资源场景分布 optimizer states,小资源场景可 CPU offload。作者强调固定并行配置的研究效率:同一套 parallelism 可复用于小规模和大规模实验,每 GPU 保留约 30 GB 存放 states,其余用于 activations。
Figure 6 解读:这张图展示 PP phases 中 computation、communication、offloading 的 overlap。K2 没有采用 DualPipe,因为它会让 parameters/gradients memory 翻倍,并迫使 parallelism 进一步增加;作者改用 interleaved 1F1B,通过增加 warm-up micro-batches overlap EP all-to-all 与 computation,同时把 weight-gradient computation 从每个 micro-batch 的 backward pass 中解耦出来,与 PP communication 并行。Activation reduction 则包括 selective recomputation、FP8-E4M3 storage for selected insensitive activations、CPU offload 和 copy engine 预取。
Training recipe 的数字来自论文报告而非公开 launch script;公开 MoonshotAI/Kimi-K2 repo 未发布 pre-training launcher 或 optimizer config。主 pre-training 使用 4,096-token context window、MuonClip、WSD learning rate schedule、15.5T tokens。前 10T tokens 在 500-step warmup 后使用 constant LR ;后 5.5T tokens cosine decay 到 ;weight decay=0.1;global batch size=67M tokens。末尾 annealing + long-context activation 阶段继续保持 67M token batch,LR 从 decay 到 ,先用 4K sequence length 训练 400B tokens,再用 32K sequence length 训练 60B tokens,最后用 YaRN 扩展到 128K context。
3.6 Agentic data synthesis:工具库、agent/task、trajectory 三阶段
K2 的 SFT 不只收集普通 instruction data,还专门构造 agentic tool-use 数据。合成 pipeline 有三步:先构造 tool specs repository,再为 sampled tool-set 生成 agent 和 task,最后生成可调用工具的 trajectories。工具来源分两类:一是直接从 GitHub 获取 3000+ real MCP tools;二是按 hierarchical domain evolution 生成 synthetic tools,先定义 financial trading、software applications、robot control 等大类,再扩展具体应用域和工具接口,最终得到 20,000+ synthetic tools。
Figure 7 解读:左侧展示 tool specs、agents、tasks 的生成:工具既来自真实 MCP,也来自 LLM 合成;agent 和 task 是围绕 tool-set 组合生成的。右侧展示 trajectory 生成与过滤:user simulator、agent、tool execution environment、judge 组成多智能体流程,轨迹需要满足 rubric 才进入训练。这个设计的关键是把“工具调用”从静态函数名预测变成带状态反馈的多轮任务完成过程。
Figure 8 解读:两张 t-SNE 图分别显示 real MCP tools 和 synthetic tools 的 embedding 分布。真实 MCP tools 按原始 source category 自然聚类,synthetic tools 按预定义 domain category 系统覆盖;二者互补,前者提供真实生态接口,后者补足长尾领域和可控任务结构。论文希望通过这种覆盖方式避免模型只学会少量常见 API,而无法泛化到 unfamiliar tools。
在 trajectory 阶段,user simulation 生成不同沟通风格和偏好的用户;tool simulator 作为近似 world model 执行 tool calls、维护状态并返回 successes、partial failures、edge cases 等多样反馈;LLM judge 根据 task rubric 做质量过滤。对于 coding/software engineering,作者不只依赖模拟器,还使用真实 execution sandboxes,运行真实代码和 unit tests,从 test pass rate 等 objective metrics 获得更可信反馈。这一点直接对应 K2 在 SWE-bench、TerminalBench、PaperBench 等任务上的目标能力。
def synthesize_tool_use_data(real_mcp_tools, domain_seed, llm, judge, sandbox):
"""Paper-derived pseudocode for K2 agentic data synthesis."""
tool_repo = list(real_mcp_tools)
for domain in evolve_domains(domain_seed):
tool_repo.extend(llm.generate_tool_specs(domain))
accepted = []
for tool_set in sample_tool_sets(tool_repo):
agent = llm.generate_agent_profile(tool_set)
for task in llm.generate_tasks(agent, tool_set):
rubric = llm.generate_success_rubric(task, tool_set)
trajectory = rollout_with_user_and_tools(agent, task, sandbox)
if judge.satisfies(trajectory, rubric):
accepted.append((agent, tool_set, task, rubric, trajectory))
return accepted3.7 Post-training RL:verifiable rewards + self-critique rubric reward
K2 的 RL 目标沿用 K1.5 的 policy optimization 形式。对问题 ,从旧策略 采样 个回答 ,优化: 其中 , 是稳定学习的 regularization parameter。这个目标可以看作把 centered reward 与 policy log-ratio regularization 融合成 squared residual,既推动高 reward samples,也抑制策略偏移。
Verifiable rewards gym 覆盖 Math/STEM/logic、complex instruction following、faithfulness、coding/software engineering、safety 等。Math/STEM 数据通过 expert annotations、internal QA extraction、open datasets 和 tagging system 保证覆盖度;难度用 SFT model pass@k 筛选,避免太简单或太难导致 reward signal 弱。Complex instruction following 使用 code interpreter deterministic verification、LLM-as-judge、hack-check layer 三者结合。Faithfulness 用 sentence-level judge 检查 claims 是否被 context 支持。Coding/software engineering 使用开源和合成问题、human-written unit tests、Kubernetes sandbox,并支持 10,000+ concurrent sandbox instances。
Self-Critique Rubric Reward 用于非完全可验证任务。K2 actor 先对一般 prompts 生成多候选,K2 critic 再基于 core rubrics、prescriptive rubrics、human-annotated rubrics 做 pairwise ranking。critic 的能力在 SFT 阶段用开源和内部 preference datasets 初始化;在 RL 过程中,verifiable prompts 的 on-policy rollouts 继续校准 critic,使客观任务中的改进可以迁移到 creative writing、open-ended QA、complex reasoning 等主观任务。附录也指出该框架可能偏好 confident / assertive responses,在复杂开放问题上可能不够鼓励 calibrated uncertainty。
def k2_rl_step(policy, old_policy, critic, prompts, optimizer, tau, max_budget_by_task):
"""Paper-derived pseudocode for K2 joint RL with verifiable and self-critic rewards."""
losses = []
for x in prompts:
ys = old_policy.sample_k(x, temperature=schedule_temperature())
rewards = []
for y in ys:
if has_verifier(x):
r = verifier_reward(x, y)
else:
r = critic.pairwise_rubric_reward(x, y, ys)
if token_count(y) > max_budget_by_task[x.task_type]:
r -= budget_penalty(y)
rewards.append(r)
mean_r = sum(rewards) / len(rewards)
for y, r in zip(ys, rewards):
log_ratio = policy.logprob(y, x) - old_policy.logprob(y, x)
losses.append((r - mean_r - tau * log_ratio) ** 2)
loss = torch.stack(losses).mean() + ptx_loss(policy, high_quality_replay_batch())
loss.backward()
optimizer.step()
return loss3.8 RL infrastructure:colocated rollout 与 checkpoint engine
K2 使用 hybrid colocated architecture:training engine 和 inference engine 在同一批 workers 上交替占用 GPU。每个 RL iteration 中,centralized controller 先让 inference engine rollout 新数据,再切换到 training engine 更新参数,然后把参数同步回 inference engine。1T MoE 的难点是 engine switching 与 failure recovery;如果每轮都通过 network filesystem reshape / broadcast 参数,带宽需求会达到 petabytes/s 量级,不现实。
Figure 9 解读:checkpoint engine co-located 在 training nodes 上,先从 training engine 获取本地参数,再把完整参数集广播到 checkpoint engine workers;每个 inference engine 只从 checkpoint engine 取自己需要的 shard。论文承认这比理论最优的 transfer-what-you-need 多传几倍数据,但同步开销更小、网络带宽利用率更高、训练和推理引擎耦合更低;K2 完整参数更新可在 30 秒内完成,对典型 RL iteration 来说可以忽略。
Figure 12 解读:附录进一步展示 checkpoint engine 的三阶段和两阶段更新。理论上可以 H2D、Broadcast、Reload 三阶段流水;但 H800 上 H2D 与 broadcast 会饱和 PCIe,因此最终采用更简单的两阶段方案:先同步 H2D,再并行 broadcast 与 reload。公开 MoonshotAI/checkpoint-engine 代码与该描述一致:ParameterServer.update() 调用 _update_per_bucket(),按 bucket 将参数复制到 buffer,使用 dist.broadcast() 分发,并通过 ZMQ/IPC 让 inference worker 调用 update_weights_from_ipc() 加载命名 tensor。
def checkpoint_engine_update(ps, checkpoint_name, files, inference_endpoint):
"""Source-derived pseudocode from MoonshotAI/checkpoint-engine."""
ps.init_process_group()
ps.register_checkpoint(checkpoint_name, files=files, named_tensors={})
ps.gather_metas(checkpoint_name)
def request_inference(socket_paths):
http_post(
inference_endpoint,
json={"method": "update_weights_from_ipc", "args": [dict(socket_paths)]},
)
ps.update(checkpoint_name, request_inference)
def update_weights_from_ipc_worker(ipc_handle, metadata_stream, load_named_weights):
buffer = rebuild_cuda_ipc_buffer(ipc_handle)
for payload in metadata_stream:
if payload is None:
release_cuda_ipc_resources(buffer)
continue
named_tensors = extract_weight_views(payload, buffer)
load_named_weights(named_tensors)3.9 Tool calling released docs 与 paper-code 差异
公开 MoonshotAI/Kimi-K2 repo 主要包含 README、deployment guide、tool calling guide、figures 和 technical report;它没有发布 MuonClip optimizer、pre-training launcher、data synthesis pipeline、SFT/RL trainer 或 model architecture implementation。部署文档说明 Kimi-K2 在 inference engines 中复用 DeepSeekV3CausalLM weight shape,但 config.json 设置 model_type="kimi_k2" 以便框架启用对应优化;若框架不支持,可临时改成 deepseek_v3,但需要手动解析 tool calls。vLLM 需要 --enable-auto-tool-choice --tool-call-parser kimi_k2,SGLang 也需要 --tool-call-parser kimi_k2。
def kimi_k2_tool_loop(client, model_name, messages, tools, tool_map):
"""Source-derived pseudocode from Kimi-K2 README/tool_call_guidance."""
finish_reason = None
while finish_reason is None or finish_reason == "tool_calls":
completion = client.chat.completions.create(
model=model_name,
messages=messages,
tools=tools,
tool_choice="auto",
)
choice = completion.choices[0]
finish_reason = choice.finish_reason
messages.append(choice.message)
if finish_reason == "tool_calls":
for call in choice.message.tool_calls:
name = call.function.name
args = json.loads(call.function.arguments)
result = tool_map[name](**args)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"name": name,
"content": json.dumps(result),
})
return messages[-1]["content"]Code reference:
main@1b4022bb(2025-10-31) forMoonshotAI/Kimi-K2;main@b8516e34(2026-02-28) forMoonshotAI/checkpoint-engine— pseudocode and mapping based on these commits.
| Paper Concept | Source File | Key Class/Function |
|---|---|---|
| Public Kimi K2 model card, benchmark table, HuggingFace links | MoonshotAI/Kimi-K2/README.md | README model summary and tool-call example |
| Deployment parser and model type behavior | MoonshotAI/Kimi-K2/docs/deploy_guidance.md | --tool-call-parser kimi_k2, model_type="kimi_k2", DeepSeekV3CausalLM compatibility note |
| Tool-calling request loop | MoonshotAI/Kimi-K2/docs/tool_call_guidance.md | OpenAI-compatible tools, finish_reason="tool_calls", role=tool message loop |
| Architecture config verification | moonshotai/Kimi-K2-Instruct/config.json on HuggingFace | model_type, n_routed_experts, num_experts_per_tok, YaRN rope_scaling |
| RL parameter update system | MoonshotAI/checkpoint-engine/checkpoint_engine/api.py | _init_api, /v1/checkpoints/{checkpoint_name}/update, request_inference_to_update |
| Bucketed checkpoint broadcast | MoonshotAI/checkpoint-engine/checkpoint_engine/ps.py | ParameterServer.update, _update_per_bucket, _detect_bucket_size, _copy_to_buffer |
| Inference-side IPC weight reload | MoonshotAI/checkpoint-engine/checkpoint_engine/worker.py | update_weights_from_ipc, _extract_weights, VllmColocateWorkerExtension.update_weights_from_ipc |
| Released training code status | public search / repo tree | 代码搜索未找到开源实现:MuonClip optimizer、pre-training config/launcher、agentic data generator、SFT/RL trainer 未在 public Kimi-K2 repo 中发布 |
论文公式与 released code 实现差异:公开 Kimi-K2 repo 没有训练代码,因此不能核对 MuonClip、pre-training schedule、rephrasing pipeline、agentic data synthesis、RL objective 的实现是否逐字等同于论文;笔记中的这些训练伪代码是基于 paper equations/report 的 paper-faithful pseudocode。公开代码能核对的是 tool-calling API loop、deployment parser、HuggingFace config,以及论文提到的 checkpoint engine 更新机制。另一个可观察差异是 HuggingFace config 的 architectures 为 DeepseekV3ForCausalLM,而 model_type 为 kimi_k2;这与部署文档“复用 DeepSeekV3CausalLM 结构但用 kimi_k2 区分优化”的说明一致,不是论文冲突。
4. Experimental Setup (实验设置)
4.1 Models and training settings
Kimi K2 包含 Base 和 Instruct 两个公开模型。Base 是 pre-trained foundation model;Instruct 是 post-trained model,用于 general-purpose chat 和 agentic experiences,论文称其为 reflex-grade non-thinking model。Pre-training 使用 15.5T tokens;main training context window 4,096;global batch size 67M tokens;MuonClip optimizer;
前 10T tokens constant LR ,500-step warmup;后 5.5T tokens cosine decay 到 ;weight decay 0.1;annealing + long-context activation 包含 400B tokens at 4K sequence length 和 60B tokens at 32K sequence length,并通过 YaRN 到 128K context。硬件是 NVIDIA H800 cluster,每节点 8 GPUs、2 TB RAM、NVLink/NVSwitch 和 Gbps RoCE。
Post-training 使用 Muon optimizer。SFT 数据由人类标注、prompt engineering、K1.5 和内部专家模型生成候选回答,再用 LLM 或 human judges 过滤。Agentic data synthesis 使用 3000+ real MCP tools、20,000+ synthetic tools、thousands of agents、rubric-based tasks、tool simulators、real coding sandboxes。RL 数据覆盖 Math/STEM/logical、complex instruction following、faithfulness、coding/software engineering、safety、subjective preference tasks;software engineering sandbox 支持 10,000+ concurrent instances。
4.2 Benchmarks, baselines and metrics
Instruct evaluation 的 coding benchmarks 包括 LiveCodeBench v6(2024-08 到 2025-05 questions)、OJBench、MultiPL-E、SWE-bench Verified、TerminalBench、Multi-SWE-bench、SWE-Lancer、PaperBench、Aider-Polyglot。Tool use 使用 -Bench 和 ACEBench。Reasoning 使用 AIME 2024/2025、MATH-500、HMMT 2025、CNMO 2024、PolyMath-en、ZebraLogic、AutoLogi、GPQA-Diamond、SuperGPQA、Humanity’s Last Exam。Long context 使用 MRCR、DROP、FRAMES、LongBench v2。Factuality 使用 FACTS Grounding、Vectara HHEM v2.1、FaithJudge。General tasks 包括 MMLU、MMLU-Redux、MMLU-Pro、IFEval、Multi-Challenge、SimpleQA、LiveBench、Arena Hard v2.0。
Baselines 分为开源和闭源。Instruct open-source baselines 是 DeepSeek-V3-0324、Qwen3-235B-A22B;proprietary baselines 是 Claude Sonnet 4、Claude Opus 4、GPT-4.1、Gemini 2.5 Flash Preview (2025-05-20)。所有候选都在 non-thinking mode 下评估,以排除额外 test-time compute。输出长度除 SWE-bench Verified Agentless 外均 capped at 8192 tokens;SWE-bench Verified Agentless capped at 16384。Long-context evaluation 使用 128K context window,超长输入截断到窗口内。部分 high-variance benchmarks 使用 Avg@k repeated sampling。
Base evaluation 的 baselines 是 DeepSeek-V3-Base、Qwen2.5-72B-Base、Llama 4-Maverick-Base。General capability 包括 MMLU、MMLU-Pro、MMLU-Redux、BBH、TriviaQA、SuperGPQA、SimpleQA、HellaSwag、AGIEval、GPQA-Diamond、ARC-Challenge、WinoGrande。Coding 使用 EvalPlus、LiveCodeBench v6、CRUXEval。Math 使用 GSM8K、GSM8K-Platinum、MATH、CMATH。Chinese 使用 C-Eval、CMMLU、CSimpleQA。MMLU、MMLU-Redux、GPQA-Diamond、HellaSwag、ARC-Challenge、C-Eval、CMMLU 用 perplexity-based evaluation;其余多为 generation-based evaluation;GPQA-Diamond 报告 8 次均值。
Safety evaluation 使用 Promptfoo 生成 adversarial prompts,比较 Kimi K2、DeepSeek-V3、DeepSeek-R1、Qwen3,覆盖 harmful、criminal、misinformation、privacy、security 等 plugin categories,以及 Basic、Prompt Injection、Iterative Jailbreak、Crescendo 等策略。每个 plugin-strategy 组合生成 3 个 attack prompts;支持中英的组合会生成 6 个 prompts;结果由人工多轮 review,减少主观差异。
5. Experimental Results (实验结果)
5.1 Instruct model:agentic coding 与 tool use 是最强项
Kimi-K2-Instruct 在 coding 和 software engineering 上的主结果很集中:LiveCodeBench v6 Pass@1 为 53.7,高于 DeepSeek-V3-0324 的 46.9、Qwen3-235B-A22B 的 37.0、Claude Sonnet 4 的 48.5、Claude Opus 4 的 47.4、GPT-4.1 的 44.7、Gemini 2.5 Flash 的 44.7。OJBench Pass@1 为 27.1,也高于 DeepSeek 24.0、Qwen 11.3、Claude Sonnet 15.3、Claude Opus 19.6、GPT-4.1 19.5、Gemini 19.5。MultiPL-E Pass@1 为 85.7,是最佳开源结果,但低于 Claude Opus 4 的 89.6 和 Claude Sonnet 4 的 88.6。
在真实软件工程任务上,SWE-bench Verified Agentless-Single-Patch 为 51.8,领先 DeepSeek 36.6、Qwen 39.4、Claude Sonnet 50.2、GPT-4.1 40.8、Gemini 32.6,但略低于 Claude Opus 53.0。Agentic-Single-Attempt Pass@1 为 65.8,领先 DeepSeek 38.8、Qwen 34.4、GPT-4.1 54.6,但低于 Claude Sonnet 72.7 和 Claude Opus 72.5。Agentic-Multi-Attempt 为 71.6,低于 Claude Sonnet 80.2 和 Claude Opus 79.4。SWE-bench Multilingual 为 47.3,接近 Claude Sonnet 51.0,并高于 GPT-4.1 31.5。SWE-Lancer 为 39.1,接近 Claude Sonnet 40.8,高于 GPT-4.1 23.0 和 Gemini 38.5。PaperBench Code-Dev 为 27.8,接近 GPT-4.1 29.9,远高于 DeepSeek 12.2 和 Qwen 13.2。
Tool use 方面,Kimi-K2-Instruct 在 -Bench micro Pass@1 平均为 66.1;分项为 retail 70.6、airline 56.5、telecom 65.8。对比 DeepSeek-V3-0324 的 retail 69.1、airline 39.0、telecom 32.5,以及 Qwen3 的 57.0、26.5、22.1,K2 的优势主要来自 airline/telecom 这类多轮约束更强的场景。ACEBench overall 为 76.5,领先 DeepSeek 72.7、Qwen 70.5、Claude Sonnet 76.2、Claude Opus 75.6、Gemini 74.5,但低于 GPT-4.1 的 80.1。
5.2 Math、STEM、general、long-context 与 factuality
Math/STEM 中,K2 的 AIME 2024 Avg@64 为 69.6,高于 DeepSeek 59.4、Qwen 40.1、Claude Sonnet 43.4、Claude Opus 48.2、GPT-4.1 46.5、Gemini 61.3。AIME 2025 为 49.5,高于 DeepSeek 46.7、Qwen 24.7、Claude Sonnet 33.1、Claude Opus 33.9、GPT-4.1 37.0、Gemini 46.6。MATH-500 为 97.4,GPQA-Diamond Avg@8 为 75.1,SuperGPQA 为 57.2;这些结果说明 K2 作为 non-thinking model 在数学和科学问答上也处于强开源水平。逻辑任务中 ZebraLogic 为 89.0,AutoLogi 为 89.5,均明显高于 Qwen3 的 37.7 / 83.3。
General tasks 中,K2 的 MMLU 为 89.5、MMLU-Redux 为 92.7、MMLU-Pro 为 81.1、IFEval Prompt Strict 为 89.8、Multi-Challenge 为 54.1、SimpleQA Correct 为 31.0、LiveBench 为 76.4。IFEval 和 Multi-Challenge 特别支持论文的 instruction following 结论:K2 在复杂多轮、冲突约束和指令严格遵循上明显强于 DeepSeek 的 81.1 / 31.4 和 GPT-4.1 的 88.0 / 36.4。SimpleQA 虽然优于 DeepSeek 27.7 和 Qwen 13.2,但低于 GPT-4.1 的 42.3,说明 factual short-answer 仍有闭源差距。
Long-context/factuality 结果比较混合。FACTS Grounding adjusted 为 88.5,明显高于 DeepSeek 68.3、Qwen 68.5、Claude Sonnet 83.6、GPT-4.1 79.2、Gemini 86.6。HHEM v2.1 的 1-Hallucination 为 98.9,FaithJudge 1-Hallucination 为 92.6。Long-context retrieval MRCR 为 55.0,领先 DeepSeek 50.8,但远低于 Claude Sonnet 74.4、GPT-4.1 66.9、Gemini 81.7。FRAMES 为 77.1,略低于 DeepSeek 79.2 和 GPT-4.1 87.4;LongBench v2 为 49.1,低于 DeepSeek 51.1、Claude Sonnet 52.5、GPT-4.1 54.3、Gemini 55.5。也就是说,K2 在 factual grounding 和 DROP 上很强,但长上下文复杂推理不是绝对领先项。
Figure 10 解读:中文 in-house benchmark 展示 Kimi-K2-Instruct 对 ChatGPT-4o-latest、Claude Sonnet 4、DeepSeek-V3-0324 的 open-ended 对比。论文报告胜率分别为 65.4%、64.6%、59.6%,loss rate 约 17%。这说明 post-training 对中文开放任务有明显增益;不过该 benchmark 是内部 held-out 数据,访问受限,因此外部可复核性弱于公开 benchmark。
5.3 Base model:pre-training 本身已经很强
Kimi-K2-Base 与 open-source base models 的对比显示,K2 的 pre-training 不是只靠 post-training 包装。Base architecture 行中,K2 是 MoE、32B activated、1043B total;DeepSeek-V3-Base 是 37B activated、671B total;Llama4-Maverick-Base 是 17B activated、400B total;Qwen2.5-72B-Base 是 dense 72B。English tasks 中 K2 在 MMLU 87.79、MMLU-Pro 69.17、MMLU-Redux 90.17、SuperGPQA 44.67、SimpleQA 35.25、TriviaQA 85.09、BBH 88.71、AGIEval 84.23、ARC-Challenge 95.73、WinoGrande 85.32 上领先;GPQA-Diamond 48.11 低于 DeepSeek 50.51;HellaSwag 94.60 低于 Qwen2.5 的 95.27。
Code base eval 中,K2 在 CRUXEval-I-cot 74.00、CRUXEval-O-cot 83.50、LiveCodeBench v6 26.29、EvalPlus 80.33 全部领先。Math 中,K2 的 MATH 70.22、GSM8K 92.12、GSM8K-Platinum 94.21 领先,CMATH 90.26 略低于 DeepSeek 90.53。Chinese 中,C-Eval 92.50、CMMLU 90.90、CSimpleQA 77.57 均领先。这些结果与 architecture scaling law 相互支撑:更高 total capacity 与更高 sparsity 没有牺牲 activated compute 下的综合能力。
5.4 Ablations and component evidence
论文最明确的 ablation 是 QK-Clip harmlessness 与 data rephrasing。QK-Clip 在 0.5B activated / 3B total MoE 的 setting 下没有显著损害 loss,且 K2 主训练中 max logits 后期自然回落,说明它更像 early-stage stability guard。Data rephrasing 的 SimpleQA ablation 则量化了 token utility:0 rephrasing + 10 epochs 是 23.76,1 rephrasing + 10 epochs 是 27.39,10 rephrasings + 1 epoch 是 28.94。Architecture scaling law 也给了定量结论:sparsity 48 达到相同 validation loss 1.5 时,相比 sparsity 8 / 16 / 32 分别减少 1.69× / 1.39× / 1.15× FLOPs;attention heads 翻倍只带来 0.5%–1.2% validation loss 改善,但 128K context 下增加 83% inference FLOPs。
这些证据共同说明每个组件的角色:MuonClip 让 token-efficient optimizer 可扩大到 1T MoE;rephrasing 在高质量语料稀缺时提高知识吸收;sparsity scaling 提高 total capacity 而控制 active FLOPs;64 attention heads 是长上下文 inference 代价和 validation loss 的折中;agentic synthesis 和 RL 主要反映在 tool use、SWE、TerminalBench、PaperBench、ACEBench 等任务上。
5.5 Limitations and takeaways
作者在 Limitations 中列出三类问题。第一,hard reasoning 或 tool definition 不清楚时,模型可能生成过多 tokens,导致输出截断或 incomplete tool calls;这与 RL 中必须引入 budget control 的动机一致。第二,如果在某些任务上不必要地启用 tool use,性能可能下降,说明 agentic capability 不是越多越好,工具选择策略本身需要校准。第三,构建完整软件项目时,one-shot prompting 成功率不如把 K2 放进 agentic coding framework,这说明模型能力和 agent framework/环境反馈强绑定。
总体结论是,Kimi K2 的主要贡献在于把开放 MoE LLM 的 pre-training 稳定性、token utility、tool-use data synthesis、general RL、large-scale rollout system 连成了一条可工作的 agentic intelligence 路线。它不是纯架构论文,也不是单纯 benchmark 报告;最有价值的部分是解释了为什么 1T MoE 需要 MuonClip,为什么 agentic data 必须用合成工具库和真实 sandbox 混合,为什么 RL infrastructure 要解决参数更新和长尾 rollout。外部复现的最大缺口是训练代码和数据 pipeline 未发布,因此公开可核对部分主要是模型权重、HuggingFace config、deployment/tool-calling docs 和 checkpoint-engine。