volvetech lsw825 commited on
Commit
abb042e
·
verified ·
0 Parent(s):

Duplicate from moonshotai/Kimi-K2-Thinking

Browse files

Co-authored-by: Shaowei Liu <lsw825@users.noreply.huggingface.co>

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +41 -0
  2. LICENSE +27 -0
  3. README.md +281 -0
  4. THIRD_PARTY_NOTICES.md +47 -0
  5. chat_template.jinja +97 -0
  6. config.json +150 -0
  7. configuration_deepseek.py +212 -0
  8. docs/deploy_guidance.md +106 -0
  9. docs/tool_call_guidance.md +258 -0
  10. figures/Base-Evaluation.png +3 -0
  11. figures/banner.png +3 -0
  12. figures/kimi-logo.png +3 -0
  13. generation_config.json +4 -0
  14. model-00001-of-000062.safetensors +3 -0
  15. model-00002-of-000062.safetensors +3 -0
  16. model-00003-of-000062.safetensors +3 -0
  17. model-00004-of-000062.safetensors +3 -0
  18. model-00005-of-000062.safetensors +3 -0
  19. model-00006-of-000062.safetensors +3 -0
  20. model-00007-of-000062.safetensors +3 -0
  21. model-00008-of-000062.safetensors +3 -0
  22. model-00009-of-000062.safetensors +3 -0
  23. model-00010-of-000062.safetensors +3 -0
  24. model-00011-of-000062.safetensors +3 -0
  25. model-00012-of-000062.safetensors +3 -0
  26. model-00013-of-000062.safetensors +3 -0
  27. model-00014-of-000062.safetensors +3 -0
  28. model-00015-of-000062.safetensors +3 -0
  29. model-00016-of-000062.safetensors +3 -0
  30. model-00017-of-000062.safetensors +3 -0
  31. model-00018-of-000062.safetensors +3 -0
  32. model-00019-of-000062.safetensors +3 -0
  33. model-00020-of-000062.safetensors +3 -0
  34. model-00021-of-000062.safetensors +3 -0
  35. model-00022-of-000062.safetensors +3 -0
  36. model-00023-of-000062.safetensors +3 -0
  37. model-00024-of-000062.safetensors +3 -0
  38. model-00025-of-000062.safetensors +3 -0
  39. model-00026-of-000062.safetensors +3 -0
  40. model-00027-of-000062.safetensors +3 -0
  41. model-00028-of-000062.safetensors +3 -0
  42. model-00029-of-000062.safetensors +3 -0
  43. model-00030-of-000062.safetensors +3 -0
  44. model-00031-of-000062.safetensors +3 -0
  45. model-00032-of-000062.safetensors +3 -0
  46. model-00033-of-000062.safetensors +3 -0
  47. model-00034-of-000062.safetensors +3 -0
  48. model-00035-of-000062.safetensors +3 -0
  49. model-00036-of-000062.safetensors +3 -0
  50. model-00037-of-000062.safetensors +3 -0
