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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: modified-mit
|
| 4 |
+
library_name: transformers
|
| 5 |
+
---
|
| 6 |
+
<div align="center">
|
| 7 |
+
<picture>
|
| 8 |
+
<img src="figures/kimi-logo.png" width="30%" alt="Kimi K2: Open Agentic Intellignece">
|
| 9 |
+
</picture>
|
| 10 |
+
</div>
|
| 11 |
+
<hr>
|
| 12 |
+
|
| 13 |
+
<div align="center" style="line-height:1">
|
| 14 |
+
<a href="https://www.kimi.com" target="_blank"><img alt="Chat" src="https://img.shields.io/badge/🤖%20Chat-Kimi%20K2-ff6b6b?color=1783ff&logoColor=white"/></a>
|
| 15 |
+
<a href="https://github.com/moonshotai/Kimi-K2"><img alt="github" src="https://img.shields.io/badge/🤖%20Github-Kimi%20K2-ff6b6b?color=1783ff&logoColor=white"/></a>
|
| 16 |
+
<a href="https://www.moonshot.ai" target="_blank"><img alt="Homepage" src="https://img.shields.io/badge/Homepage-Moonshot%20AI-white?logo=Kimi&logoColor=white"/></a>
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
<div align="center" style="line-height: 1;">
|
| 20 |
+
<a href="https://huggingface.co/moonshotai" target="_blank"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Moonshot%20AI-ffc107?color=ffc107&logoColor=white"/></a>
|
| 21 |
+
<a href="https://twitter.com/kimi_moonshot" target="_blank"><img alt="Twitter Follow" src="https://img.shields.io/badge/Twitter-Kimi.ai-white?logo=x&logoColor=white"/></a>
|
| 22 |
+
<a href="https://discord.gg/TYU2fdJykW" target="_blank"><img alt="Discord" src="https://img.shields.io/badge/Discord-Kimi.ai-white?logo=discord&logoColor=white"/></a>
|
| 23 |
+
</div>
|
| 24 |
+
<div align="center" style="line-height: 1;">
|
| 25 |
+
<a href="https://huggingface.co/moonshotai/Kimi-K2-Instruct-0905/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Modified_MIT-f5de53?&color=f5de53"/></a>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<p align="center">
|
| 29 |
+
<b>📰 <a href="https://moonshotai.github.io/Kimi-K2/">Tech Blog</a></b> | <b>📄 <a href="https://github.com/MoonshotAI/Kimi-K2/blob/main/tech_report.pdf">Paper</a></b>
|
| 30 |
+
</p>
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
## 1. Model Introduction
|
| 34 |
+
|
| 35 |
+
Kimi K2-Instruct-0905 is the latest, most capable version of Kimi K2. It is a state-of-the-art mixture-of-experts (MoE) language model, featuring 32 billion activated parameters and a total of 1 trillion parameters.
|
| 36 |
+
|
| 37 |
+
### Key Features
|
| 38 |
+
- Enhanced agentic coding intelligence: Kimi K2-Instruct-0905 demonstrates significant improvements in performance on public benchmarks and real-world coding agent tasks.
|
| 39 |
+
- Improved frontend coding experience: Kimi K2-Instruct-0905 offers advancements in both the aesthetics and practicality of frontend programming.
|
| 40 |
+
- Extended context length: Kimi K2-Instruct-0905’s context window has been increased from 128k to 256k tokens, providing better support for long-horizon tasks.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
## 2. Model Summary
|
| 44 |
+
|
| 45 |
+
<div align="center">
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
| | |
|
| 49 |
+
|:---:|:---:|
|
| 50 |
+
| **Architecture** | Mixture-of-Experts (MoE) |
|
| 51 |
+
| **Total Parameters** | 1T |
|
| 52 |
+
| **Activated Parameters** | 32B |
|
| 53 |
+
| **Number of Layers** (Dense layer included) | 61 |
|
| 54 |
+
| **Number of Dense Layers** | 1 |
|
| 55 |
+
| **Attention Hidden Dimension** | 7168 |
|
| 56 |
+
| **MoE Hidden Dimension** (per Expert) | 2048 |
|
| 57 |
+
| **Number of Attention Heads** | 64 |
|
| 58 |
+
| **Number of Experts** | 384 |
|
| 59 |
+
| **Selected Experts per Token** | 8 |
|
| 60 |
+
| **Number of Shared Experts** | 1 |
|
| 61 |
+
| **Vocabulary Size** | 160K |
|
| 62 |
+
| **Context Length** | 256K |
|
| 63 |
+
| **Attention Mechanism** | MLA |
|
| 64 |
+
| **Activation Function** | SwiGLU |
|
| 65 |
+
</div>
|
| 66 |
+
|
| 67 |
+
## 3. Evaluation Results
|
| 68 |
+
|
| 69 |
+
| Benchmark | Metric | K2-Instruct-0905 | K2-Instruct-0711 | Qwen3-Coder-480B-A35B-Instruct | GLM-4.5 | DeepSeek-V3.1 | Claude-Sonnet-4 | Claude-Opus-4 |
|
| 70 |
+
|------------------------|--------|------------------|------------------|--------|--------|--------|-----------------|---------------|
|
| 71 |
+
| SWE-Bench verified | ACC | 69.2 ± 0.63 | 65.8 | 69.6* | 64.2* | 66.0* | 72.7* | 72.5* |
|
| 72 |
+
| SWE-Bench Multilingual | ACC | 55.9 ± 0.72 | 47.3 | 54.7* | 52.7 | 54.5* | 53.3* | - |
|
| 73 |
+
| Multi-SWE-Bench | ACC | 33.5 ± 0.28 | 31.3 | 32.7 | 31.7 | 29.0 | 35.7 | - |
|
| 74 |
+
| Terminal-Bench | ACC | 44.5 ± 2.03 | 37.5 | 37.5* | 39.9* | 31.3* | 36.4* | 43.2* |
|
| 75 |
+
| SWE-Dev | ACC | 66.6 ± 0.72 | 61.9 | 64.7 | 63.2 | 53.3 | 67.1 | - |
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
All K2-Instruct-0905 numbers are reported as mean ± std over five independent, full-test-set runs.
|
| 79 |
+
Before each run we prune the repository so that every Git object unreachable from the target commit disappears; this guarantees the agent sees only the code that would legitimately be available at that point in history.
|
| 80 |
+
|
| 81 |
+
Except for Terminal-Bench (Terminus-2), every result was produced with our in-house evaluation harness. The harness is derived from SWE-agent, but we clamp the context windows of the Bash and Edit tools and rewrite the system prompt to match the task semantics. All baseline figures denoted with an asterisk (*) are excerpted directly from their official report or public leaderboard; the remaining metrics were evaluated by us under conditions identical to those used for K2-Instruct-0905.
|
| 82 |
+
|
| 83 |
+
For SWE-Dev we go one step further: we overwrite the original repository files and delete any test file that exercises the functions the agent is expected to generate, eliminating any indirect hints about the desired implementation.
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
## 4. Deployment
|
| 87 |
+
> [!Note]
|
| 88 |
+
> You can access Kimi K2's API on https://platform.moonshot.ai , we provide OpenAI/Anthropic-compatible API for you.
|
| 89 |
+
>
|
| 90 |
+
> The Anthropic-compatible API maps temperature by `real_temperature = request_temperature * 0.6` for better compatible with existing applications.
|
| 91 |
+
|
| 92 |
+
Our model checkpoints are stored in the block-fp8 format, you can find it on [Huggingface](https://huggingface.co/moonshotai/Kimi-K2-Instruct).
|
| 93 |
+
|
| 94 |
+
Currently, Kimi-K2 is recommended to run on the following inference engines:
|
| 95 |
+
|
| 96 |
+
* vLLM
|
| 97 |
+
* SGLang
|
| 98 |
+
* KTransformers
|
| 99 |
+
* TensorRT-LLM
|
| 100 |
+
|
| 101 |
+
Deployment examples for vLLM and SGLang can be found in the [Model Deployment Guide](docs/deploy_guidance.md).
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## 5. Model Usage
|
| 106 |
+
|
| 107 |
+
### Chat Completion
|
| 108 |
+
|
| 109 |
+
Once the local inference service is up, you can interact with it through the chat endpoint:
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
def simple_chat(client: OpenAI, model_name: str):
|
| 113 |
+
messages = [
|
| 114 |
+
{"role": "system", "content": "You are Kimi, an AI assistant created by Moonshot AI."},
|
| 115 |
+
{"role": "user", "content": [{"type": "text", "text": "Please give a brief self-introduction."}]},
|
| 116 |
+
]
|
| 117 |
+
response = client.chat.completions.create(
|
| 118 |
+
model=model_name,
|
| 119 |
+
messages=messages,
|
| 120 |
+
stream=False,
|
| 121 |
+
temperature=0.6,
|
| 122 |
+
max_tokens=256
|
| 123 |
+
)
|
| 124 |
+
print(response.choices[0].message.content)
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
> [!NOTE]
|
| 128 |
+
> The recommended temperature for Kimi-K2-Instruct-0905 is `temperature = 0.6`.
|
| 129 |
+
> If no special instructions are required, the system prompt above is a good default.
|
| 130 |
+
|
| 131 |
+
---
|
| 132 |
+
|
| 133 |
+
### Tool Calling
|
| 134 |
+
|
| 135 |
+
Kimi-K2-Instruct-0905 has strong tool-calling capabilities.
|
| 136 |
+
To enable them, you need to pass the list of available tools in each request, then the model will autonomously decide when and how to invoke them.
|
| 137 |
+
|
| 138 |
+
The following example demonstrates calling a weather tool end-to-end:
|
| 139 |
+
|
| 140 |
+
```python
|
| 141 |
+
# Your tool implementation
|
| 142 |
+
def get_weather(city: str) -> dict:
|
| 143 |
+
return {"weather": "Sunny"}
|
| 144 |
+
# Tool schema definition
|
| 145 |
+
tools = [{
|
| 146 |
+
"type": "function",
|
| 147 |
+
"function": {
|
| 148 |
+
"name": "get_weather",
|
| 149 |
+
"description": "Retrieve current weather information. Call this when the user asks about the weather.",
|
| 150 |
+
"parameters": {
|
| 151 |
+
"type": "object",
|
| 152 |
+
"required": ["city"],
|
| 153 |
+
"properties": {
|
| 154 |
+
"city": {
|
| 155 |
+
"type": "string",
|
| 156 |
+
"description": "Name of the city"
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
}]
|
| 162 |
+
# Map tool names to their implementations
|
| 163 |
+
tool_map = {
|
| 164 |
+
"get_weather": get_weather
|
| 165 |
+
}
|
| 166 |
+
def tool_call_with_client(client: OpenAI, model_name: str):
|
| 167 |
+
messages = [
|
| 168 |
+
{"role": "system", "content": "You are Kimi, an AI assistant created by Moonshot AI."},
|
| 169 |
+
{"role": "user", "content": "What's the weather like in Beijing today? Use the tool to check."}
|
| 170 |
+
]
|
| 171 |
+
finish_reason = None
|
| 172 |
+
while finish_reason is None or finish_reason == "tool_calls":
|
| 173 |
+
completion = client.chat.completions.create(
|
| 174 |
+
model=model_name,
|
| 175 |
+
messages=messages,
|
| 176 |
+
temperature=0.6,
|
| 177 |
+
tools=tools, # tool list defined above
|
| 178 |
+
tool_choice="auto"
|
| 179 |
+
)
|
| 180 |
+
choice = completion.choices[0]
|
| 181 |
+
finish_reason = choice.finish_reason
|
| 182 |
+
if finish_reason == "tool_calls":
|
| 183 |
+
messages.append(choice.message)
|
| 184 |
+
for tool_call in choice.message.tool_calls:
|
| 185 |
+
tool_call_name = tool_call.function.name
|
| 186 |
+
tool_call_arguments = json.loads(tool_call.function.arguments)
|
| 187 |
+
tool_function = tool_map[tool_call_name]
|
| 188 |
+
tool_result = tool_function(**tool_call_arguments)
|
| 189 |
+
print("tool_result:", tool_result)
|
| 190 |
+
messages.append({
|
| 191 |
+
"role": "tool",
|
| 192 |
+
"tool_call_id": tool_call.id,
|
| 193 |
+
"name": tool_call_name,
|
| 194 |
+
"content": json.dumps(tool_result)
|
| 195 |
+
})
|
| 196 |
+
print("-" * 100)
|
| 197 |
+
print(choice.message.content)
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
The `tool_call_with_client` function implements the pipeline from user query to tool execution.
|
| 201 |
+
This pipeline requires the inference engine to support Kimi-K2’s native tool-parsing logic.
|
| 202 |
+
For more information, see the [Tool Calling Guide](docs/tool_call_guidance.md).
|
| 203 |
+
|
| 204 |
+
---
|
| 205 |
+
|
| 206 |
+
## 6. License
|
| 207 |
+
|
| 208 |
+
Both the code repository and the model weights are released under the [Modified MIT License](LICENSE).
|
| 209 |
+
|
| 210 |
+
---
|
| 211 |
+
|
| 212 |
+
## 7. Third Party Notices
|
| 213 |
+
|
| 214 |
+
See [THIRD PARTY NOTICES](THIRD_PARTY_NOTICES.md)
|
| 215 |
+
|
| 216 |
+
---
|
| 217 |
+
|
| 218 |
+
## 7. Contact Us
|
| 219 |
+
|
| 220 |
+
If you have any questions, please reach out at [support@moonshot.cn](mailto:support@moonshot.cn).
|