Image-Text-to-Text
Transformers
Safetensors
kimi_k31
feature-extraction
custom_code
compressed-tensors
Instructions to use tiny-random/kimi-k3.1-pro with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/kimi-k3.1-pro with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/kimi-k3.1-pro", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("tiny-random/kimi-k3.1-pro", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/kimi-k3.1-pro with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/kimi-k3.1-pro" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/kimi-k3.1-pro", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tiny-random/kimi-k3.1-pro
- SGLang
How to use tiny-random/kimi-k3.1-pro with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tiny-random/kimi-k3.1-pro" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/kimi-k3.1-pro", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tiny-random/kimi-k3.1-pro" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/kimi-k3.1-pro", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tiny-random/kimi-k3.1-pro with Docker Model Runner:
docker model run hf.co/tiny-random/kimi-k3.1-pro
Upload folder using huggingface_hub
Browse files- .meta/create_model.py +9 -5
- .meta/model.log +80 -80
- README.md +17 -10
- config.json +5 -5
- model.safetensors +2 -2
.meta/create_model.py
CHANGED
|
@@ -195,6 +195,9 @@ def create_model(source_model_id: str, source_revision: str, save_folder: str) -
|
|
| 195 |
)
|
| 196 |
# Kernel-sensitive geometry mirrors tiny-random/kimi-k3: KDA head_dim and MLA ranks stay at
|
| 197 |
# source values, only head count and q LoRA / layer count / widths shrink.
|
|
|
|
|
|
|
|
|
|
| 198 |
text_config.update(
|
| 199 |
{
|
| 200 |
"attn_res_block_size": 8,
|
|
@@ -202,13 +205,14 @@ def create_model(source_model_id: str, source_revision: str, save_folder: str) -
|
|
| 202 |
"hidden_size": 8,
|
| 203 |
"intermediate_size": 32,
|
| 204 |
"kv_lora_rank": 512,
|
| 205 |
-
"moe_intermediate_size":
|
| 206 |
"num_attention_heads": 8,
|
| 207 |
-
"num_experts":
|
|
|
|
| 208 |
"num_hidden_layers": 17,
|
| 209 |
"num_key_value_heads": 8,
|
| 210 |
-
"q_lora_rank":
|
| 211 |
-
"routed_expert_hidden_size":
|
| 212 |
"_attn_implementation": "eager",
|
| 213 |
}
|
| 214 |
)
|
|
@@ -337,5 +341,5 @@ def create_model(source_model_id: str, source_revision: str, save_folder: str) -
|
|
| 337 |
create_model(
|
| 338 |
source_model_id="moonshotai/Kimi-K3.1-Pro",
|
| 339 |
source_revision="6d0a0202956796543364d666ab19c6ad1a494ee1",
|
| 340 |
-
save_folder="/tmp/kimi-k31",
|
| 341 |
)
|
|
|
|
| 195 |
)
|
| 196 |
# Kernel-sensitive geometry mirrors tiny-random/kimi-k3: KDA head_dim and MLA ranks stay at
|
| 197 |
# source values, only head count and q LoRA / layer count / widths shrink.
|
| 198 |
+
# Experts are shrunk aggressively (16 experts x 128 intermediate, top-k 8, still group-32
|
| 199 |
+
# aligned for MXFP4) because MoE tensors otherwise dominate the checkpoint; the source uses
|
| 200 |
+
# 896 experts at 3,072/3,584 with top-k 16.
|
| 201 |
text_config.update(
|
| 202 |
{
|
| 203 |
"attn_res_block_size": 8,
|
|
|
|
| 205 |
"hidden_size": 8,
|
| 206 |
"intermediate_size": 32,
|
| 207 |
"kv_lora_rank": 512,
|
| 208 |
+
"moe_intermediate_size": 128,
|
| 209 |
"num_attention_heads": 8,
|
| 210 |
+
"num_experts": 16,
|
| 211 |
+
"num_experts_per_token": 8,
|
| 212 |
"num_hidden_layers": 17,
|
| 213 |
"num_key_value_heads": 8,
|
| 214 |
+
"q_lora_rank": 128,
|
| 215 |
+
"routed_expert_hidden_size": 128,
|
| 216 |
"_attn_implementation": "eager",
|
| 217 |
}
|
| 218 |
)
|
|
|
|
| 341 |
create_model(
|
| 342 |
source_model_id="moonshotai/Kimi-K3.1-Pro",
|
| 343 |
source_revision="6d0a0202956796543364d666ab19c6ad1a494ee1",
|
| 344 |
+
save_folder="/tmp/kimi-k31-small",
|
| 345 |
)
|
.meta/model.log
CHANGED
|
@@ -79,22 +79,22 @@ KimiK3ForConditionalGeneration(
|
|
| 79 |
)
|
| 80 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 81 |
(experts): ModuleList(
|
| 82 |
-
(0-
|
| 83 |
-
(w1): Linear(in_features=
|
| 84 |
-
(w2): Linear(in_features=
|
| 85 |
-
(w3): Linear(in_features=
|
| 86 |
(act_fn): SituAndMul()
|
| 87 |
)
|
| 88 |
)
|
| 89 |
(gate): KimiMoEGate()
|
| 90 |
(shared_experts): KimiMLP(
|
| 91 |
-
(gate_proj): Linear(in_features=8, out_features=
|
| 92 |
-
(up_proj): Linear(in_features=8, out_features=
|
| 93 |
-
(down_proj): Linear(in_features=
|
| 94 |
(act_fn): SituAndMul()
|
| 95 |
)
|
| 96 |
-
(routed_expert_down_proj): Linear(in_features=8, out_features=
|
| 97 |
-
(routed_expert_up_proj): Linear(in_features=
|
| 98 |
(routed_expert_norm): KimiRMSNorm()
|
| 99 |
)
|
| 100 |
(input_layernorm): KimiRMSNorm()
|
|
@@ -106,9 +106,9 @@ KimiK3ForConditionalGeneration(
|
|
| 106 |
)
|
| 107 |
(3): KimiDecoderLayer(
|
| 108 |
(self_attn): KimiMLAAttention(
|
| 109 |
-
(q_a_proj): Linear(in_features=8, out_features=
|
| 110 |
(q_a_layernorm): KimiRMSNorm()
|
| 111 |
-
(q_b_proj): Linear(in_features=
|
| 112 |
(kv_a_proj_with_mqa): Linear(in_features=8, out_features=576, bias=False)
|
| 113 |
(kv_a_layernorm): KimiRMSNorm()
|
| 114 |
(kv_b_proj): Linear(in_features=512, out_features=2048, bias=False)
|
|
@@ -117,22 +117,22 @@ KimiK3ForConditionalGeneration(
|
|
| 117 |
)
|
| 118 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 119 |
(experts): ModuleList(
|
| 120 |
-
(0-
|
| 121 |
-
(w1): Linear(in_features=
|
| 122 |
-
(w2): Linear(in_features=
|
| 123 |
-
(w3): Linear(in_features=
|
| 124 |
(act_fn): SituAndMul()
|
| 125 |
)
|
| 126 |
)
|
| 127 |
(gate): KimiMoEGate()
|
| 128 |
(shared_experts): KimiMLP(
|
| 129 |
-
(gate_proj): Linear(in_features=8, out_features=
|
| 130 |
-
(up_proj): Linear(in_features=8, out_features=
|
| 131 |
-
(down_proj): Linear(in_features=
|
| 132 |
(act_fn): SituAndMul()
|
| 133 |
)
|
| 134 |
-
(routed_expert_down_proj): Linear(in_features=8, out_features=
|
| 135 |
-
(routed_expert_up_proj): Linear(in_features=
|
| 136 |
(routed_expert_norm): KimiRMSNorm()
|
| 137 |
)
|
| 138 |
(input_layernorm): KimiRMSNorm()
|
|
@@ -159,22 +159,22 @@ KimiK3ForConditionalGeneration(
|
|
| 159 |
)
|
| 160 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 161 |
(experts): ModuleList(
|
| 162 |
-
(0-
|
| 163 |
-
(w1): Linear(in_features=
|
| 164 |
-
(w2): Linear(in_features=
|
| 165 |
-
(w3): Linear(in_features=
|
| 166 |
(act_fn): SituAndMul()
|
| 167 |
)
|
| 168 |
)
|
| 169 |
(gate): KimiMoEGate()
|
| 170 |
(shared_experts): KimiMLP(
|
| 171 |
-
(gate_proj): Linear(in_features=8, out_features=
|
| 172 |
-
(up_proj): Linear(in_features=8, out_features=
|
| 173 |
-
(down_proj): Linear(in_features=
|
| 174 |
(act_fn): SituAndMul()
|
| 175 |
)
|
| 176 |
-
(routed_expert_down_proj): Linear(in_features=8, out_features=
|
| 177 |
-
(routed_expert_up_proj): Linear(in_features=
|
| 178 |
(routed_expert_norm): KimiRMSNorm()
|
| 179 |
)
|
| 180 |
(input_layernorm): KimiRMSNorm()
|
|
@@ -186,9 +186,9 @@ KimiK3ForConditionalGeneration(
|
|
| 186 |
)
|
| 187 |
(7): KimiDecoderLayer(
|
| 188 |
(self_attn): KimiMLAAttention(
|
| 189 |
-
(q_a_proj): Linear(in_features=8, out_features=
|
| 190 |
(q_a_layernorm): KimiRMSNorm()
|
| 191 |
-
(q_b_proj): Linear(in_features=
|
| 192 |
(kv_a_proj_with_mqa): Linear(in_features=8, out_features=576, bias=False)
|
| 193 |
(kv_a_layernorm): KimiRMSNorm()
|
| 194 |
(kv_b_proj): Linear(in_features=512, out_features=2048, bias=False)
|
|
@@ -197,22 +197,22 @@ KimiK3ForConditionalGeneration(
|
|
| 197 |
)
|
| 198 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 199 |
(experts): ModuleList(
|
| 200 |
-
(0-
|
| 201 |
-
(w1): Linear(in_features=
|
| 202 |
-
(w2): Linear(in_features=
|
| 203 |
-
(w3): Linear(in_features=
|
| 204 |
(act_fn): SituAndMul()
|
| 205 |
)
|
| 206 |
)
|
| 207 |
(gate): KimiMoEGate()
|
| 208 |
(shared_experts): KimiMLP(
|
| 209 |
-
(gate_proj): Linear(in_features=8, out_features=
|
| 210 |
-
(up_proj): Linear(in_features=8, out_features=
|
| 211 |
-
(down_proj): Linear(in_features=
|
| 212 |
(act_fn): SituAndMul()
|
| 213 |
)
|
| 214 |
-
(routed_expert_down_proj): Linear(in_features=8, out_features=
|
| 215 |
-
(routed_expert_up_proj): Linear(in_features=
|
| 216 |
(routed_expert_norm): KimiRMSNorm()
|
| 217 |
)
|
| 218 |
(input_layernorm): KimiRMSNorm()
|
|
@@ -239,22 +239,22 @@ KimiK3ForConditionalGeneration(
|
|
| 239 |
)
|
| 240 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 241 |
(experts): ModuleList(
|
| 242 |
-
(0-
|
| 243 |
-
(w1): Linear(in_features=
|
| 244 |
-
(w2): Linear(in_features=
|
| 245 |
-
(w3): Linear(in_features=
|
| 246 |
(act_fn): SituAndMul()
|
| 247 |
)
|
| 248 |
)
|
| 249 |
(gate): KimiMoEGate()
|
| 250 |
(shared_experts): KimiMLP(
|
| 251 |
-
(gate_proj): Linear(in_features=8, out_features=
|
| 252 |
-
(up_proj): Linear(in_features=8, out_features=
|
| 253 |
-
(down_proj): Linear(in_features=
|
| 254 |
(act_fn): SituAndMul()
|
| 255 |
)
|
| 256 |
-
(routed_expert_down_proj): Linear(in_features=8, out_features=
|
| 257 |
-
(routed_expert_up_proj): Linear(in_features=
|
| 258 |
(routed_expert_norm): KimiRMSNorm()
|
| 259 |
)
|
| 260 |
(input_layernorm): KimiRMSNorm()
|
|
@@ -266,9 +266,9 @@ KimiK3ForConditionalGeneration(
|
|
| 266 |
)
|
| 267 |
(11): KimiDecoderLayer(
|
| 268 |
(self_attn): KimiMLAAttention(
|
| 269 |
-
(q_a_proj): Linear(in_features=8, out_features=
|
| 270 |
(q_a_layernorm): KimiRMSNorm()
|
| 271 |
-
(q_b_proj): Linear(in_features=
|
| 272 |
(kv_a_proj_with_mqa): Linear(in_features=8, out_features=576, bias=False)
|
| 273 |
(kv_a_layernorm): KimiRMSNorm()
|
| 274 |
(kv_b_proj): Linear(in_features=512, out_features=2048, bias=False)
|
|
@@ -277,22 +277,22 @@ KimiK3ForConditionalGeneration(
|
|
| 277 |
)
|
| 278 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 279 |
(experts): ModuleList(
|
| 280 |
-
(0-
|
| 281 |
-
(w1): Linear(in_features=
|
| 282 |
-
(w2): Linear(in_features=
|
| 283 |
-
(w3): Linear(in_features=
|
| 284 |
(act_fn): SituAndMul()
|
| 285 |
)
|
| 286 |
)
|
| 287 |
(gate): KimiMoEGate()
|
| 288 |
(shared_experts): KimiMLP(
|
| 289 |
-
(gate_proj): Linear(in_features=8, out_features=
|
| 290 |
-
(up_proj): Linear(in_features=8, out_features=
|
| 291 |
-
(down_proj): Linear(in_features=
|
| 292 |
(act_fn): SituAndMul()
|
| 293 |
)
|
| 294 |
-
(routed_expert_down_proj): Linear(in_features=8, out_features=
|
| 295 |
-
(routed_expert_up_proj): Linear(in_features=
|
| 296 |
(routed_expert_norm): KimiRMSNorm()
|
| 297 |
)
|
| 298 |
(input_layernorm): KimiRMSNorm()
|
|
@@ -319,22 +319,22 @@ KimiK3ForConditionalGeneration(
|
|
| 319 |
)
|
| 320 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 321 |
(experts): ModuleList(
|
| 322 |
-
(0-
|
| 323 |
-
(w1): Linear(in_features=
|
| 324 |
-
(w2): Linear(in_features=
|
| 325 |
-
(w3): Linear(in_features=
|
| 326 |
(act_fn): SituAndMul()
|
| 327 |
)
|
| 328 |
)
|
| 329 |
(gate): KimiMoEGate()
|
| 330 |
(shared_experts): KimiMLP(
|
| 331 |
-
(gate_proj): Linear(in_features=8, out_features=
|
| 332 |
-
(up_proj): Linear(in_features=8, out_features=
|
| 333 |
-
(down_proj): Linear(in_features=
|
| 334 |
(act_fn): SituAndMul()
|
| 335 |
)
|
| 336 |
-
(routed_expert_down_proj): Linear(in_features=8, out_features=
|
| 337 |
-
(routed_expert_up_proj): Linear(in_features=
|
| 338 |
(routed_expert_norm): KimiRMSNorm()
|
| 339 |
)
|
| 340 |
(input_layernorm): KimiRMSNorm()
|
|
@@ -346,9 +346,9 @@ KimiK3ForConditionalGeneration(
|
|
| 346 |
)
|
| 347 |
(15-16): 2 x KimiDecoderLayer(
|
| 348 |
(self_attn): KimiMLAAttention(
|
| 349 |
-
(q_a_proj): Linear(in_features=8, out_features=
|
| 350 |
(q_a_layernorm): KimiRMSNorm()
|
| 351 |
-
(q_b_proj): Linear(in_features=
|
| 352 |
(kv_a_proj_with_mqa): Linear(in_features=8, out_features=576, bias=False)
|
| 353 |
(kv_a_layernorm): KimiRMSNorm()
|
| 354 |
(kv_b_proj): Linear(in_features=512, out_features=2048, bias=False)
|
|
@@ -357,22 +357,22 @@ KimiK3ForConditionalGeneration(
|
|
| 357 |
)
|
| 358 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 359 |
(experts): ModuleList(
|
| 360 |
-
(0-
|
| 361 |
-
(w1): Linear(in_features=
|
| 362 |
-
(w2): Linear(in_features=
|
| 363 |
-
(w3): Linear(in_features=
|
| 364 |
(act_fn): SituAndMul()
|
| 365 |
)
|
| 366 |
)
|
| 367 |
(gate): KimiMoEGate()
|
| 368 |
(shared_experts): KimiMLP(
|
| 369 |
-
(gate_proj): Linear(in_features=8, out_features=
|
| 370 |
-
(up_proj): Linear(in_features=8, out_features=
|
| 371 |
-
(down_proj): Linear(in_features=
|
| 372 |
(act_fn): SituAndMul()
|
| 373 |
)
|
| 374 |
-
(routed_expert_down_proj): Linear(in_features=8, out_features=
|
| 375 |
-
(routed_expert_up_proj): Linear(in_features=
|
| 376 |
(routed_expert_norm): KimiRMSNorm()
|
| 377 |
)
|
| 378 |
(input_layernorm): KimiRMSNorm()
|
|
|
|
| 79 |
)
|
| 80 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 81 |
(experts): ModuleList(
|
| 82 |
+
(0-15): 16 x KimiBlockSparseMLP(
|
| 83 |
+
(w1): Linear(in_features=128, out_features=128, bias=False)
|
| 84 |
+
(w2): Linear(in_features=128, out_features=128, bias=False)
|
| 85 |
+
(w3): Linear(in_features=128, out_features=128, bias=False)
|
| 86 |
(act_fn): SituAndMul()
|
| 87 |
)
|
| 88 |
)
|
| 89 |
(gate): KimiMoEGate()
|
| 90 |
(shared_experts): KimiMLP(
|
| 91 |
+
(gate_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 92 |
+
(up_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 93 |
+
(down_proj): Linear(in_features=256, out_features=8, bias=False)
|
| 94 |
(act_fn): SituAndMul()
|
| 95 |
)
|
| 96 |
+
(routed_expert_down_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 97 |
+
(routed_expert_up_proj): Linear(in_features=128, out_features=8, bias=False)
|
| 98 |
(routed_expert_norm): KimiRMSNorm()
|
| 99 |
)
|
| 100 |
(input_layernorm): KimiRMSNorm()
|
|
|
|
| 106 |
)
|
| 107 |
(3): KimiDecoderLayer(
|
| 108 |
(self_attn): KimiMLAAttention(
|
| 109 |
+
(q_a_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 110 |
(q_a_layernorm): KimiRMSNorm()
|
| 111 |
+
(q_b_proj): Linear(in_features=128, out_features=1536, bias=False)
|
| 112 |
(kv_a_proj_with_mqa): Linear(in_features=8, out_features=576, bias=False)
|
| 113 |
(kv_a_layernorm): KimiRMSNorm()
|
| 114 |
(kv_b_proj): Linear(in_features=512, out_features=2048, bias=False)
|
|
|
|
| 117 |
)
|
| 118 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 119 |
(experts): ModuleList(
|
| 120 |
+
(0-15): 16 x KimiBlockSparseMLP(
|
| 121 |
+
(w1): Linear(in_features=128, out_features=128, bias=False)
|
| 122 |
+
(w2): Linear(in_features=128, out_features=128, bias=False)
|
| 123 |
+
(w3): Linear(in_features=128, out_features=128, bias=False)
|
| 124 |
(act_fn): SituAndMul()
|
| 125 |
)
|
| 126 |
)
|
| 127 |
(gate): KimiMoEGate()
|
| 128 |
(shared_experts): KimiMLP(
|
| 129 |
+
(gate_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 130 |
+
(up_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 131 |
+
(down_proj): Linear(in_features=256, out_features=8, bias=False)
|
| 132 |
(act_fn): SituAndMul()
|
| 133 |
)
|
| 134 |
+
(routed_expert_down_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 135 |
+
(routed_expert_up_proj): Linear(in_features=128, out_features=8, bias=False)
|
| 136 |
(routed_expert_norm): KimiRMSNorm()
|
| 137 |
)
|
| 138 |
(input_layernorm): KimiRMSNorm()
|
|
|
|
| 159 |
)
|
| 160 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 161 |
(experts): ModuleList(
|
| 162 |
+
(0-15): 16 x KimiBlockSparseMLP(
|
| 163 |
+
(w1): Linear(in_features=128, out_features=128, bias=False)
|
| 164 |
+
(w2): Linear(in_features=128, out_features=128, bias=False)
|
| 165 |
+
(w3): Linear(in_features=128, out_features=128, bias=False)
|
| 166 |
(act_fn): SituAndMul()
|
| 167 |
)
|
| 168 |
)
|
| 169 |
(gate): KimiMoEGate()
|
| 170 |
(shared_experts): KimiMLP(
|
| 171 |
+
(gate_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 172 |
+
(up_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 173 |
+
(down_proj): Linear(in_features=256, out_features=8, bias=False)
|
| 174 |
(act_fn): SituAndMul()
|
| 175 |
)
|
| 176 |
+
(routed_expert_down_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 177 |
+
(routed_expert_up_proj): Linear(in_features=128, out_features=8, bias=False)
|
| 178 |
(routed_expert_norm): KimiRMSNorm()
|
| 179 |
)
|
| 180 |
(input_layernorm): KimiRMSNorm()
|
|
|
|
| 186 |
)
|
| 187 |
(7): KimiDecoderLayer(
|
| 188 |
(self_attn): KimiMLAAttention(
|
| 189 |
+
(q_a_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 190 |
(q_a_layernorm): KimiRMSNorm()
|
| 191 |
+
(q_b_proj): Linear(in_features=128, out_features=1536, bias=False)
|
| 192 |
(kv_a_proj_with_mqa): Linear(in_features=8, out_features=576, bias=False)
|
| 193 |
(kv_a_layernorm): KimiRMSNorm()
|
| 194 |
(kv_b_proj): Linear(in_features=512, out_features=2048, bias=False)
|
|
|
|
| 197 |
)
|
| 198 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 199 |
(experts): ModuleList(
|
| 200 |
+
(0-15): 16 x KimiBlockSparseMLP(
|
| 201 |
+
(w1): Linear(in_features=128, out_features=128, bias=False)
|
| 202 |
+
(w2): Linear(in_features=128, out_features=128, bias=False)
|
| 203 |
+
(w3): Linear(in_features=128, out_features=128, bias=False)
|
| 204 |
(act_fn): SituAndMul()
|
| 205 |
)
|
| 206 |
)
|
| 207 |
(gate): KimiMoEGate()
|
| 208 |
(shared_experts): KimiMLP(
|
| 209 |
+
(gate_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 210 |
+
(up_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 211 |
+
(down_proj): Linear(in_features=256, out_features=8, bias=False)
|
| 212 |
(act_fn): SituAndMul()
|
| 213 |
)
|
| 214 |
+
(routed_expert_down_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 215 |
+
(routed_expert_up_proj): Linear(in_features=128, out_features=8, bias=False)
|
| 216 |
(routed_expert_norm): KimiRMSNorm()
|
| 217 |
)
|
| 218 |
(input_layernorm): KimiRMSNorm()
|
|
|
|
| 239 |
)
|
| 240 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 241 |
(experts): ModuleList(
|
| 242 |
+
(0-15): 16 x KimiBlockSparseMLP(
|
| 243 |
+
(w1): Linear(in_features=128, out_features=128, bias=False)
|
| 244 |
+
(w2): Linear(in_features=128, out_features=128, bias=False)
|
| 245 |
+
(w3): Linear(in_features=128, out_features=128, bias=False)
|
| 246 |
(act_fn): SituAndMul()
|
| 247 |
)
|
| 248 |
)
|
| 249 |
(gate): KimiMoEGate()
|
| 250 |
(shared_experts): KimiMLP(
|
| 251 |
+
(gate_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 252 |
+
(up_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 253 |
+
(down_proj): Linear(in_features=256, out_features=8, bias=False)
|
| 254 |
(act_fn): SituAndMul()
|
| 255 |
)
|
| 256 |
+
(routed_expert_down_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 257 |
+
(routed_expert_up_proj): Linear(in_features=128, out_features=8, bias=False)
|
| 258 |
(routed_expert_norm): KimiRMSNorm()
|
| 259 |
)
|
| 260 |
(input_layernorm): KimiRMSNorm()
|
|
|
|
| 266 |
)
|
| 267 |
(11): KimiDecoderLayer(
|
| 268 |
(self_attn): KimiMLAAttention(
|
| 269 |
+
(q_a_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 270 |
(q_a_layernorm): KimiRMSNorm()
|
| 271 |
+
(q_b_proj): Linear(in_features=128, out_features=1536, bias=False)
|
| 272 |
(kv_a_proj_with_mqa): Linear(in_features=8, out_features=576, bias=False)
|
| 273 |
(kv_a_layernorm): KimiRMSNorm()
|
| 274 |
(kv_b_proj): Linear(in_features=512, out_features=2048, bias=False)
|
|
|
|
| 277 |
)
|
| 278 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 279 |
(experts): ModuleList(
|
| 280 |
+
(0-15): 16 x KimiBlockSparseMLP(
|
| 281 |
+
(w1): Linear(in_features=128, out_features=128, bias=False)
|
| 282 |
+
(w2): Linear(in_features=128, out_features=128, bias=False)
|
| 283 |
+
(w3): Linear(in_features=128, out_features=128, bias=False)
|
| 284 |
(act_fn): SituAndMul()
|
| 285 |
)
|
| 286 |
)
|
| 287 |
(gate): KimiMoEGate()
|
| 288 |
(shared_experts): KimiMLP(
|
| 289 |
+
(gate_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 290 |
+
(up_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 291 |
+
(down_proj): Linear(in_features=256, out_features=8, bias=False)
|
| 292 |
(act_fn): SituAndMul()
|
| 293 |
)
|
| 294 |
+
(routed_expert_down_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 295 |
+
(routed_expert_up_proj): Linear(in_features=128, out_features=8, bias=False)
|
| 296 |
(routed_expert_norm): KimiRMSNorm()
|
| 297 |
)
|
| 298 |
(input_layernorm): KimiRMSNorm()
|
|
|
|
| 319 |
)
|
| 320 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 321 |
(experts): ModuleList(
|
| 322 |
+
(0-15): 16 x KimiBlockSparseMLP(
|
| 323 |
+
(w1): Linear(in_features=128, out_features=128, bias=False)
|
| 324 |
+
(w2): Linear(in_features=128, out_features=128, bias=False)
|
| 325 |
+
(w3): Linear(in_features=128, out_features=128, bias=False)
|
| 326 |
(act_fn): SituAndMul()
|
| 327 |
)
|
| 328 |
)
|
| 329 |
(gate): KimiMoEGate()
|
| 330 |
(shared_experts): KimiMLP(
|
| 331 |
+
(gate_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 332 |
+
(up_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 333 |
+
(down_proj): Linear(in_features=256, out_features=8, bias=False)
|
| 334 |
(act_fn): SituAndMul()
|
| 335 |
)
|
| 336 |
+
(routed_expert_down_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 337 |
+
(routed_expert_up_proj): Linear(in_features=128, out_features=8, bias=False)
|
| 338 |
(routed_expert_norm): KimiRMSNorm()
|
| 339 |
)
|
| 340 |
(input_layernorm): KimiRMSNorm()
|
|
|
|
| 346 |
)
|
| 347 |
(15-16): 2 x KimiDecoderLayer(
|
| 348 |
(self_attn): KimiMLAAttention(
|
| 349 |
+
(q_a_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 350 |
(q_a_layernorm): KimiRMSNorm()
|
| 351 |
+
(q_b_proj): Linear(in_features=128, out_features=1536, bias=False)
|
| 352 |
(kv_a_proj_with_mqa): Linear(in_features=8, out_features=576, bias=False)
|
| 353 |
(kv_a_layernorm): KimiRMSNorm()
|
| 354 |
(kv_b_proj): Linear(in_features=512, out_features=2048, bias=False)
|
|
|
|
| 357 |
)
|
| 358 |
(block_sparse_moe): KimiSparseMoeBlock(
|
| 359 |
(experts): ModuleList(
|
| 360 |
+
(0-15): 16 x KimiBlockSparseMLP(
|
| 361 |
+
(w1): Linear(in_features=128, out_features=128, bias=False)
|
| 362 |
+
(w2): Linear(in_features=128, out_features=128, bias=False)
|
| 363 |
+
(w3): Linear(in_features=128, out_features=128, bias=False)
|
| 364 |
(act_fn): SituAndMul()
|
| 365 |
)
|
| 366 |
)
|
| 367 |
(gate): KimiMoEGate()
|
| 368 |
(shared_experts): KimiMLP(
|
| 369 |
+
(gate_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 370 |
+
(up_proj): Linear(in_features=8, out_features=256, bias=False)
|
| 371 |
+
(down_proj): Linear(in_features=256, out_features=8, bias=False)
|
| 372 |
(act_fn): SituAndMul()
|
| 373 |
)
|
| 374 |
+
(routed_expert_down_proj): Linear(in_features=8, out_features=128, bias=False)
|
| 375 |
+
(routed_expert_up_proj): Linear(in_features=128, out_features=8, bias=False)
|
| 376 |
(routed_expert_norm): KimiRMSNorm()
|
| 377 |
)
|
| 378 |
(input_layernorm): KimiRMSNorm()
|
README.md
CHANGED
|
@@ -9,14 +9,14 @@ This is a randomly initialized tiny model based on [moonshotai/Kimi-K3.1-Pro](ht
|
|
| 9 |
|
| 10 |
| Feature | Source | This repo |
|
| 11 |
|---|---|---|
|
| 12 |
-
| Checkpoint tensor elements | 57.36B BF16, 11.12M F32, 1.45T U8 |
|
| 13 |
-
| Safetensors weight files | 1.56 TB (96 files) |
|
| 14 |
| Total / DSA-gated layers | 93 / 24 (plus 69 KDA, 1 dense) | 17 / 5 (plus 11 KDA, 1 dense) |
|
| 15 |
| Attention composition | 69 KDA + 24 gated DSA | 11 KDA + 5 DSA cadence |
|
| 16 |
| Hidden width / MLP width | 7,168 / 33,792 | 8 / 32 |
|
| 17 |
| Full-attn Q heads / head dim | 96 / 128 (nope 128, rope 64, v 128) | 8 / 128 (same per-head dims) |
|
| 18 |
-
| MLA q / kv LoRA rank | 1,536 / 512 |
|
| 19 |
-
| Routed / shared experts, top-k | 896 / 2, 16 |
|
| 20 |
| LSA index heads / head dim / topk | 32 / 128 / 2,048 | 32 / 128 / 2,048 (unchanged) |
|
| 21 |
| Physical DSA indexer layers | 24 (dsa_layers - 1) | [3, 7, 11, 15, 16] |
|
| 22 |
| Routed expert precision | MXFP4 packed (group 32, E8M0 scales) | Same |
|
|
@@ -29,7 +29,7 @@ Kimi K3.1 Pro ships configuration and processor code but no modeling implementat
|
|
| 29 |
|
| 30 |
| File path | Size |
|
| 31 |
|------|------|
|
| 32 |
-
| model.safetensors |
|
| 33 |
|
| 34 |
### Example usage
|
| 35 |
|
|
@@ -71,27 +71,33 @@ def transformers_example(model_id: str):
|
|
| 71 |
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
| 74 |
-
transformers_example(model_id="scratch/kimi-k31")
|
| 75 |
```
|
| 76 |
|
| 77 |
#### vLLM serving (unverified)
|
| 78 |
|
|
|
|
|
|
|
|
|
|
| 79 |
# K3.1 gated-DSA serving requires a vLLM build with KimiK31 DSA support (newer than the
|
| 80 |
# released wheel at tiny-model creation time). See https://recipes.vllm.ai/moonshotai/Kimi-K3.1-Pro
|
| 81 |
-
vllm serve scratch/kimi-k31 \
|
| 82 |
--trust-remote-code \
|
| 83 |
--tensor-parallel-size 8 \
|
| 84 |
--load-format safetensors \
|
| 85 |
--max-model-len 131072 \
|
| 86 |
--gpu-memory-utilization 0.90
|
| 87 |
-
|
| 88 |
|
| 89 |
#### SGLang serving (unverified)
|
| 90 |
|
|
|
|
|
|
|
|
|
|
| 91 |
# K3.1 gated-DSA serving requires an SGLang build newer than 0.5.23 (the KimiK31 DSA indexer
|
| 92 |
# kernels had not landed in the released wheel at tiny-model creation time).
|
| 93 |
python3 -m sglang.launch_server \
|
| 94 |
-
--model-path scratch/kimi-k31 \
|
| 95 |
--trust-remote-code \
|
| 96 |
--tp-size 8 \
|
| 97 |
--chunked-prefill-size 16384 \
|
|
@@ -101,6 +107,7 @@ python3 -m sglang.launch_server \
|
|
| 101 |
--reasoning-parser kimi_k3 \
|
| 102 |
--tool-call-parser kimi_k3 \
|
| 103 |
--mem-fraction-static 0.85
|
|
|
|
| 104 |
|
| 105 |
### Creating this repo
|
| 106 |
|
|
@@ -110,6 +117,6 @@ python3 -m sglang.launch_server \
|
|
| 110 |
|
| 111 |
### Change log
|
| 112 |
|
| 113 |
-
- 2026-11-05: Initial version. Kimi K3.1 Pro is K3 (69 KDA + 24 attention layers) with the 24 full-attention layers replaced by gated DSA sparse attention carrying an LSA indexer. The tiny model follows the proven tiny-random/kimi-k3 geometry (residual 8, 8 attention heads, q LoRA
|
| 114 |
|
| 115 |
*This repo is generated by GPT-6.1-Sol.*
|
|
|
|
| 9 |
|
| 10 |
| Feature | Source | This repo |
|
| 11 |
|---|---|---|
|
| 12 |
+
| Checkpoint tensor elements | 57.36B BF16, 11.12M F32, 1.45T U8 | 13.98M BF16, 163.07K F32, 6.68M U8 |
|
| 13 |
+
| Safetensors weight files | 1.56 TB (96 files) | 35.58 MB (model.safetensors) |
|
| 14 |
| Total / DSA-gated layers | 93 / 24 (plus 69 KDA, 1 dense) | 17 / 5 (plus 11 KDA, 1 dense) |
|
| 15 |
| Attention composition | 69 KDA + 24 gated DSA | 11 KDA + 5 DSA cadence |
|
| 16 |
| Hidden width / MLP width | 7,168 / 33,792 | 8 / 32 |
|
| 17 |
| Full-attn Q heads / head dim | 96 / 128 (nope 128, rope 64, v 128) | 8 / 128 (same per-head dims) |
|
| 18 |
+
| MLA q / kv LoRA rank | 1,536 / 512 | 128 / 512 |
|
| 19 |
+
| Routed / shared experts, top-k | 896 / 2, 16 | 16 / 2, 8 |
|
| 20 |
| LSA index heads / head dim / topk | 32 / 128 / 2,048 | 32 / 128 / 2,048 (unchanged) |
|
| 21 |
| Physical DSA indexer layers | 24 (dsa_layers - 1) | [3, 7, 11, 15, 16] |
|
| 22 |
| Routed expert precision | MXFP4 packed (group 32, E8M0 scales) | Same |
|
|
|
|
| 29 |
|
| 30 |
| File path | Size |
|
| 31 |
|------|------|
|
| 32 |
+
| model.safetensors | 35.6MB |
|
| 33 |
|
| 34 |
### Example usage
|
| 35 |
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
| 74 |
+
transformers_example(model_id="scratch/kimi-k31-small")
|
| 75 |
```
|
| 76 |
|
| 77 |
#### vLLM serving (unverified)
|
| 78 |
|
| 79 |
+
Requires a vLLM build with KimiK31 gated-DSA support (newer than the released wheel at tiny-model creation time). See https://recipes.vllm.ai/moonshotai/Kimi-K3.1-Pro.
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
# K3.1 gated-DSA serving requires a vLLM build with KimiK31 DSA support (newer than the
|
| 83 |
# released wheel at tiny-model creation time). See https://recipes.vllm.ai/moonshotai/Kimi-K3.1-Pro
|
| 84 |
+
vllm serve scratch/kimi-k31-small \
|
| 85 |
--trust-remote-code \
|
| 86 |
--tensor-parallel-size 8 \
|
| 87 |
--load-format safetensors \
|
| 88 |
--max-model-len 131072 \
|
| 89 |
--gpu-memory-utilization 0.90
|
| 90 |
+
```
|
| 91 |
|
| 92 |
#### SGLang serving (unverified)
|
| 93 |
|
| 94 |
+
Requires an SGLang build newer than 0.5.23 with the KimiK31 DSA indexer (the gated-DSA kernels had not landed in the released wheel at tiny-model creation time).
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
# K3.1 gated-DSA serving requires an SGLang build newer than 0.5.23 (the KimiK31 DSA indexer
|
| 98 |
# kernels had not landed in the released wheel at tiny-model creation time).
|
| 99 |
python3 -m sglang.launch_server \
|
| 100 |
+
--model-path scratch/kimi-k31-small \
|
| 101 |
--trust-remote-code \
|
| 102 |
--tp-size 8 \
|
| 103 |
--chunked-prefill-size 16384 \
|
|
|
|
| 107 |
--reasoning-parser kimi_k3 \
|
| 108 |
--tool-call-parser kimi_k3 \
|
| 109 |
--mem-fraction-static 0.85
|
| 110 |
+
```
|
| 111 |
|
| 112 |
### Creating this repo
|
| 113 |
|
|
|
|
| 117 |
|
| 118 |
### Change log
|
| 119 |
|
| 120 |
+
- 2026-11-05: Initial version. Kimi K3.1 Pro is K3 (69 KDA + 24 attention layers) with the 24 full-attention layers replaced by gated DSA sparse attention carrying an LSA indexer. The tiny model follows the proven tiny-random/kimi-k3 geometry (residual 8, 8 attention heads, q LoRA 128, kv LoRA 512, 17 layers in the 12 KDA + 5 DSA cadence) and keeps the source DSA indexer contract (32 index heads, head dim 128, topk 2048) on five physical layers. The MXFP4 routed-expert packing and K3 KDA/MLA compatibility patches are preserved; the released K3 remote modeling constructs the DSA layers as dense MLA because no released Transformers/SGLang runtime yet ships the K3.1 gated-DSA operator (the indexer tensors are included forward-compatibly).
|
| 121 |
|
| 122 |
*This repo is generated by GPT-6.1-Sol.*
|
config.json
CHANGED
|
@@ -97,14 +97,14 @@
|
|
| 97 |
"mla_use_nope": true,
|
| 98 |
"mla_use_output_gate": true,
|
| 99 |
"model_type": "kimi_linear",
|
| 100 |
-
"moe_intermediate_size":
|
| 101 |
"moe_layer_freq": 1,
|
| 102 |
"moe_renormalize": true,
|
| 103 |
"moe_router_activation_func": "sigmoid",
|
| 104 |
"num_attention_heads": 8,
|
| 105 |
"num_expert_group": 1,
|
| 106 |
-
"num_experts":
|
| 107 |
-
"num_experts_per_token":
|
| 108 |
"num_hidden_layers": 17,
|
| 109 |
"num_key_value_heads": 8,
|
| 110 |
"num_nextn_predict_layers": 0,
|
|
@@ -115,7 +115,7 @@
|
|
| 115 |
"prefix": null,
|
| 116 |
"problem_type": null,
|
| 117 |
"pruned_heads": {},
|
| 118 |
-
"q_lora_rank":
|
| 119 |
"qk_nope_head_dim": 128,
|
| 120 |
"qk_rope_head_dim": 64,
|
| 121 |
"return_dict": true,
|
|
@@ -125,7 +125,7 @@
|
|
| 125 |
"rope_type": "default"
|
| 126 |
},
|
| 127 |
"rope_theta": 10000.0,
|
| 128 |
-
"routed_expert_hidden_size":
|
| 129 |
"routed_scaling_factor": 1.0,
|
| 130 |
"sep_token_id": null,
|
| 131 |
"task_specific_params": null,
|
|
|
|
| 97 |
"mla_use_nope": true,
|
| 98 |
"mla_use_output_gate": true,
|
| 99 |
"model_type": "kimi_linear",
|
| 100 |
+
"moe_intermediate_size": 128,
|
| 101 |
"moe_layer_freq": 1,
|
| 102 |
"moe_renormalize": true,
|
| 103 |
"moe_router_activation_func": "sigmoid",
|
| 104 |
"num_attention_heads": 8,
|
| 105 |
"num_expert_group": 1,
|
| 106 |
+
"num_experts": 16,
|
| 107 |
+
"num_experts_per_token": 8,
|
| 108 |
"num_hidden_layers": 17,
|
| 109 |
"num_key_value_heads": 8,
|
| 110 |
"num_nextn_predict_layers": 0,
|
|
|
|
| 115 |
"prefix": null,
|
| 116 |
"problem_type": null,
|
| 117 |
"pruned_heads": {},
|
| 118 |
+
"q_lora_rank": 128,
|
| 119 |
"qk_nope_head_dim": 128,
|
| 120 |
"qk_rope_head_dim": 64,
|
| 121 |
"return_dict": true,
|
|
|
|
| 125 |
"rope_type": "default"
|
| 126 |
},
|
| 127 |
"rope_theta": 10000.0,
|
| 128 |
+
"routed_expert_hidden_size": 128,
|
| 129 |
"routed_scaling_factor": 1.0,
|
| 130 |
"sep_token_id": null,
|
| 131 |
"task_specific_params": null,
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:35842b8a041956803e5ea97e515fe0463a22a4e8b5ec1a5151868af0bebfd4be
|
| 3 |
+
size 35578920
|