Update minimized Kimi-K2.5 MXFP4 model
Browse files- .gitattributes +1 -0
- README.md +6 -5
- chat_template.jinja +1 -5
- config.json +109 -65
- docs/deploy_guidance.md +82 -0
- figures/demo_video.mp4 +3 -0
- figures/kimi-logo.png +0 -0
- model-00001-of-00007.safetensors +3 -0
- model-00002-of-00007.safetensors +3 -0
- model-00003-of-00007.safetensors +3 -0
- model-00004-of-00007.safetensors +3 -0
- model-00005-of-00007.safetensors +3 -0
- model-00006-of-00007.safetensors +3 -0
- model-00007-of-00007.safetensors +3 -0
- model.safetensors.index.json +3 -0
- quark_profile.yaml +78 -0
- tokenization_kimi.py +1 -5
.gitattributes
CHANGED
|
@@ -34,3 +34,4 @@ saved_model/**/* 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
|
|
|
|
|
|
| 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/demo_video.mp4 filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -16,8 +16,9 @@ base_model:
|
|
| 16 |
- **Operating System(s):** Linux
|
| 17 |
- **Inference Engine:** [vLLM](https://docs.vllm.ai/en/latest/)
|
| 18 |
- **Model Optimizer:** [AMD-Quark](https://quark.docs.amd.com/latest/index.html) (V0.11.1)
|
| 19 |
-
- **
|
| 20 |
-
- **
|
|
|
|
| 21 |
- **Calibration Dataset:** [Pile](https://huggingface.co/datasets/mit-han-lab/pile-val-backup)
|
| 22 |
|
| 23 |
This model was built with Kimi-K2.5 model by applying [AMD-Quark](https://quark.docs.amd.com/latest/index.html) for MXFP4 quantization.
|
|
@@ -29,7 +30,7 @@ The model was quantized from [moonshotai/Kimi-K2.5](https://huggingface.co/moons
|
|
| 29 |
**Quantization scripts:**
|
| 30 |
```
|
| 31 |
cd Quark/examples/torch/language_modeling/llm_ptq/
|
| 32 |
-
exclude_layers="*self_attn* *mlp.gate *lm_head *
|
| 33 |
|
| 34 |
python quantize_quark.py \
|
| 35 |
--model_dir moonshotai/Kimi-K2.5 \
|
|
@@ -65,9 +66,9 @@ The model was evaluated on GSM8K benchmarks.
|
|
| 65 |
</td>
|
| 66 |
<td>94.09
|
| 67 |
</td>
|
| 68 |
-
<td>93.
|
| 69 |
</td>
|
| 70 |
-
<td>
|
| 71 |
</td>
|
| 72 |
</tr>
|
| 73 |
</table>
|
|
|
|
| 16 |
- **Operating System(s):** Linux
|
| 17 |
- **Inference Engine:** [vLLM](https://docs.vllm.ai/en/latest/)
|
| 18 |
- **Model Optimizer:** [AMD-Quark](https://quark.docs.amd.com/latest/index.html) (V0.11.1)
|
| 19 |
+
- **Quantized layers:** `layers.0.mlp`, `experts` and `shared_experts`
|
| 20 |
+
- **Weight quantization:** OCP MXFP4, Static
|
| 21 |
+
- **Activation quantization:** OCP MXFP4, Dynamic
|
| 22 |
- **Calibration Dataset:** [Pile](https://huggingface.co/datasets/mit-han-lab/pile-val-backup)
|
| 23 |
|
| 24 |
This model was built with Kimi-K2.5 model by applying [AMD-Quark](https://quark.docs.amd.com/latest/index.html) for MXFP4 quantization.
|
|
|
|
| 30 |
**Quantization scripts:**
|
| 31 |
```
|
| 32 |
cd Quark/examples/torch/language_modeling/llm_ptq/
|
| 33 |
+
exclude_layers="*self_attn* *mlp.gate *lm_head *mm_projector* *vision_tower*"
|
| 34 |
|
| 35 |
python quantize_quark.py \
|
| 36 |
--model_dir moonshotai/Kimi-K2.5 \
|
|
|
|
| 66 |
</td>
|
| 67 |
<td>94.09
|
| 68 |
</td>
|
| 69 |
+
<td>93.1
|
| 70 |
</td>
|
| 71 |
+
<td>98.95%
|
| 72 |
</td>
|
| 73 |
</tr>
|
| 74 |
</table>
|
chat_template.jinja
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
{%- elif c is not none -%}
|
| 6 |
{% for content in c -%}
|
| 7 |
{% if content['type'] == 'image' or content['type'] == 'image_url' -%}
|
| 8 |
-
<|
|
| 9 |
{% elif content['type'] == 'video' or content['type']== 'video_url'-%}
|
| 10 |
<|kimi_k25_video_placeholder|>
|
| 11 |
{% else -%}
|
|
@@ -57,10 +57,6 @@
|
|
| 57 |
<|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>
|
| 58 |
{%- endif -%}
|
| 59 |
{%- endif -%}
|
| 60 |
-
|
| 61 |
-
{%- if messages|length == 0 or messages[0]['role'] != 'system' -%}
|
| 62 |
-
<|im_system|>system<|im_middle|>You are Kimi, an AI assistant created by Moonshot AI.<|im_end|>
|
| 63 |
-
{%- endif -%}
|
| 64 |
|
| 65 |
{%- for message in hist_msgs -%}
|
| 66 |
{{set_roles(message)}}
|
|
|
|
| 5 |
{%- elif c is not none -%}
|
| 6 |
{% for content in c -%}
|
| 7 |
{% if content['type'] == 'image' or content['type'] == 'image_url' -%}
|
| 8 |
+
<|media_begin|>image<|media_content|><|media_pad|><|media_end|>
|
| 9 |
{% elif content['type'] == 'video' or content['type']== 'video_url'-%}
|
| 10 |
<|kimi_k25_video_placeholder|>
|
| 11 |
{% else -%}
|
|
|
|
| 57 |
<|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>
|
| 58 |
{%- endif -%}
|
| 59 |
{%- endif -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
{%- for message in hist_msgs -%}
|
| 62 |
{{set_roles(message)}}
|
config.json
CHANGED
|
@@ -14,6 +14,111 @@
|
|
| 14 |
"media_placeholder_token_id": 163605,
|
| 15 |
"model_type": "kimi_k25",
|
| 16 |
"pad_token_id": 163839,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
"text_config": {
|
| 18 |
"_name_or_path": "",
|
| 19 |
"add_cross_attention": false,
|
|
@@ -69,16 +174,16 @@
|
|
| 69 |
"moe_intermediate_size": 2048,
|
| 70 |
"moe_layer_freq": 1,
|
| 71 |
"n_group": 1,
|
| 72 |
-
"n_routed_experts":
|
| 73 |
"n_shared_experts": 1,
|
| 74 |
"no_repeat_ngram_size": 0,
|
| 75 |
"norm_topk_prob": true,
|
| 76 |
-
"num_attention_heads":
|
| 77 |
"num_beam_groups": 1,
|
| 78 |
"num_beams": 1,
|
| 79 |
"num_experts_per_tok": 8,
|
| 80 |
"num_hidden_layers": 4,
|
| 81 |
-
"num_key_value_heads":
|
| 82 |
"num_nextn_predict_layers": 0,
|
| 83 |
"num_return_sequences": 1,
|
| 84 |
"output_attentions": false,
|
|
@@ -154,67 +259,6 @@
|
|
| 154 |
"vt_hidden_size": 1152,
|
| 155 |
"vt_intermediate_size": 4304,
|
| 156 |
"vt_num_attention_heads": 16,
|
| 157 |
-
"vt_num_hidden_layers":
|
| 158 |
-
},
|
| 159 |
-
"quantization_config": {
|
| 160 |
-
"global_quant_config": {
|
| 161 |
-
"input_tensors": {
|
| 162 |
-
"dtype": "fp4",
|
| 163 |
-
"is_dynamic": true,
|
| 164 |
-
"qscheme": "per_group",
|
| 165 |
-
"ch_axis": -1,
|
| 166 |
-
"group_size": 32,
|
| 167 |
-
"symmetric": null,
|
| 168 |
-
"round_method": "half_even",
|
| 169 |
-
"scale_type": "float",
|
| 170 |
-
"scale_format": "e8m0",
|
| 171 |
-
"scale_calculation_mode": "even",
|
| 172 |
-
"mx_element_dtype": null,
|
| 173 |
-
"observer_cls": "PerBlockMXObserver",
|
| 174 |
-
"is_scale_quant": false
|
| 175 |
-
},
|
| 176 |
-
"output_tensors": null,
|
| 177 |
-
"weight": {
|
| 178 |
-
"dtype": "fp4",
|
| 179 |
-
"is_dynamic": false,
|
| 180 |
-
"qscheme": "per_group",
|
| 181 |
-
"ch_axis": -1,
|
| 182 |
-
"group_size": 32,
|
| 183 |
-
"symmetric": null,
|
| 184 |
-
"round_method": "half_even",
|
| 185 |
-
"scale_type": "float",
|
| 186 |
-
"scale_format": "e8m0",
|
| 187 |
-
"scale_calculation_mode": "even",
|
| 188 |
-
"mx_element_dtype": null,
|
| 189 |
-
"observer_cls": "PerBlockMXObserver",
|
| 190 |
-
"is_scale_quant": false
|
| 191 |
-
},
|
| 192 |
-
"bias": null,
|
| 193 |
-
"target_device": null
|
| 194 |
-
},
|
| 195 |
-
"exclude": [
|
| 196 |
-
"lm_head",
|
| 197 |
-
"re:.*self_attn.*",
|
| 198 |
-
"re:.*shared_experts.*",
|
| 199 |
-
"re:.*mlp\\.(gate|up|gate_up|down)_proj.*",
|
| 200 |
-
"re:mm_projector.*",
|
| 201 |
-
"re:vision_tower.*"
|
| 202 |
-
],
|
| 203 |
-
"algo_config": null,
|
| 204 |
-
"softmax_quant_spec": null,
|
| 205 |
-
"quant_method": "quark",
|
| 206 |
-
"layer_type_quant_config": {},
|
| 207 |
-
"layer_quant_config": {},
|
| 208 |
-
"kv_cache_quant_config": {},
|
| 209 |
-
"kv_cache_post_rope": false,
|
| 210 |
-
"quant_mode": "eager_mode",
|
| 211 |
-
"version": "0.11+4a34634b4a",
|
| 212 |
-
"export": {
|
| 213 |
-
"kv_cache_group": [],
|
| 214 |
-
"min_kv_scale": 0.0,
|
| 215 |
-
"pack_method": "reorder",
|
| 216 |
-
"weight_format": "real_quantized",
|
| 217 |
-
"weight_merge_groups": null
|
| 218 |
-
}
|
| 219 |
}
|
| 220 |
}
|
|
|
|
| 14 |
"media_placeholder_token_id": 163605,
|
| 15 |
"model_type": "kimi_k25",
|
| 16 |
"pad_token_id": 163839,
|
| 17 |
+
"quantization_config": {
|
| 18 |
+
"algo_config": null,
|
| 19 |
+
"exclude": [
|
| 20 |
+
"language_model.lm_head",
|
| 21 |
+
"language_model.model.layers.0.self_attn.kv_a_proj_with_mqa",
|
| 22 |
+
"language_model.model.layers.0.self_attn.kv_b_proj",
|
| 23 |
+
"language_model.model.layers.0.self_attn.o_proj",
|
| 24 |
+
"language_model.model.layers.0.self_attn.q_a_proj",
|
| 25 |
+
"language_model.model.layers.0.self_attn.q_b_proj",
|
| 26 |
+
"language_model.model.layers.1.mlp.gate",
|
| 27 |
+
"language_model.model.layers.1.self_attn.kv_a_proj_with_mqa",
|
| 28 |
+
"language_model.model.layers.1.self_attn.kv_b_proj",
|
| 29 |
+
"language_model.model.layers.1.self_attn.o_proj",
|
| 30 |
+
"language_model.model.layers.1.self_attn.q_a_proj",
|
| 31 |
+
"language_model.model.layers.1.self_attn.q_b_proj",
|
| 32 |
+
"language_model.model.layers.2.mlp.gate",
|
| 33 |
+
"language_model.model.layers.2.self_attn.kv_a_proj_with_mqa",
|
| 34 |
+
"language_model.model.layers.2.self_attn.kv_b_proj",
|
| 35 |
+
"language_model.model.layers.2.self_attn.o_proj",
|
| 36 |
+
"language_model.model.layers.2.self_attn.q_a_proj",
|
| 37 |
+
"language_model.model.layers.2.self_attn.q_b_proj",
|
| 38 |
+
"language_model.model.layers.3.mlp.gate",
|
| 39 |
+
"language_model.model.layers.3.self_attn.kv_a_proj_with_mqa",
|
| 40 |
+
"language_model.model.layers.3.self_attn.kv_b_proj",
|
| 41 |
+
"language_model.model.layers.3.self_attn.o_proj",
|
| 42 |
+
"language_model.model.layers.3.self_attn.q_a_proj",
|
| 43 |
+
"language_model.model.layers.3.self_attn.q_b_proj",
|
| 44 |
+
"mm_projector.proj.0",
|
| 45 |
+
"mm_projector.proj.2",
|
| 46 |
+
"vision_tower.encoder.blocks.0.mlp.fc0",
|
| 47 |
+
"vision_tower.encoder.blocks.0.mlp.fc1",
|
| 48 |
+
"vision_tower.encoder.blocks.0.norm0",
|
| 49 |
+
"vision_tower.encoder.blocks.0.norm1",
|
| 50 |
+
"vision_tower.encoder.blocks.0.wo",
|
| 51 |
+
"vision_tower.encoder.blocks.0.wqkv",
|
| 52 |
+
"vision_tower.encoder.blocks.1.mlp.fc0",
|
| 53 |
+
"vision_tower.encoder.blocks.1.mlp.fc1",
|
| 54 |
+
"vision_tower.encoder.blocks.1.norm0",
|
| 55 |
+
"vision_tower.encoder.blocks.1.norm1",
|
| 56 |
+
"vision_tower.encoder.blocks.1.wo",
|
| 57 |
+
"vision_tower.encoder.blocks.1.wqkv",
|
| 58 |
+
"vision_tower.encoder.blocks.2.mlp.fc0",
|
| 59 |
+
"vision_tower.encoder.blocks.2.mlp.fc1",
|
| 60 |
+
"vision_tower.encoder.blocks.2.norm0",
|
| 61 |
+
"vision_tower.encoder.blocks.2.norm1",
|
| 62 |
+
"vision_tower.encoder.blocks.2.wo",
|
| 63 |
+
"vision_tower.encoder.blocks.2.wqkv",
|
| 64 |
+
"vision_tower.encoder.blocks.3.mlp.fc0",
|
| 65 |
+
"vision_tower.encoder.blocks.3.mlp.fc1",
|
| 66 |
+
"vision_tower.encoder.blocks.3.norm0",
|
| 67 |
+
"vision_tower.encoder.blocks.3.norm1",
|
| 68 |
+
"vision_tower.encoder.blocks.3.wo",
|
| 69 |
+
"vision_tower.encoder.blocks.3.wqkv"
|
| 70 |
+
],
|
| 71 |
+
"export": {
|
| 72 |
+
"kv_cache_group": [],
|
| 73 |
+
"min_kv_scale": 0.0,
|
| 74 |
+
"pack_method": "reorder",
|
| 75 |
+
"weight_format": "real_quantized",
|
| 76 |
+
"weight_merge_groups": null
|
| 77 |
+
},
|
| 78 |
+
"global_quant_config": {
|
| 79 |
+
"bias": null,
|
| 80 |
+
"input_tensors": {
|
| 81 |
+
"ch_axis": -1,
|
| 82 |
+
"dtype": "fp4",
|
| 83 |
+
"group_size": 32,
|
| 84 |
+
"is_dynamic": true,
|
| 85 |
+
"is_scale_quant": false,
|
| 86 |
+
"mx_element_dtype": null,
|
| 87 |
+
"observer_cls": "PerBlockMXObserver",
|
| 88 |
+
"qscheme": "per_group",
|
| 89 |
+
"round_method": "half_even",
|
| 90 |
+
"scale_calculation_mode": "even",
|
| 91 |
+
"scale_format": "e8m0",
|
| 92 |
+
"scale_type": "float",
|
| 93 |
+
"symmetric": null
|
| 94 |
+
},
|
| 95 |
+
"output_tensors": null,
|
| 96 |
+
"target_device": null,
|
| 97 |
+
"weight": {
|
| 98 |
+
"ch_axis": -1,
|
| 99 |
+
"dtype": "fp4",
|
| 100 |
+
"group_size": 32,
|
| 101 |
+
"is_dynamic": false,
|
| 102 |
+
"is_scale_quant": false,
|
| 103 |
+
"mx_element_dtype": null,
|
| 104 |
+
"observer_cls": "PerBlockMXObserver",
|
| 105 |
+
"qscheme": "per_group",
|
| 106 |
+
"round_method": "half_even",
|
| 107 |
+
"scale_calculation_mode": "even",
|
| 108 |
+
"scale_format": "e8m0",
|
| 109 |
+
"scale_type": "float",
|
| 110 |
+
"symmetric": null
|
| 111 |
+
}
|
| 112 |
+
},
|
| 113 |
+
"kv_cache_post_rope": false,
|
| 114 |
+
"kv_cache_quant_config": {},
|
| 115 |
+
"layer_quant_config": {},
|
| 116 |
+
"layer_type_quant_config": {},
|
| 117 |
+
"quant_method": "quark",
|
| 118 |
+
"quant_mode": "eager_mode",
|
| 119 |
+
"softmax_quant_spec": null,
|
| 120 |
+
"version": "0.11.2+b560ff9e7f9"
|
| 121 |
+
},
|
| 122 |
"text_config": {
|
| 123 |
"_name_or_path": "",
|
| 124 |
"add_cross_attention": false,
|
|
|
|
| 174 |
"moe_intermediate_size": 2048,
|
| 175 |
"moe_layer_freq": 1,
|
| 176 |
"n_group": 1,
|
| 177 |
+
"n_routed_experts": 384,
|
| 178 |
"n_shared_experts": 1,
|
| 179 |
"no_repeat_ngram_size": 0,
|
| 180 |
"norm_topk_prob": true,
|
| 181 |
+
"num_attention_heads": 64,
|
| 182 |
"num_beam_groups": 1,
|
| 183 |
"num_beams": 1,
|
| 184 |
"num_experts_per_tok": 8,
|
| 185 |
"num_hidden_layers": 4,
|
| 186 |
+
"num_key_value_heads": 64,
|
| 187 |
"num_nextn_predict_layers": 0,
|
| 188 |
"num_return_sequences": 1,
|
| 189 |
"output_attentions": false,
|
|
|
|
| 259 |
"vt_hidden_size": 1152,
|
| 260 |
"vt_intermediate_size": 4304,
|
| 261 |
"vt_num_attention_heads": 16,
|
| 262 |
+
"vt_num_hidden_layers": 4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
}
|
| 264 |
}
|
docs/deploy_guidance.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Kimi-K2.5 Deployment Guide
|
| 2 |
+
|
| 3 |
+
> [!Note]
|
| 4 |
+
> This guide only provides some examples of deployment commands for Kimi-K2.5, 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 |
+
## vLLM Deployment
|
| 8 |
+
|
| 9 |
+
This model is available in nightly vLLM wheel:
|
| 10 |
+
```
|
| 11 |
+
uv pip install -U vllm \
|
| 12 |
+
--torch-backend=auto \
|
| 13 |
+
--extra-index-url https://wheels.vllm.ai/nightly
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
Here is the example to serve this model on a H200 single node with TP8 via vLLM:
|
| 17 |
+
```bash
|
| 18 |
+
vllm serve $MODEL_PATH -tp 8 --mm-encoder-tp-mode data --trust-remote-code --tool-call-parser kimi_k2 --reasoning-parser kimi_k2
|
| 19 |
+
```
|
| 20 |
+
**Key notes**
|
| 21 |
+
- `--tool-call-parser kimi_k2`: Required for enabling tool calling
|
| 22 |
+
- `--reasoning-parser kimi_k2`: Kimi-K2.5 enables thinking mode by default. Make sure to pass this for correct reasoning processing.
|
| 23 |
+
|
| 24 |
+
## SGLang Deployment
|
| 25 |
+
|
| 26 |
+
This model is available in SGLang latest main:
|
| 27 |
+
|
| 28 |
+
```
|
| 29 |
+
pip install "sglang @ git+https://github.com/sgl-project/sglang.git#subdirectory=python"
|
| 30 |
+
pip install nvidia-cudnn-cu12==9.16.0.29
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Similarly, here is the example for it to run with TP8 on H200 in a single node via SGLang:
|
| 34 |
+
``` bash
|
| 35 |
+
sglang serve --model-path $MODEL_PATH --tp 8 --trust-remote-code --tool-call-parser kimi_k2 --reasoning-parser kimi_k2
|
| 36 |
+
```
|
| 37 |
+
**Key parameter notes:**
|
| 38 |
+
- `--tool-call-parser kimi_k2`: Required when enabling tool usage.
|
| 39 |
+
- `--reasoning-parser kimi_k2`: Required for correctly processing reasoning content.
|
| 40 |
+
|
| 41 |
+
## KTransformers Deployment
|
| 42 |
+
### KTransformers+SGLang Inference Deployment
|
| 43 |
+
Launch with KTransformers + SGLang for CPU+GPU heterogeneous inference:
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
python -m sglang.launch_server \
|
| 47 |
+
--model path/to/Kimi-K2.5/ \
|
| 48 |
+
--kt-amx-weight-path path/to/Kimi-K2.5/ \
|
| 49 |
+
--kt-cpuinfer 64 \
|
| 50 |
+
--kt-threadpool-count 2 \
|
| 51 |
+
--kt-num-gpu-experts 180 \
|
| 52 |
+
--kt-amx-method AMXINT4 \
|
| 53 |
+
--trust-remote-code \
|
| 54 |
+
--mem-fraction-static 0.98 \
|
| 55 |
+
--chunked-prefill-size 16384 \
|
| 56 |
+
--max-running-requests 48 \
|
| 57 |
+
--max-total-tokens 50000 \
|
| 58 |
+
--tensor-parallel-size 8 \
|
| 59 |
+
--enable-p2p-check \
|
| 60 |
+
--disable-shared-experts-fusion
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Achieves 640.12 tokens/s Prefill and 24.51 tokens/s Decode (48-way concurrency) on 8× NVIDIA L20 + 2× Intel 6454S.
|
| 64 |
+
|
| 65 |
+
More details: https://github.com/kvcache-ai/ktransformers/blob/main/doc/en/Kimi-K2.5.md .
|
| 66 |
+
|
| 67 |
+
### KTransformers+LLaMA-Factory Fine-tuning Deployment
|
| 68 |
+
|
| 69 |
+
You can use below command to run LoRA SFT with KT+llamafactory.
|
| 70 |
+
|
| 71 |
+
```
|
| 72 |
+
# For LoRA SFT
|
| 73 |
+
USE_KT=1 llamafactory-cli train examples/train_lora/kimik2_lora_sft_kt.yaml
|
| 74 |
+
# For Chat with model after LoRA SFT
|
| 75 |
+
llamafactory-cli chat examples/inference/kimik2_lora_sft_kt.yaml
|
| 76 |
+
# For API with model after LoRA SFT
|
| 77 |
+
llamafactory-cli api examples/inference/kimik2_lora_sft_kt.yaml
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
This achieves end-to-end LoRA SFT Throughput: 44.55 token/s on 2× NVIDIA 4090 + Intel 8488C with 1.97T RAM and 200G swap memory.
|
| 81 |
+
|
| 82 |
+
More details refer to https://github.com/kvcache-ai/ktransformers/blob/main/doc/en/SFT_Installation_Guide_KimiK2.5.md .
|
figures/demo_video.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:09b4d925aa0a7c712feef50765355f0625d8f6d46ea302fd98db9609e9070047
|
| 3 |
+
size 270100
|
figures/kimi-logo.png
ADDED
|
model-00001-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:42a2d99bc0c34e386ae682ed749b0ef89e5264d58b9c69e5bfcfdece27595d2d
|
| 3 |
+
size 5365266456
|
model-00002-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bdfe4ab0dec82144dd4b1f0225bf86cb3558e20801b1a1e1f699fd5926c483c7
|
| 3 |
+
size 5362966080
|
model-00003-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bcb7312dd70da4a4685363a9783a73a97c1603ad7b3e9d3118e7cd44bfc538f2
|
| 3 |
+
size 5365756248
|
model-00004-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:acfeed6e455d2fe5eeda2d23f8d143eff89a170b818ae13caaaa3e90a451d5f0
|
| 3 |
+
size 5362966096
|
model-00005-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c243fa18c930a5318e9a84e1710011a300d63f207bdc2e05beaefa6a15be4dcd
|
| 3 |
+
size 5365756088
|
model-00006-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:23b4b78a4734bb16f27716de9299859572a559f4aa294bd8b851bcd7faea2762
|
| 3 |
+
size 3586057136
|
model-00007-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b8ef9813f27fb085b5e0a887631630ba3a4260496e049ea70b82dafbedaaa78
|
| 3 |
+
size 2590102248
|
model.safetensors.index.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9225e4226cd4201ae1d9aaeda7e72a3b06fd0698dd212fb77df9cb6d904376d
|
| 3 |
+
size 758863
|
quark_profile.yaml
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Quark Profiling Results
|
| 2 |
+
|
| 3 |
+
memory_usage:
|
| 4 |
+
- step: "Start"
|
| 5 |
+
timestamp: 1775015372.9551535
|
| 6 |
+
relative_time_secs: 0.0
|
| 7 |
+
cpu_memory_mb: 3967.14
|
| 8 |
+
gpu_memory_mb: 774.32
|
| 9 |
+
disk_read_mb: 0.0
|
| 10 |
+
disk_write_mb: 0.0
|
| 11 |
+
- step: "File-to-File Quantization Start"
|
| 12 |
+
timestamp: 1775015373.1001534
|
| 13 |
+
relative_time_secs: 0.14499998092651367
|
| 14 |
+
cpu_memory_mb: 3967.14
|
| 15 |
+
gpu_memory_mb: 774.32
|
| 16 |
+
disk_read_mb: 0.0
|
| 17 |
+
disk_write_mb: 0.0
|
| 18 |
+
- step: "File-to-File Quantization Start"
|
| 19 |
+
timestamp: 1775015373.207735
|
| 20 |
+
relative_time_secs: 0.2525815963745117
|
| 21 |
+
cpu_memory_mb: 3967.14
|
| 22 |
+
gpu_memory_mb: 774.32
|
| 23 |
+
disk_read_mb: 0.0
|
| 24 |
+
disk_write_mb: 0.0
|
| 25 |
+
- step: "File-to-File Quantization End"
|
| 26 |
+
timestamp: 1775015373.3390446
|
| 27 |
+
relative_time_secs: 0.38389110565185547
|
| 28 |
+
cpu_memory_mb: 3967.14
|
| 29 |
+
gpu_memory_mb: 774.32
|
| 30 |
+
disk_read_mb: 0.0
|
| 31 |
+
disk_write_mb: 0.0
|
| 32 |
+
- step: "File-to-File Quantization End"
|
| 33 |
+
timestamp: 1775015373.47948
|
| 34 |
+
relative_time_secs: 0.5243265628814697
|
| 35 |
+
cpu_memory_mb: 3967.14
|
| 36 |
+
gpu_memory_mb: 774.32
|
| 37 |
+
disk_read_mb: 0.0
|
| 38 |
+
disk_write_mb: 0.0
|
| 39 |
+
- step: "End"
|
| 40 |
+
timestamp: 1775015373.6052163
|
| 41 |
+
relative_time_secs: 0.6500627994537354
|
| 42 |
+
cpu_memory_mb: 3967.14
|
| 43 |
+
gpu_memory_mb: 774.32
|
| 44 |
+
disk_read_mb: 0.0
|
| 45 |
+
disk_write_mb: 0.0
|
| 46 |
+
|
| 47 |
+
# Summary Metrics
|
| 48 |
+
total_quantization_time_seconds: 0.6501
|
| 49 |
+
peak_memory_mb: 3967.14
|
| 50 |
+
peak_gpu_memory_mb: 774.32
|
| 51 |
+
total_disk_read_mb: 0.0
|
| 52 |
+
total_disk_write_mb: 0.0
|
| 53 |
+
|
| 54 |
+
# Metric Definitions:
|
| 55 |
+
#
|
| 56 |
+
# Checkpoint Metrics (per record):
|
| 57 |
+
# - step: Name of the profiling checkpoint. Common steps include:
|
| 58 |
+
# - "Start": Initial state when profiling begins
|
| 59 |
+
# - "Model Loaded": After loading the ONNX model into memory
|
| 60 |
+
# - "Pre-process Start/End": Before and after model preprocessing
|
| 61 |
+
# - "Calibration Start/End": Before and after calibration data collection
|
| 62 |
+
# - "Quantization (MatMulNBits) Start/End": MatMulNBits quantization phase
|
| 63 |
+
# - "Quantization (Static) Start/End": Static quantization phase
|
| 64 |
+
# - "Post-process Start/End": Before and after post-processing
|
| 65 |
+
# - "Fast Finetune Start/End": Before and after fast finetuning (if enabled)
|
| 66 |
+
# - timestamp: Unix timestamp (seconds since epoch) when this measurement was taken. Useful for correlating with external logs or events.
|
| 67 |
+
# - relative_time_secs: Time elapsed (in seconds) since the "Start" step. Useful for understanding the duration of each phase relative to the beginning of profiling.
|
| 68 |
+
# - cpu_memory_mb: Current Resident Set Size (RSS) in megabytes at this step. This includes memory from the main process and all child processes. RSS represents the portion of memory held in RAM (not swapped out).
|
| 69 |
+
# - gpu_memory_mb: Current GPU memory usage in megabytes. This represents actual GPU memory used by the process, including allocations from PyTorch, ONNX Runtime, TensorRT, and other frameworks. Only available when PyTorch with CUDA/ROCm is installed and GPU is available.
|
| 70 |
+
# - disk_read_mb: Cumulative disk bytes read (in megabytes) since the start of profiling. Measured relative to the baseline captured at the 'Start' checkpoint, including I/O from the main process and all child processes. Only available when psutil is installed and the OS exposes per-process I/O counters (Linux /proc/<pid>/io, Windows; not available on macOS without root).
|
| 71 |
+
# - disk_write_mb: Cumulative disk bytes written (in megabytes) since the start of profiling. Measured relative to the baseline captured at the 'Start' checkpoint, including I/O from the main process and all child processes. Only available when psutil is installed and the OS exposes per-process I/O counters (Linux /proc/<pid>/io, Windows; not available on macOS without root).
|
| 72 |
+
#
|
| 73 |
+
# Summary Metrics (overall):
|
| 74 |
+
# - total_quantization_time_seconds: Total elapsed time (in seconds) from the start of profiling to the end of the quantization process.
|
| 75 |
+
# - peak_memory_mb: Peak resident set size (RSS) in megabytes for the main process during the entire profiling session. On Linux, this is read from VmHWM (high water mark) in /proc/<pid>/status. On Windows, this is the peak working set size. This metric may not be available on all platforms.
|
| 76 |
+
# - peak_gpu_memory_mb: Peak GPU memory usage in megabytes during the entire profiling session. This is the maximum GPU memory used, including allocations from PyTorch, ONNX Runtime, TensorRT, and other frameworks. Only available when PyTorch with CUDA/ROCm is installed and GPU is available.
|
| 77 |
+
# - total_disk_read_mb: Total disk bytes read (in megabytes) during the entire profiling session. Computed as the difference between the final and baseline cumulative read counters, including I/O from the main process and all child processes. Only available when psutil is installed and the OS exposes per-process I/O counters (Linux /proc/<pid>/io, Windows; not available on macOS without root).
|
| 78 |
+
# - total_disk_write_mb: Total disk bytes written (in megabytes) during the entire profiling session. Computed as the difference between the final and baseline cumulative write counters, including I/O from the main process and all child processes. Only available when psutil is installed and the OS exposes per-process I/O counters (Linux /proc/<pid>/io, Windows; not available on macOS without root).
|
tokenization_kimi.py
CHANGED
|
@@ -9,11 +9,7 @@ import tiktoken
|
|
| 9 |
from tiktoken.load import load_tiktoken_bpe
|
| 10 |
from tokenizers import AddedToken
|
| 11 |
|
| 12 |
-
|
| 13 |
-
from transformers.models.gpt2.tokenization_gpt2 import bytes_to_unicode
|
| 14 |
-
except:
|
| 15 |
-
from transformers.convert_slow_tokenizer import bytes_to_unicode
|
| 16 |
-
|
| 17 |
from transformers.tokenization_utils import PreTrainedTokenizer
|
| 18 |
|
| 19 |
from .tool_declaration_ts import encode_tools_to_typescript_style
|
|
|
|
| 9 |
from tiktoken.load import load_tiktoken_bpe
|
| 10 |
from tokenizers import AddedToken
|
| 11 |
|
| 12 |
+
from transformers.convert_slow_tokenizer import bytes_to_unicode
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
from transformers.tokenization_utils import PreTrainedTokenizer
|
| 14 |
|
| 15 |
from .tool_declaration_ts import encode_tools_to_typescript_style
|