.gitattributes ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.safetensors.index.json filter=lfs diff=lfs merge=lfs -text
37
+ figures/Base-Evaluation.png filter=lfs diff=lfs merge=lfs -text
38
+ figures/banner.png filter=lfs diff=lfs merge=lfs -text
39
+ figures/kimi-logo.png filter=lfs diff=lfs merge=lfs -text
40
+ figures/* filter=lfs diff=lfs merge=lfs -text
41
+ *.png filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Modified MIT License
2
+
3
+ Copyright (c) 2025 Moonshot AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the “Software”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ Our only modification part is that, if the Software (or any derivative works
24
+ thereof) is used for any of your commercial products or services that have
25
+ more than 100 million monthly active users, or more than 20 million US dollars
26
+ (or equivalent in other currencies) in monthly revenue, you shall prominently
27
+ display "Kimi K2" on the user interface of such product or service.
README.md ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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://www.moonshot.ai" target="_blank"><img alt="Homepage" src="https://img.shields.io/badge/Homepage-Moonshot%20AI-white?logo=Kimi&logoColor=white"/></a>
16
+ </div>
17
+
18
+ <div align="center" style="line-height: 1;">
19
+ <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>
20
+ <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>
21
+ <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>
22
+ </div>
23
+ <div align="center" style="line-height: 1;">
24
+ <a href="https://huggingface.co/moonshotai/Kimi-K2-Thinking/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Modified_MIT-f5de53?&color=f5de53"/></a>
25
+ </div>
26
+
27
+ <p align="center">
28
+ <b>📰&nbsp;&nbsp;<a href="https://moonshotai.github.io/Kimi-K2/thinking.html">Tech Blog</a></b>
29
+ </p>
30
+
31
+
32
+ ## 1. Model Introduction
33
+
34
+ Kimi K2 Thinking is the latest, most capable version of open-source thinking model. Starting with Kimi K2, we built it as a thinking agent that reasons step-by-step while dynamically invoking tools. It sets a new state-of-the-art on Humanity's Last Exam (HLE), BrowseComp, and other benchmarks by dramatically scaling multi-step reasoning depth and maintaining stable tool-use across 200–300 sequential calls. At the same time, K2 Thinking is a native INT4 quantization model with 256k context window, achieving lossless reductions in inference latency and GPU memory usage.
35
+
36
+ ### Key Features
37
+ - **Deep Thinking & Tool Orchestration**: End-to-end trained to interleave chain-of-thought reasoning with function calls, enabling autonomous research, coding, and writing workflows that last hundreds of steps without drift.
38
+ - **Native INT4 Quantization**: Quantization-Aware Training (QAT) is employed in post-training stage to achieve lossless 2x speed-up in low-latency mode.
39
+ - **Stable Long-Horizon Agency**: Maintains coherent goal-directed behavior across up to 200–300 consecutive tool invocations, surpassing prior models that degrade after 30–50 steps.
40
+
41
+
42
+ ## 2. Model Summary
43
+
44
+ <div align="center">
45
+
46
+
47
+ | | |
48
+ |:---:|:---:|
49
+ | **Architecture** | Mixture-of-Experts (MoE) |
50
+ | **Total Parameters** | 1T |
51
+ | **Activated Parameters** | 32B |
52
+ | **Number of Layers** (Dense layer included) | 61 |
53
+ | **Number of Dense Layers** | 1 |
54
+ | **Attention Hidden Dimension** | 7168 |
55
+ | **MoE Hidden Dimension** (per Expert) | 2048 |
56
+ | **Number of Attention Heads** | 64 |
57
+ | **Number of Experts** | 384 |
58
+ | **Selected Experts per Token** | 8 |
59
+ | **Number of Shared Experts** | 1 |
60
+ | **Vocabulary Size** | 160K |
61
+ | **Context Length** | 256K |
62
+ | **Attention Mechanism** | MLA |
63
+ | **Activation Function** | SwiGLU |
64
+ </div>
65
+
66
+ ## 3. Evaluation Results
67
+
68
+ **Reasoning Tasks**
69
+ | Benchmark | Setting | K2 Thinking | GPT-5<br> (High) | Claude Sonnet 4.5<br> (Thinking) | K2 0905 | DeepSeek-V3.2 | Grok-4 |
70
+ |:----------:|:--------:|:------------:|:------:|:----------------------------:|:--------:|:--------------:|:-------:|
71
+ | **HLE (Text-only)** | no tools | 23.9 | 26.3 | 19.8* | 7.9 | 19.8 | 25.4 |
72
+ | | w/ tools | 44.9 | 41.7* | 32.0* | 21.7 | 20.3* | 41.0 |
73
+ | | heavy | 51.0 | 42.0 | - | - | - | 50.7 |
74
+ | **AIME25** | no tools | 94.5 | 94.6 | 87.0 | 51.0 | 89.3 | 91.7 |
75
+ | | w/ python | 99.1 | 99.6 | 100.0 | 75.2 | 58.1* | 98.8 |
76
+ | | heavy | 100.0 | 100.0 | - | - | - | 100.0 |
77
+ | **HMMT25** | no tools | 89.4 | 93.3 | 74.6* | 38.8 | 83.6 | 90.0 |
78
+ | | w/ python | 95.1 | 96.7 | 88.8* | 70.4 | 49.5* | 93.9 |
79
+ | | heavy | 97.5 | 100.0 | - | - | - | 96.7 |
80
+ | **IMO-AnswerBench** | no tools | 78.6 | 76.0* | 65.9* | 45.8 | 76.0* | 73.1 |
81
+ | **GPQA** | no tools | 84.5 | 85.7 | 83.4 | 74.2 | 79.9 | 87.5 |
82
+
83
+ **General Tasks**
84
+ | Benchmark | Setting | K2 Thinking | GPT-5<br> (High) | Claude Sonnet 4.5<br> (Thinking) | K2 0905 | DeepSeek-V3.2 |
85
+ |:----------:|:--------:|:------------:|:------:|:----------------------------:|:--------:|:--------------:|
86
+ | **MMLU-Pro** | no tools | 84.6 | 87.1 | 87.5 | 81.9 | 85.0 |
87
+ | **MMLU-Redux** | no tools | 94.4 | 95.3 | 95.6 | 92.7 | 93.7 |
88
+ | **Longform Writing** | no tools | 73.8 | 71.4 | 79.8 | 62.8 | 72.5 |
89
+ | **HealthBench** | no tools | 58.0 | 67.2 | 44.2 | 43.8 | 46.9 |
90
+
91
+ **Agentic Search Tasks**
92
+ | Benchmark | Setting | K2 Thinking | GPT-5<br> (High) | Claude Sonnet 4.5<br> (Thinking) | K2 0905 | DeepSeek-V3.2 |
93
+ |:----------:|:--------:|:------------:|:------:|:----------------------------:|:--------:|:--------------:|
94
+ | **BrowseComp** | w/ tools | 60.2 | 54.9 | 24.1 | 7.4 | 40.1 |
95
+ | **BrowseComp-ZH** | w/ tools | 62.3 | 63.0* | 42.4* | 22.2 | 47.9 |
96
+ | **Seal-0** | w/ tools | 56.3 | 51.4* | 53.4* | 25.2 | 38.5* |
97
+ | **FinSearchComp-T3** | w/ tools | 47.4 | 48.5* | 44.0* | 10.4 | 27.0* |
98
+ | **Frames** | w/ tools | 87.0 | 86.0* | 85.0* | 58.1 | 80.2* |
99
+
100
+ **Coding Tasks**
101
+ | Benchmark | Setting | K2 Thinking | GPT-5<br> (High) | Claude Sonnet 4.5<br> (Thinking) | K2 0905 | DeepSeek-V3.2 |
102
+ |:----------:|:--------:|:------------:|:------:|:----------------------------:|:--------:|:--------------:|
103
+ | **SWE-bench Verified** | w/ tools | 71.3 | 74.9 | 77.2 | 69.2 | 67.8 |
104
+ | **SWE-bench Multilingual** | w/ tools | 61.1 | 55.3* | 68.0 | 55.9 | 57.9 |
105
+ | **Multi-SWE-bench** | w/ tools | 41.9 | 39.3* | 44.3 | 33.5 | 30.6 |
106
+ | **SciCode** | no tools | 44.8 | 42.9 | 44.7 | 30.7 | 37.7 |
107
+ | **LiveCodeBenchV6** | no tools | 83.1 | 87.0* | 64.0* | 56.1* | 74.1 |
108
+ | **OJ-Bench (cpp)** | no tools | 48.7 | 56.2* | 30.4* | 25.5* | 38.2* |
109
+ | **Terminal-Bench** | w/ simulated tools (JSON) | 47.1 | 43.8 | 51.0 | 44.5 | 37.7 |
110
+ <details>
111
+ <summary><b>Footnotes</b></summary>
112
+
113
+ 1. To ensure a fast, lightweight experience, we selectively employ a subset of tools and reduce the number of tool call steps under the chat mode on kimi.com. As a result, chatting on kimi.com may not reproduce our benchmark scores. Our agentic mode will be updated soon to reflect the full capabilities of K2 Thinking.
114
+
115
+ 2. **Testing Details**:
116
+  2.1. All benchmarks were evaluated at temperature = 1.0 and 256 k context length for K2 Thinking, except for SciCode, for which we followed the official temperature setting of 0.0.
117
+  2.2. HLE (no tools), AIME25, HMMT25, and GPQA were capped at a 96k thinking-token budget, while IMO-Answer Bench, LiveCodeBench and OJ-Bench were capped at a 128k thinking-token budget. Longform Writing was capped at a 32k completion-token budget.
118
+  2.3. For AIME and HMMT (no tools), we report the average of 32 runs (avg@32). For AIME and HMMT (with Python), we report the average of 16 runs (avg@16). For IMO-AnswerBench, we report the average of 8 runs (avg@8).
119
+
120
+ 3. **Baselines**:
121
+  3.1 GPT-5, Claude-4.5-sonnet, Grok-4 results and DeepSeek-V3.2 results are quoted from the [GPT-5 post](https://openai.com/index/introducing-gpt-5/), [GPT-5 for Developers post](https://openai.com/index/introducing-gpt-5-for-developers/), [GPT-5 system card](https://openai.com/index/gpt-5-system-card/), [claude-sonnet-4-5 post](https://www.anthropic.com/news/claude-sonnet-4-5), [grok-4 post](https://x.ai/news/grok-4), [deepseek-v3.2 post](https://api-docs.deepseek.com/news/news250929), the [public Terminal-Bench leaderboard](https://www.tbench.ai/leaderboard) (Terminus-2), the [public Vals AI leaderboard](https://vals.ai/) and [artificialanalysis](https://artificialanalysis.ai/). Benchmarks for which no available public scores were re-tested under the same conditions used for k2 thinking and are marked with an asterisk(*). For the GPT-5 test, we set the reasoning effort to high.
122
+  3.2 The GPT-5 and Grok-4 on the HLE full set with tools are 35.2 and 38.6 from the official posts. In our internal evaluation on the HLE text-only subset, GPT-5 scores 41.7 and Grok-4 scores 38.6 (Grok-4’s launch cited 41.0 on the text-only subset). For GPT-5's HLE text-only w/o tool, we use score from <a href="https://scale.com/leaderboard/humanitys_last_exam_text_only" target="_blank">Scale.ai</a>. The official GPT5 HLE full set w/o tool is 24.8.
123
+  3.3 For <a href="https://aclanthology.org/2025.emnlp-main.1794.pdf" target="_blank">IMO-AnswerBench</a>: GPT-5 scored 65.6 in the benchmark paper. We re-evaluated GPT-5 with official API and obtained a score of 76.
124
+
125
+ 4. **For HLE (w/ tools) and the agentic-search benchmarks**:
126
+  4.1. K2 Thinking was equipped with search, code-interpreter, and web-browsing tools.
127
+  4.2. BrowseComp-ZH, Seal-0 and FinSearchComp-T3 were run 4 times independently and the average is reported (avg@4).
128
+  4.3. The evaluation used o3-mini as judge, configured identically to the official HLE setting; judge prompts were taken verbatim from the official repository.
129
+  4.4. On HLE, the maximum step limit was 120, with a 48 k-token reasoning budget per step; on agentic-search tasks, the limit was 300 steps with a 24 k-token reasoning budget per step.
130
+  4.5. When tool execution results cause the accumulated input to exceed the model's context limit (256k), we employ a simple context management strategy that hides all previous tool outputs.
131
+  4.6. The web access to Hugging Face may lead to data leakage in certain benchmark tests, such as HLE. K2 Thinking can achieve a score of 51.3 on HLE without blocking Hugging Face. To ensure a fair and rigorous comparison, we blocked access to Hugging Face during testing.
132
+
133
+ 5. **For Coding Tasks**:
134
+  5.1. Terminal-Bench scores were obtained with the default agent framework (Terminus-2) and the provided JSON parser.
135
+  5.2. For other coding tasks, the 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.
136
+  5.3. All reported scores of coding tasks are averaged over 5 independent runs.
137
+
138
+ 6. **Heavy Mode**: K2 Thinking Heavy Mode employs an efficient parallel strategy: it first rolls out eight trajectories simultaneously, then reflectively aggregates all outputs to generate the final result. Heavy mode for GPT-5 denotes the official GPT-5 Pro score.
139
+ </details>
140
+
141
+ ## 4. Native INT4 Quantization
142
+
143
+ Low-bit quantization is an effective way to reduce inference latency and GPU memory usage on large-scale inference servers. However, thinking models use excessive decoding lengths, and thus quantization often results in substantial performance drops.
144
+
145
+ To overcome this challenge, we adopt Quantization-Aware Training (QAT) during the post-training phase, applying INT4 weight-only quantization to the MoE components. It allows K2 Thinking to support native INT4 inference with a roughly 2x generation speed improvement while achieving state-of-the-art performance. All benchmark results are reported under INT4 precision.
146
+
147
+ The checkpoints are saved in compressed-tensors format, supported by most of mainstream inference engine. If you need the checkpoints in higher precision such as FP8 or BF16, you can refer to [official repo of compressed-tensors](https://github.com/vllm-project/compressed-tensors) to unpack the int4 weights and convert to any higher precision.
148
+
149
+ ## 5. Deployment
150
+ > [!Note]
151
+ > You can access K2 Thinking's API on https://platform.moonshot.ai , we provide OpenAI/Anthropic-compatible API for you.
152
+
153
+ Currently, Kimi-K2-Thinking is recommended to run on the following inference engines:
154
+
155
+ * vLLM
156
+ * SGLang
157
+ * KTransformers
158
+
159
+ Deployment examples can be found in the [Model Deployment Guide](docs/deploy_guidance.md).
160
+
161
+ ---
162
+
163
+ ## 6. Model Usage
164
+
165
+ ### Chat Completion
166
+
167
+ Once the local inference service is up, you can interact with it through the chat endpoint:
168
+
169
+ ```python
170
+ def simple_chat(client: openai.OpenAI, model_name: str):
171
+ messages = [
172
+ {"role": "system", "content": "You are Kimi, an AI assistant created by Moonshot AI."},
173
+ {"role": "user", "content": [{"type": "text", "text": "which one is bigger, 9.11 or 9.9? think carefully."}]},
174
+ ]
175
+ response = client.chat.completions.create(
176
+ model=model_name,
177
+ messages=messages,
178
+ stream=False,
179
+ temperature=1.0,
180
+ max_tokens=4096
181
+ )
182
+ print(f"k2 answer: {response.choices[0].message.content}")
183
+ print("=====below is reasoning content======")
184
+ print(f"reasoning content: {response.choices[0].message.reasoning_content}")
185
+ ```
186
+
187
+ > [!NOTE]
188
+ > The recommended temperature for Kimi-K2-Thinking is `temperature = 1.0`.
189
+ > If no special instructions are required, the system prompt above is a good default.
190
+
191
+ ---
192
+
193
+ ### Tool Calling
194
+
195
+ Kimi-K2-Thinking has the same tool calling settings as Kimi-K2-Instruct.
196
+
197
+ 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.
198
+
199
+ The following example demonstrates calling a weather tool end-to-end:
200
+
201
+ ```python
202
+ # Your tool implementation
203
+ def get_weather(city: str) -> dict:
204
+ return {"weather": "Sunny"}
205
+ # Tool schema definition
206
+ tools = [{
207
+ "type": "function",
208
+ "function": {
209
+ "name": "get_weather",
210
+ "description": "Retrieve current weather information. Call this when the user asks about the weather.",
211
+ "parameters": {
212
+ "type": "object",
213
+ "required": ["city"],
214
+ "properties": {
215
+ "city": {
216
+ "type": "string",
217
+ "description": "Name of the city"
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }]
223
+ # Map tool names to their implementations
224
+ tool_map = {
225
+ "get_weather": get_weather
226
+ }
227
+ def tool_call_with_client(client: OpenAI, model_name: str):
228
+ messages = [
229
+ {"role": "system", "content": "You are Kimi, an AI assistant created by Moonshot AI."},
230
+ {"role": "user", "content": "What's the weather like in Beijing today? Use the tool to check."}
231
+ ]
232
+ finish_reason = None
233
+ while finish_reason is None or finish_reason == "tool_calls":
234
+ completion = client.chat.completions.create(
235
+ model=model_name,
236
+ messages=messages,
237
+ temperature=1.0,
238
+ tools=tools, # tool list defined above
239
+ tool_choice="auto"
240
+ )
241
+ choice = completion.choices[0]
242
+ finish_reason = choice.finish_reason
243
+ if finish_reason == "tool_calls":
244
+ messages.append(choice.message)
245
+ for tool_call in choice.message.tool_calls:
246
+ tool_call_name = tool_call.function.name
247
+ tool_call_arguments = json.loads(tool_call.function.arguments)
248
+ tool_function = tool_map[tool_call_name]
249
+ tool_result = tool_function(**tool_call_arguments)
250
+ print("tool_result:", tool_result)
251
+ messages.append({
252
+ "role": "tool",
253
+ "tool_call_id": tool_call.id,
254
+ "name": tool_call_name,
255
+ "content": json.dumps(tool_result)
256
+ })
257
+ print("-" * 100)
258
+ print(choice.message.content)
259
+ ```
260
+
261
+ The `tool_call_with_client` function implements the pipeline from user query to tool execution.
262
+ This pipeline requires the inference engine to support Kimi-K2’s native tool-parsing logic.
263
+ For more information, see the [Tool Calling Guide](docs/tool_call_guidance.md).
264
+
265
+ ---
266
+
267
+ ## 7. License
268
+
269
+ Both the code repository and the model weights are released under the [Modified MIT License](LICENSE).
270
+
271
+ ---
272
+
273
+ ## 8. Third Party Notices
274
+
275
+ See [THIRD PARTY NOTICES](THIRD_PARTY_NOTICES.md)
276
+
277
+ ---
278
+
279
+ ## 9. Contact Us
280
+
281
+ If you have any questions, please reach out at [support@moonshot.cn](mailto:support@moonshot.cn).
THIRD_PARTY_NOTICES.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # THIRD_PARTY_NOTICES
2
+
3
+ This file lists third-party software contained in Kimi-K2-Thinking along with their licenses, in compliance with the redistribution clauses of those licenses.
4
+
5
+ ---
6
+
7
+ ## 1. DeepSeek-V3
8
+
9
+ Our model archietecture is DeepSeek-V3-like. Some of modeling codes are copied from the source repository.
10
+
11
+ - **Source Repository**
12
+ https://huggingface.co/deepseek-ai/DeepSeek-V3
13
+
14
+ - **Files / Directories Used**
15
+ - configuration_deepseek.py
16
+ - modeling_deepseek.py
17
+
18
+ - **License Type**
19
+ MIT License
20
+
21
+ - **Copyright Notice**
22
+ Copyright (c) 2023 DeepSeek
23
+
24
+ - **Full License Text**
25
+ ```
26
+ MIT License
27
+
28
+ Copyright (c) 2023 DeepSeek
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ of this software and associated documentation files (the "Software"), to deal
32
+ in the Software without restriction, including without limitation the rights
33
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34
+ copies of the Software, and to permit persons to whom the Software is
35
+ furnished to do so, subject to the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be included in all
38
+ copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
46
+ SOFTWARE.
47
+ ```
chat_template.jinja ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- macro render_content(msg) -%}
2
+ {%- set c = msg.get('content') -%}
3
+ {%- if c is string -%}
4
+ {{ c }}
5
+ {%- elif c is not none -%}
6
+ {% for content in c -%}
7
+ {% if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
8
+ <|media_start|>image<|media_content|><|media_pad|><|media_end|>
9
+ {% else -%}
10
+ {{ content['text'] }}
11
+ {%- endif -%}
12
+ {%- endfor -%}
13
+ {%- endif -%}
14
+ {%- endmacro -%}
15
+
16
+ {% macro set_roles(message) -%}
17
+ {%- set role_name = message.get('name') or message['role'] -%}
18
+ {%- if message['role'] == 'user' -%}
19
+ <|im_user|>{{role_name}}<|im_middle|>
20
+ {%- elif message['role'] == 'assistant' -%}
21
+ <|im_assistant|>{{role_name}}<|im_middle|>
22
+ {%- else -%}
23
+ <|im_system|>{{role_name}}<|im_middle|>
24
+ {%- endif -%}
25
+ {%- endmacro -%}
26
+
27
+
28
+ {%- macro render_toolcalls(message) -%}
29
+ <|tool_calls_section_begin|>
30
+ {%- for tool_call in message['tool_calls'] -%}
31
+ {%- set formatted_id = tool_call['id'] -%}
32
+ <|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|>
33
+ {%- endfor -%}
34
+ <|tool_calls_section_end|>
35
+ {%- endmacro -%}
36
+
37
+
38
+ {# Find last non-tool-call assisitant message #}
39
+ {%- set ns = namespace(last_non_tool_call_assistant_msg=-1) -%}
40
+ {%- for idx in range(messages|length-1, -1, -1) -%}
41
+ {%- if messages[idx]['role'] == 'assistant' and not messages[idx].get('tool_calls') -%}
42
+ {%- set ns.last_non_tool_call_assistant_msg = idx -%}
43
+ {%- break -%}
44
+ {%- endif -%}
45
+ {%- endfor -%}
46
+
47
+ {# split all messages into history & suffix, reasoning_content in suffix should be reserved.#}
48
+ {%- set hist_msgs = messages[:ns.last_non_tool_call_assistant_msg+1] -%}
49
+ {%- set suffix_msgs = messages[ns.last_non_tool_call_assistant_msg+1:] -%}
50
+
51
+ {%- if tools -%}
52
+ <|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>
53
+ {%- endif -%}
54
+
55
+ {%- if messages|length == 0 or messages[0]['role'] != 'system' -%}
56
+ <|im_system|>system<|im_middle|>You are Kimi, an AI assistant created by Moonshot AI.<|im_end|>
57
+ {%- endif -%}
58
+
59
+ {%- for message in hist_msgs -%}
60
+ {{set_roles(message)}}
61
+ {%- if message['role'] == 'assistant' -%}
62
+ <think></think>{{render_content(message)}}
63
+ {%- if message.get('tool_calls') -%}
64
+ {{render_toolcalls(message)}}
65
+ {%- endif -%}
66
+ {%- elif message['role'] == 'tool' -%}
67
+ {%- set tool_call_id = message.tool_call_id -%}
68
+ ## Return of {{ tool_call_id }}
69
+ {{render_content(message)}}
70
+ {%- elif message['content'] is not none -%}
71
+ {{render_content(message)}}
72
+ {%- endif -%}
73
+ <|im_end|>
74
+ {%- endfor -%}
75
+
76
+ {%- for message in suffix_msgs -%}
77
+ {{set_roles(message)}}
78
+ {%- if message['role'] == 'assistant' -%}
79
+ {%- set rc = message.get('reasoning_content', '') -%}
80
+ <think>{{rc}}</think>{{render_content(message)}}
81
+ {%- if message.get('tool_calls') -%}
82
+ {{render_toolcalls(message)}}
83
+ {%- endif -%}
84
+ {%- elif message['role'] == 'tool' -%}
85
+ {%- set tool_call_id = message.tool_call_id -%}
86
+ ## Return of {{ tool_call_id }}
87
+ {{render_content(message)}}
88
+ {%- elif message['content'] is not none -%}
89
+ {{render_content(message)}}
90
+ {%- endif -%}
91
+ <|im_end|>
92
+ {%- endfor -%}
93
+
94
+
95
+ {%- if add_generation_prompt -%}
96
+ <|im_assistant|>assistant<|im_middle|>
97
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_attn_implementation_autoset": false,
3
+ "_name_or_path": "",
4
+ "add_cross_attention": false,
5
+ "architectures": [
6
+ "DeepseekV3ForCausalLM"
7
+ ],
8
+ "attention_bias": false,
9
+ "attention_dropout": 0.0,
10
+ "auto_map": {
11
+ "AutoConfig": "configuration_deepseek.DeepseekV3Config",
12
+ "AutoModel": "modeling_deepseek.DeepseekV3Model",
13
+ "AutoModelForCausalLM": "modeling_deepseek.DeepseekV3ForCausalLM"
14
+ },
15
+ "aux_loss_alpha": 0.001,
16
+ "bad_words_ids": null,
17
+ "begin_suppress_tokens": null,
18
+ "bos_token_id": 163584,
19
+ "chunk_size_feed_forward": 0,
20
+ "cross_attention_hidden_size": null,
21
+ "decoder_start_token_id": null,
22
+ "diversity_penalty": 0.0,
23
+ "do_sample": false,
24
+ "early_stopping": false,
25
+ "encoder_no_repeat_ngram_size": 0,
26
+ "eos_token_id": 163586,
27
+ "ep_size": 1,
28
+ "exponential_decay_length_penalty": null,
29
+ "finetuning_task": null,
30
+ "first_k_dense_replace": 1,
31
+ "forced_bos_token_id": null,
32
+ "forced_eos_token_id": null,
33
+ "hidden_act": "silu",
34
+ "hidden_size": 7168,
35
+ "id2label": {
36
+ "0": "LABEL_0",
37
+ "1": "LABEL_1"
38
+ },
39
+ "initializer_range": 0.02,
40
+ "intermediate_size": 18432,
41
+ "is_decoder": false,
42
+ "is_encoder_decoder": false,
43
+ "kv_lora_rank": 512,
44
+ "label2id": {
45
+ "LABEL_0": 0,
46
+ "LABEL_1": 1
47
+ },
48
+ "length_penalty": 1.0,
49
+ "max_length": 20,
50
+ "max_position_embeddings": 262144,
51
+ "min_length": 0,
52
+ "model_type": "kimi_k2",
53
+ "moe_intermediate_size": 2048,
54
+ "moe_layer_freq": 1,
55
+ "n_group": 1,
56
+ "n_routed_experts": 384,
57
+ "n_shared_experts": 1,
58
+ "no_repeat_ngram_size": 0,
59
+ "norm_topk_prob": true,
60
+ "num_attention_heads": 64,
61
+ "num_beam_groups": 1,
62
+ "num_beams": 1,
63
+ "num_experts_per_tok": 8,
64
+ "num_hidden_layers": 61,
65
+ "num_key_value_heads": 64,
66
+ "num_nextn_predict_layers": 0,
67
+ "num_return_sequences": 1,
68
+ "output_attentions": false,
69
+ "output_hidden_states": false,
70
+ "output_scores": false,
71
+ "pad_token_id": 163839,
72
+ "prefix": null,
73
+ "pretraining_tp": 1,
74
+ "problem_type": null,
75
+ "pruned_heads": {},
76
+ "q_lora_rank": 1536,
77
+ "qk_nope_head_dim": 128,
78
+ "qk_rope_head_dim": 64,
79
+ "quantization_config": {
80
+ "config_groups": {
81
+ "group_0": {
82
+ "input_activations": null,
83
+ "output_activations": null,
84
+ "targets": [
85
+ "Linear"
86
+ ],
87
+ "weights": {
88
+ "actorder": null,
89
+ "block_structure": null,
90
+ "dynamic": false,
91
+ "group_size": 32,
92
+ "num_bits": 4,
93
+ "observer": "minmax",
94
+ "observer_kwargs": {},
95
+ "strategy": "group",
96
+ "symmetric": true,
97
+ "type": "int"
98
+ }
99
+ }
100
+ },
101
+ "format": "pack-quantized",
102
+ "ignore": [
103
+ "lm_head",
104
+ "re:.*self_attn.*",
105
+ "re:.*shared_experts.*",
106
+ "re:.*mlp\\.(gate|up|gate_up|down)_proj.*"
107
+ ],
108
+ "kv_cache_scheme": null,
109
+ "quant_method": "compressed-tensors",
110
+ "quantization_status": "compressed"
111
+ },
112
+ "remove_invalid_values": false,
113
+ "repetition_penalty": 1.0,
114
+ "return_dict": true,
115
+ "return_dict_in_generate": false,
116
+ "rms_norm_eps": 1e-05,
117
+ "rope_scaling": {
118
+ "beta_fast": 1.0,
119
+ "beta_slow": 1.0,
120
+ "factor": 64.0,
121
+ "mscale": 1.0,
122
+ "mscale_all_dim": 1.0,
123
+ "original_max_position_embeddings": 4096,
124
+ "type": "yarn"
125
+ },
126
+ "rope_theta": 50000.0,
127
+ "routed_scaling_factor": 2.827,
128
+ "scoring_func": "sigmoid",
129
+ "sep_token_id": null,
130
+ "seq_aux": true,
131
+ "suppress_tokens": null,
132
+ "task_specific_params": null,
133
+ "temperature": 1.0,
134
+ "tf_legacy_loss": false,
135
+ "tie_encoder_decoder": false,
136
+ "tie_word_embeddings": false,
137
+ "tokenizer_class": null,
138
+ "top_k": 50,
139
+ "top_p": 1.0,
140
+ "topk_group": 1,
141
+ "topk_method": "noaux_tc",
142
+ "torch_dtype": "bfloat16",
143
+ "torchscript": false,
144
+ "transformers_version": "4.51.3",
145
+ "typical_p": 1.0,
146
+ "use_bfloat16": false,
147
+ "use_cache": true,
148
+ "v_head_dim": 128,
149
+ "vocab_size": 163840
150
+ }
configuration_deepseek.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copy from https://huggingface.co/deepseek-ai/DeepSeek-V3/blob/main/configuration_deepseek.py
2
+
3
+ from transformers.configuration_utils import PretrainedConfig
4
+ from transformers.utils import logging
5
+
6
+ logger = logging.get_logger(__name__)
7
+
8
+ DEEPSEEK_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
9
+ class DeepseekV3Config(PretrainedConfig):
10
+ r"""
11
+ This is the configuration class to store the configuration of a [`DeepseekV3Model`]. It is used to instantiate an DeepSeek
12
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
13
+ defaults will yield a similar configuration to that of the DeepSeek-V3.
14
+
15
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
16
+ documentation from [`PretrainedConfig`] for more information.
17
+
18
+
19
+ Args:
20
+ vocab_size (`int`, *optional*, defaults to 129280):
21
+ Vocabulary size of the Deep model. Defines the number of different tokens that can be represented by the
22
+ `inputs_ids` passed when calling [`DeepseekV3Model`]
23
+ hidden_size (`int`, *optional*, defaults to 4096):
24
+ Dimension of the hidden representations.
25
+ intermediate_size (`int`, *optional*, defaults to 11008):
26
+ Dimension of the MLP representations.
27
+ moe_intermediate_size (`int`, *optional*, defaults to 1407):
28
+ Dimension of the MoE representations.
29
+ num_hidden_layers (`int`, *optional*, defaults to 32):
30
+ Number of hidden layers in the Transformer decoder.
31
+ num_nextn_predict_layers (`int`, *optional*, defaults to 1):
32
+ Number of nextn predict layers in the DeepSeekV3 Model.
33
+ num_attention_heads (`int`, *optional*, defaults to 32):
34
+ Number of attention heads for each attention layer in the Transformer decoder.
35
+ n_shared_experts (`int`, *optional*, defaults to None):
36
+ Number of shared experts, None means dense model.
37
+ n_routed_experts (`int`, *optional*, defaults to None):
38
+ Number of routed experts, None means dense model.
39
+ routed_scaling_factor (`float`, *optional*, defaults to 1.0):
40
+ Scaling factor or routed experts.
41
+ topk_method (`str`, *optional*, defaults to `gready`):
42
+ Topk method used in routed gate.
43
+ n_group (`int`, *optional*, defaults to None):
44
+ Number of groups for routed experts.
45
+ topk_group (`int`, *optional*, defaults to None):
46
+ Number of selected groups for each token(for each token, ensuring the selected experts is only within `topk_group` groups).
47
+ num_experts_per_tok (`int`, *optional*, defaults to None):
48
+ Number of selected experts, None means dense model.
49
+ moe_layer_freq (`int`, *optional*, defaults to 1):
50
+ The frequency of the MoE layer: one expert layer for every `moe_layer_freq - 1` dense layers.
51
+ first_k_dense_replace (`int`, *optional*, defaults to 0):
52
+ Number of dense layers in shallow layers(embed->dense->dense->...->dense->moe->moe...->lm_head).
53
+ \--k dense layers--/
54
+ norm_topk_prob (`bool`, *optional*, defaults to False):
55
+ Whether to normalize the weights of the routed experts.
56
+ scoring_func (`str`, *optional*, defaults to 'softmax'):
57
+ Method of computing expert weights.
58
+ aux_loss_alpha (`float`, *optional*, defaults to 0.001):
59
+ Auxiliary loss weight coefficient.
60
+ seq_aux = (`bool`, *optional*, defaults to True):
61
+ Whether to compute the auxiliary loss for each individual sample.
62
+ num_key_value_heads (`int`, *optional*):
63
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
64
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
65
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
66
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
67
+ by meanpooling all the original heads within that group. For more details checkout [this
68
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
69
+ `num_attention_heads`.
70
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
71
+ The non-linear activation function (function or string) in the decoder.
72
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
73
+ The maximum sequence length that this model might ever be used with.
74
+ initializer_range (`float`, *optional*, defaults to 0.02):
75
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
76
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
77
+ The epsilon used by the rms normalization layers.
78
+ use_cache (`bool`, *optional*, defaults to `True`):
79
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
80
+ relevant if `config.is_decoder=True`.
81
+ pad_token_id (`int`, *optional*):
82
+ Padding token id.
83
+ bos_token_id (`int`, *optional*, defaults to 1):
84
+ Beginning of stream token id.
85
+ eos_token_id (`int`, *optional*, defaults to 2):
86
+ End of stream token id.
87
+ pretraining_tp (`int`, *optional*, defaults to 1):
88
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
89
+ document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
90
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
91
+ issue](https://github.com/pytorch/pytorch/issues/76232).
92
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
93
+ Whether to tie weight embeddings
94
+ rope_theta (`float`, *optional*, defaults to 10000.0):
95
+ The base period of the RoPE embeddings.
96
+ rope_scaling (`Dict`, *optional*):
97
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
98
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
99
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
100
+ `max_position_embeddings` to the expected new maximum.
101
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
102
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
103
+ attention_dropout (`float`, *optional*, defaults to 0.0):
104
+ The dropout ratio for the attention probabilities.
105
+
106
+ ```python
107
+ >>> from transformers import DeepseekV3Model, DeepseekV3Config
108
+
109
+ >>> # Initializing a Deepseek-V3 style configuration
110
+ >>> configuration = DeepseekV3Config()
111
+
112
+ >>> # Accessing the model configuration
113
+ >>> configuration = model.config
114
+ ```"""
115
+
116
+ model_type = "deepseek_v3"
117
+ keys_to_ignore_at_inference = ["past_key_values"]
118
+
119
+ def __init__(
120
+ self,
121
+ vocab_size=129280,
122
+ hidden_size=7168,
123
+ intermediate_size=18432,
124
+ moe_intermediate_size = 2048,
125
+ num_hidden_layers=61,
126
+ num_nextn_predict_layers=1,
127
+ num_attention_heads=128,
128
+ num_key_value_heads=128,
129
+ n_shared_experts = 1,
130
+ n_routed_experts = 256,
131
+ ep_size = 1,
132
+ routed_scaling_factor = 2.5,
133
+ kv_lora_rank = 512,
134
+ q_lora_rank = 1536,
135
+ qk_rope_head_dim = 64,
136
+ v_head_dim = 128,
137
+ qk_nope_head_dim = 128,
138
+ topk_method = 'noaux_tc',
139
+ n_group = 8,
140
+ topk_group = 4,
141
+ num_experts_per_tok = 8,
142
+ moe_layer_freq = 1,
143
+ first_k_dense_replace = 3,
144
+ norm_topk_prob = True,
145
+ scoring_func = 'sigmoid',
146
+ aux_loss_alpha = 0.001,
147
+ seq_aux = True,
148
+ hidden_act="silu",
149
+ max_position_embeddings=4096,
150
+ initializer_range=0.02,
151
+ rms_norm_eps=1e-6,
152
+ use_cache=True,
153
+ pad_token_id=None,
154
+ bos_token_id=0,
155
+ eos_token_id=1,
156
+ pretraining_tp=1,
157
+ tie_word_embeddings=False,
158
+ rope_theta=10000.0,
159
+ rope_scaling=None,
160
+ attention_bias=False,
161
+ attention_dropout=0.0,
162
+ **kwargs,
163
+ ):
164
+ self.vocab_size = vocab_size
165
+ self.max_position_embeddings = max_position_embeddings
166
+ self.hidden_size = hidden_size
167
+ self.intermediate_size = intermediate_size
168
+ self.moe_intermediate_size = moe_intermediate_size
169
+ self.num_hidden_layers = num_hidden_layers
170
+ self.num_nextn_predict_layers = num_nextn_predict_layers
171
+ self.num_attention_heads = num_attention_heads
172
+ self.n_shared_experts = n_shared_experts
173
+ self.n_routed_experts = n_routed_experts
174
+ self.ep_size = ep_size
175
+ self.routed_scaling_factor = routed_scaling_factor
176
+ self.kv_lora_rank = kv_lora_rank
177
+ self.q_lora_rank = q_lora_rank
178
+ self.qk_rope_head_dim = qk_rope_head_dim
179
+ self.v_head_dim = v_head_dim
180
+ self.qk_nope_head_dim = qk_nope_head_dim
181
+ self.topk_method = topk_method
182
+ self.n_group = n_group
183
+ self.topk_group = topk_group
184
+ self.num_experts_per_tok = num_experts_per_tok
185
+ self.moe_layer_freq = moe_layer_freq
186
+ self.first_k_dense_replace = first_k_dense_replace
187
+ self.norm_topk_prob = norm_topk_prob
188
+ self.scoring_func = scoring_func
189
+ self.aux_loss_alpha = aux_loss_alpha
190
+ self.seq_aux = seq_aux
191
+ # for backward compatibility
192
+ if num_key_value_heads is None:
193
+ num_key_value_heads = num_attention_heads
194
+
195
+ self.num_key_value_heads = num_key_value_heads
196
+ self.hidden_act = hidden_act
197
+ self.initializer_range = initializer_range
198
+ self.rms_norm_eps = rms_norm_eps
199
+ self.pretraining_tp = pretraining_tp
200
+ self.use_cache = use_cache
201
+ self.rope_theta = rope_theta
202
+ self.rope_scaling = rope_scaling
203
+ self.attention_bias = attention_bias
204
+ self.attention_dropout = attention_dropout
205
+
206
+ super().__init__(
207
+ pad_token_id=pad_token_id,
208
+ bos_token_id=bos_token_id,
209
+ eos_token_id=eos_token_id,
210
+ tie_word_embeddings=tie_word_embeddings,
211
+ **kwargs,
212
+ )
docs/deploy_guidance.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Kimi-K2-Thinking Deployment Guide
2
+
3
+ > [!Note]
4
+ > This guide only provides some examples of deployment commands for Kimi-K2-Thinking, which may not be the optimal configuration. Since inference engines are still being updated frequenty, please continue to follow the guidance from their homepage if you want to achieve better inference performance.
5
+
6
+ > kimi_k2 reasoning parser and other related features have been merged into vLLM/sglang and will be available in the next release. For now, please use the nightly build Docker image.
7
+
8
+
9
+ ## vLLM Deployment
10
+
11
+ The smallest deployment unit for Kimi-K2-Thinking INT4 weights with 256k seqlen on mainstream H200 platform is a cluster with 8 GPUs with Tensor Parallel (TP).
12
+ Running parameters for this environment are provided below. For other parallelism strategies, please refer to updates of official documents.
13
+
14
+
15
+ ### Tensor Parallelism
16
+
17
+ Here is a sample launch command with TP=8:
18
+
19
+ ``` bash
20
+
21
+ vllm serve $MODEL_PATH \
22
+ --served-model-name kimi-k2-thinking \
23
+ --trust-remote-code \
24
+ --tensor-parallel-size 8 \
25
+ --enable-auto-tool-choice \
26
+ --max-num-batched-tokens 32768 \
27
+ --tool-call-parser kimi_k2 \
28
+ --reasoning-parser kimi_k2
29
+ ```
30
+
31
+ **Key parameter notes:**
32
+ - `--enable-auto-tool-choice`: Required when enabling tool usage.
33
+ - `--tool-call-parser kimi_k2`: Required when enabling tool usage.
34
+ - `--reasoning-parser kimi_k2`: Required for correctly processing reasoning content.
35
+ - `--max-num-batched-tokens 32768`: Using chunk prefill to reduce peak memory usage.
36
+
37
+
38
+ ## SGLang Deployment
39
+
40
+ Similarly, here are the examples using TP in SGLang for Deployment.
41
+
42
+ ### Tensor Parallelism
43
+
44
+ Here is the simple example code to run TP8 on H200 in a sigle node:
45
+
46
+ ``` bash
47
+ python -m sglang.launch_server --model-path $MODEL_PATH --tp 8 --trust-remote-code --tool-call-parser kimi_k2 --reasoning-parser kimi_k2
48
+ ```
49
+
50
+ **Key parameter notes:**
51
+ - `--tool-call-parser kimi_k2`: Required when enabling tool usage.
52
+ - `--reasoning-parser kimi_k2`: Required for correctly processing reasoning content.
53
+
54
+
55
+ ## KTransformers Deployment
56
+
57
+ ### KTransformers+SGLang Inference Deployment
58
+
59
+ Launch with KTransformers + SGLang for CPU+GPU heterogeneous inference:
60
+
61
+ ``` bash
62
+ python -m sglang.launch_server \
63
+ --model path/to/Kimi-K2-Thinking/ \
64
+ --kt-amx-weight-path path/to/Kimi-K2-Instruct-CPU-weight/ \
65
+ --kt-cpuinfer 56 \
66
+ --kt-threadpool-count 2 \
67
+ --kt-num-gpu-experts 200 \
68
+ --kt-amx-method AMXINT4 \
69
+ --trust-remote-code \
70
+ --mem-fraction-static 0.98 \
71
+ --chunked-prefill-size 4096 \
72
+ --max-running-requests 37 \
73
+ --max-total-tokens 37000 \
74
+ --enable-mixed-chunk \
75
+ --tensor-parallel-size 8 \
76
+ --enable-p2p-check \
77
+ --disable-shared-experts-fusion
78
+ ```
79
+
80
+ Achieves 577.74 tokens/s Prefill and 45.91 tokens/s Decode (37-way concurrency) on 8× NVIDIA L20 + 2× Intel 6454S.
81
+
82
+ More details: https://github.com/kvcache-ai/ktransformers/blob/main/doc/en/Kimi-K2-Thinking.md
83
+
84
+
85
+ ### KTransformers+LLaMA-Factory Fine-tuning Deployment
86
+
87
+ You can use below command to run LoRA SFT with KT+llamafactory.
88
+
89
+ ``` bash
90
+ # For LoRA SFT
91
+ USE_KT=1 llamafactory-cli train examples/train_lora/kimik2_lora_sft_kt.yaml
92
+ # For Chat with model after LoRA SFT
93
+ llamafactory-cli chat examples/inference/kimik2_lora_sft_kt.yaml
94
+ # For API with model after LoRA SFT
95
+ llamafactory-cli api examples/inference/kimik2_lora_sft_kt.yaml
96
+ ```
97
+
98
+ This achieves end-to-end LoRA SFT Throughput: 46.55 token/s on 2× NVIDIA 4090 + Intel 8488C with 1.97T RAM and 200G swap memory.
99
+
100
+ More details refer to https://github.com/kvcache-ai/ktransformers/blob/main/doc/en/SFT_Installation_Guide_KimiK2.md.
101
+
102
+ ## Others
103
+
104
+ Kimi-K2-Thinking reuses the `DeepSeekV3CausalLM` architecture and convert it's weight into proper shape to save redevelopment effort. To let inference engines distinguish it from DeepSeek-V3 and apply the best optimizations, we set `"model_type": "kimi_k2"` in `config.json`.
105
+
106
+ If you are using a framework that is not on the recommended list, you can still run the model by manually changing `model_type` to "deepseek_v3" in `config.json` as a temporary workaround. You may need to manually parse tool calls in case no tool call parser is available in your framework.
docs/tool_call_guidance.md ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Tool Calling
2
+ To enable the tool calling feature, you may need to set certain tool calling parser options when starting the service. See [deploy_guidance](./deploy_guidance.md) for details.
3
+ In Kimi-K2, a tool calling process includes:
4
+ - Passing function descriptions to Kimi-K2
5
+ - Kimi-K2 decides to make a function call and returns the necessary information for the function call to the user
6
+ - The user performs the function call, collects the call results, and passes the function call results to Kimi-K2
7
+ - Kimi-K2 continues to generate content based on the function call results until the model believes it has obtained sufficient information to respond to the user
8
+
9
+ ### Preparing Tools
10
+ Suppose we have a function `get_weather` that can query the weather conditions in real-time.
11
+ This function accepts a city name as a parameter and returns the weather conditions. We need to prepare a structured description for it so that Kimi-K2 can understand its functionality.
12
+
13
+ ```python
14
+ def get_weather(city):
15
+ return {"weather": "Sunny"}
16
+
17
+ # Collect the tool descriptions in tools
18
+ tools = [{
19
+ "type": "function",
20
+ "function": {
21
+ "name": "get_weather",
22
+ "description": "Get weather information. Call this tool when the user needs to get weather information",
23
+ "parameters": {
24
+ "type": "object",
25
+ "required": ["city"],
26
+ "properties": {
27
+ "city": {
28
+ "type": "string",
29
+ "description": "City name",
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }]
35
+
36
+ # Tool name->object mapping for easy calling later
37
+ tool_map = {
38
+ "get_weather": get_weather
39
+ }
40
+ ```
41
+ ### Chat with tools
42
+ We use `openai.OpenAI` to send messages to Kimi-K2 along with tool descriptions. Kimi-K2 will autonomously decide whether to use and how to use the provided tools.
43
+ If Kimi-K2 believes a tool call is needed, it will return a result with `finish_reason='tool_calls'`. At this point, the returned result includes the tool call information.
44
+ After calling tools with the provided information, we then need to append the tool call results to the chat history and continue calling Kimi-K2.
45
+ Kimi-K2 may need to call tools multiple times until the model believes the current results can answer the user's question. We should check `finish_reason` until it is not `tool_calls`.
46
+
47
+ The results obtained by the user after calling the tools should be added to `messages` with `role='tool'`.
48
+
49
+ ```python
50
+ import json
51
+ from openai import OpenAI
52
+ model_name='moonshotai/Kimi-K2-Thinking'
53
+ client = OpenAI(base_url=endpoint,
54
+ api_key='xxx')
55
+
56
+ messages = [
57
+ {"role": "user", "content": "What's the weather like in Beijing today? Let's check using the tool."}
58
+ ]
59
+ finish_reason = None
60
+ while finish_reason is None or finish_reason == "tool_calls":
61
+ completion = client.chat.completions.create(
62
+ model=model_name,
63
+ messages=messages,
64
+ temperature=0.3,
65
+ tools=tools,
66
+ tool_choice="auto",
67
+ )
68
+ choice = completion.choices[0]
69
+ finish_reason = choice.finish_reason
70
+ # Note: The finish_reason when tool calls end may vary across different engines, so this condition check needs to be adjusted accordingly
71
+ if finish_reason == "tool_calls":
72
+ messages.append(choice.message)
73
+ for tool_call in choice.message.tool_calls:
74
+ tool_call_name = tool_call.function.name
75
+ tool_call_arguments = json.loads(tool_call.function.arguments)
76
+ tool_function = tool_map[tool_call_name]
77
+ tool_result = tool_function(tool_call_arguments)
78
+ print("tool_result", tool_result)
79
+
80
+ messages.append({
81
+ "role": "tool",
82
+ "tool_call_id": tool_call.id,
83
+ "name": tool_call_name,
84
+ "content": json.dumps(tool_result),
85
+ })
86
+ print('-' * 100)
87
+ print(choice.message.content)
88
+ ```
89
+ ### Tool Calling in Streaming Mode
90
+ Tool calling can also be used in streaming mode. In this case, we need to collect the tool call information returned in the stream until we have a complete tool call. Please refer to the code below:
91
+
92
+ ```python
93
+ messages = [
94
+ {"role": "user", "content": "What's the weather like in Beijing today? Let's check using the tool."}
95
+ ]
96
+ finish_reason = None
97
+ msg = ''
98
+ while finish_reason is None or finish_reason == "tool_calls":
99
+ completion = client.chat.completions.create(
100
+ model=model_name,
101
+ messages=messages,
102
+ temperature=0.3,
103
+ tools=tools,
104
+ tool_choice="auto",
105
+ stream=True
106
+ )
107
+ tool_calls = []
108
+ for chunk in completion:
109
+ delta = chunk.choices[0].delta
110
+ if delta.content:
111
+ msg += delta.content
112
+ if delta.tool_calls:
113
+ for tool_call_chunk in delta.tool_calls:
114
+ if tool_call_chunk.index is not None:
115
+ # Extend the tool_calls list
116
+ while len(tool_calls) <= tool_call_chunk.index:
117
+ tool_calls.append({
118
+ "id": "",
119
+ "type": "function",
120
+ "function": {
121
+ "name": "",
122
+ "arguments": ""
123
+ }
124
+ })
125
+
126
+ tc = tool_calls[tool_call_chunk.index]
127
+
128
+ if tool_call_chunk.id:
129
+ tc["id"] += tool_call_chunk.id
130
+ if tool_call_chunk.function.name:
131
+ tc["function"]["name"] += tool_call_chunk.function.name
132
+ if tool_call_chunk.function.arguments:
133
+ tc["function"]["arguments"] += tool_call_chunk.function.arguments
134
+
135
+ finish_reason = chunk.choices[0].finish_reason
136
+ # Note: The finish_reason when tool calls end may vary across different engines, so this condition check needs to be adjusted accordingly
137
+ if finish_reason == "tool_calls":
138
+ for tool_call in tool_calls:
139
+ tool_call_name = tool_call['function']['name']
140
+ tool_call_arguments = json.loads(tool_call['function']['arguments'])
141
+ tool_function = tool_map[tool_call_name]
142
+ tool_result = tool_function(tool_call_arguments)
143
+ messages.append({
144
+ "role": "tool",
145
+ "tool_call_id": tool_call['id'],
146
+ "name": tool_call_name,
147
+ "content": json.dumps(tool_result),
148
+ })
149
+ # The text generated by the tool call is not the final version, reset msg
150
+ msg = ''
151
+
152
+ print(msg)
153
+ ```
154
+ ### Manually Parsing Tool Calls
155
+ The tool call requests generated by Kimi-K2 can also be parsed manually, which is especially useful when the service you are using does not provide a tool-call parser.
156
+ The tool call requests generated by Kimi-K2 are wrapped by `<|tool_calls_section_begin|>` and `<|tool_calls_section_end|>`,
157
+ with each tool call wrapped by `<|tool_call_begin|>` and `<|tool_call_end|>`. The tool ID and arguments are separated by `<|tool_call_argument_begin|>`.
158
+ The format of the tool ID is `functions.{func_name}:{idx}`, from which we can parse the function name.
159
+
160
+ Based on the above rules, we can directly post request to the completions interface and manually parse tool calls.
161
+
162
+ ```python
163
+ import requests
164
+ from transformers import AutoTokenizer
165
+ messages = [
166
+ {"role": "user", "content": "What's the weather like in Beijing today? Let's check using the tool."}
167
+ ]
168
+ msg = ''
169
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
170
+ while True:
171
+ text = tokenizer.apply_chat_template(
172
+ messages,
173
+ tokenize=False,
174
+ tools=tools,
175
+ add_generation_prompt=True,
176
+ )
177
+ payload = {
178
+ "model": model_name,
179
+ "prompt": text,
180
+ "max_tokens": 512
181
+ }
182
+ response = requests.post(
183
+ f"{endpoint}/completions",
184
+ headers={"Content-Type": "application/json"},
185
+ json=payload,
186
+ stream=False,
187
+ )
188
+ raw_out = response.json()
189
+
190
+ raw_output = raw_out["choices"][0]["text"]
191
+ tool_calls = extract_tool_call_info(raw_output)
192
+ if len(tool_calls) == 0:
193
+ # No tool calls
194
+ msg = raw_output
195
+ break
196
+ else:
197
+ for tool_call in tool_calls:
198
+ tool_call_name = tool_call['function']['name']
199
+ tool_call_arguments = json.loads(tool_call['function']['arguments'])
200
+ tool_function = tool_map[tool_call_name]
201
+ tool_result = tool_function(tool_call_arguments)
202
+
203
+ messages.append({
204
+ "role": "tool",
205
+ "tool_call_id": tool_call['id'],
206
+ "name": tool_call_name,
207
+ "content": json.dumps(tool_result),
208
+ })
209
+ print('-' * 100)
210
+ print(msg)
211
+ ```
212
+ Here, `extract_tool_call_info` parses the model output and returns the model call information. A simple implementation would be:
213
+ ```python
214
+ def extract_tool_call_info(tool_call_rsp: str):
215
+ if '<|tool_calls_section_begin|>' not in tool_call_rsp:
216
+ # No tool calls
217
+ return []
218
+ import re
219
+ pattern = r"<\|tool_calls_section_begin\|>(.*?)<\|tool_calls_section_end\|>"
220
+
221
+ tool_calls_sections = re.findall(pattern, tool_call_rsp, re.DOTALL)
222
+
223
+ # Extract multiple tool calls
224
+ func_call_pattern = r"<\|tool_call_begin\|>\s*(?P<tool_call_id>[\w\.]+:\d+)\s*<\|tool_call_argument_begin\|>\s*(?P<function_arguments>.*?)\s*<\|tool_call_end\|>"
225
+ tool_calls = []
226
+ for match in re.findall(func_call_pattern, tool_calls_sections[0], re.DOTALL):
227
+ function_id, function_args = match
228
+ # function_id: functions.get_weather:0
229
+ function_name = function_id.split('.')[1].split(':')[0]
230
+ tool_calls.append(
231
+ {
232
+ "id": function_id,
233
+ "type": "function",
234
+ "function": {
235
+ "name": function_name,
236
+ "arguments": function_args
237
+ }
238
+ }
239
+ )
240
+ return tool_calls
241
+ ```
242
+
243
+ ## FAQ
244
+
245
+ #### Q1: I received special tokens like '<|tool_call_begin|>' in the 'content' field instead of a normal tool_call.
246
+
247
+ This indicates a tool-call crash, which most often occurs in multi-turn tool-calling scenarios due to incorrect tool-call ID. K2 expects the ID to follow the format `functions.func_name:idx`, where `functions` is a fixed string; `func_name` is the actual function name, like `get_weather`, and `idx` is a global counter that starts at 0 and increments with each function invocation.
248
+ Please check all tool-call IDs in the message list.
249
+
250
+
251
+ #### Q2: My tool-call ID is incorrect—how can I fix it?
252
+
253
+ First, make sure your code and chat template are up to date with the latest version from the Hugging Face repo.
254
+ If you're using vLLM or SGLang and they are generating random tool-call IDs, upgrade them to the latest release. For other frameworks, you must either parse the tool-call ID from the model output and set it correctly in the server-side response, or rewrite every tool-call ID according to the rules above on the client side before sending the messages to Kimi K2.
255
+
256
+ #### Q3: My tool call id is correct, but I still get crashed in multiturn tool call.
257
+
258
+ Please describe your situation in the [discussion](https://huggingface.co/moonshotai/Kimi-K2-Thinking/discussions)
figures/Base-Evaluation.png ADDED

Git LFS Details

  • SHA256: d1d3ee49430417c17326c9def19264756a3bc0b0aa001e598d0e0d751ebf93f8
  • Pointer size: 131 Bytes
  • Size of remote file: 245 kB
figures/banner.png ADDED

Git LFS Details

  • SHA256: 380b39db25a6842cedaabad354a0a4929b617835094800124bba756c3b0e98f8
  • Pointer size: 131 Bytes
  • Size of remote file: 292 kB
figures/kimi-logo.png ADDED

Git LFS Details

  • SHA256: 4a80f64242bf907940765adc7bcf340c28dd83334b07c5503792a26495d1933b
  • Pointer size: 130 Bytes
  • Size of remote file: 88 kB
generation_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_length": 262144,
3
+ "eos_token_id": 163586
4
+ }
model-00001-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b95d261d31fe9ecc1d0cd6c3ad6fb52191b689475a0acb5e17fa14703c416d4
3
+ size 995002080
model-00002-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1fb5ef3388d02b6ddb04ee8126b43794cb9730ee62757917126c3c3bd5615432
3
+ size 9808995784
model-00003-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b05696985be2980de1ef6e25288c86cf8527b2485b7806b49f6478ad0f22e47e
3
+ size 9808995784
model-00004-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e411c8ba5b1141e291cfec0ab8575abdc66405b7180346e2bcf0922e6ce03b70
3
+ size 9808995784
model-00005-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2fb30da4bc8ac8714e2505bc0f408f2de066fd1d3acf496565970995d1571d9a
3
+ size 9808995784
model-00006-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eace8de10915e5f79f611eae90b1f503fe74c02b8e5b172e76c44df089d5efee
3
+ size 9808995784
model-00007-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:055b814232e4316d2d91263cefd93c812877086c257d92ac5ab824173103be5e
3
+ size 9808995784
model-00008-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:af87dadc5413a8fcf30204a37acfff9df666df557aa5ef47ec311777a76f0e15
3
+ size 9808995784
model-00009-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3180accd136cce3bc614d89a28d799b1a6bcca998ebf6b663b0cc2043718b392
3
+ size 9808995784
model-00010-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f3885c59a40662088e37b4bee49cdd33428cd40ca18f165405cda7806f4931de
3
+ size 9808995784
model-00011-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb7591448d508cccba625d4d02affd4f9a2c92517728e3bf2ae5e51214f31ac9
3
+ size 9808999256
model-00012-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:766eb3b51f5bf5aeb99f6a7c61f83b56516dc9fcc2b94a7cb9b999b23e7215dd
3
+ size 9808999256
model-00013-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca1661d9843460f63870282cbbe22a68768a7d7bddf5a983a430249ed8e4724a
3
+ size 9808999256
model-00014-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:855acdcee579c79e463c9e3f2dd8a35b7ed0c4109c387e4a5780987e7c98d6a3
3
+ size 9808999256
model-00015-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7107908272365b31008c30e10f0b90f64e8fdc328ad7ba573c9a0eeea59bb550
3
+ size 9808999256
model-00016-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca84d3d21a5fcde572ea00447a30fb6174107f9dcb13c994ba6540717056620c
3
+ size 9808999256
model-00017-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2f84512dd980f1c23b7ea2b81cd98cca4deae5df175f3903a4110c4573b75173
3
+ size 9808999256
model-00018-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:590d7f85ea053663cb7286dfb619f7a7d3b21ff69bd955f72c8014ca2236b643
3
+ size 9808999256
model-00019-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6695243bd3ce55705e384ef51be993ba6b881ddbff841510be7937141b05761d
3
+ size 9808999256
model-00020-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e84f956e805f92ba224da76e5adc8f4303e5b66b7ac82aa2b793517c0f7bb1a3
3
+ size 9808999256
model-00021-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ed0c3abc1898eb36cacdcf152f6d22f244dd8f95ec3e597a406575ef936e12c
3
+ size 9808999256
model-00022-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:96ce2ddc9ff80d522e57437c123147066593e429523e1a24b0e5b134b8af5030
3
+ size 9808999256
model-00023-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc62e7fcd8184cd45c046e2f92f2abde6009c160b7b0cd57da536af38e66d771
3
+ size 9808999256
model-00024-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bdc950d90d49057ba81e45ac440ac6ebd187701b43705d3b5a20d67ba0128d9b
3
+ size 9808999256
model-00025-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb792b1d2591fda0a7b0ff0e5bf18841a2b1cd09ae075ae027923818f7bf1b5f
3
+ size 9808999256
model-00026-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a16fe7a9816d71e5927fc93e229aef8821a37ca2382700ef9878c4b72cb9ee34
3
+ size 9808999256
model-00027-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:149b930f77cad67a727fe66333ac16dc834300d6cc7a23a0df74c286c37f972c
3
+ size 9808999256
model-00028-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:10ef5c61dacb9c0390dd5e783a82d10bbaf25b1ff5d1cb2f1bbfe0a59b14d0cd
3
+ size 9808999256
model-00029-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f694289ad0f5c42dbcbcec326a8d2286f3b989e8c72a23c79cab8145ce4411d7
3
+ size 9808999256
model-00030-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3478d49b25e9b1964e55c095f87acdc742268ff1c343863b1b2c36d1a08cd941
3
+ size 9808999256
model-00031-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a537d379ca0382d20eb4ba04a19ffbb53d5387fc3c828cfb597135c4b61fc9d8
3
+ size 9808999256
model-00032-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4cd98998e2379b38f7ac412df3a1a129e1620cd3c76d97fa0366d92cad984c02
3
+ size 9808999256
model-00033-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45a2dcd2e1ffd907e820d2721bfa53be572c0048d8c6d1a1c4de7039daacea91
3
+ size 9808999256
model-00034-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1cda7176b5651e3a3be960058f2e9ccdb965680c469a241b9169bcca7e861abf
3
+ size 9808999256
model-00035-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8fcd19675824aa0741579ecf437ffe37f6ee17a2064f58fb196f5b20bd587161
3
+ size 9808999256
model-00036-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3735102c0af02bf52a566bbe18a93622779eeec6329eec1fc87033d4a01dbe05
3
+ size 9808999256
model-00037-of-000062.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:562593af7257c91cdfc5662ab1c46d3f7bba61ffe0d233c9958f70e357c28466
3
+ size 9808999256