Image-Text-to-Text
Transformers
Safetensors
kimi_k3
feature-extraction
vLLM
cubic-quantization
W2A8
W3A8
W4A8
W2A16
W3A16
W4A16
multimodal
custom_code
8-bit precision
Instructions to use QuantTrio/Kimi-K3-Cubic-2.5Bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use QuantTrio/Kimi-K3-Cubic-2.5Bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="QuantTrio/Kimi-K3-Cubic-2.5Bit", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("QuantTrio/Kimi-K3-Cubic-2.5Bit", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use QuantTrio/Kimi-K3-Cubic-2.5Bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "QuantTrio/Kimi-K3-Cubic-2.5Bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantTrio/Kimi-K3-Cubic-2.5Bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/QuantTrio/Kimi-K3-Cubic-2.5Bit
- SGLang
How to use QuantTrio/Kimi-K3-Cubic-2.5Bit 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 "QuantTrio/Kimi-K3-Cubic-2.5Bit" \ --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": "QuantTrio/Kimi-K3-Cubic-2.5Bit", "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 "QuantTrio/Kimi-K3-Cubic-2.5Bit" \ --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": "QuantTrio/Kimi-K3-Cubic-2.5Bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use QuantTrio/Kimi-K3-Cubic-2.5Bit with Docker Model Runner:
docker model run hf.co/QuantTrio/Kimi-K3-Cubic-2.5Bit
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +22 -9
- .ipynb_checkpoints/cubic_quantization_report-checkpoint.json +105 -0
- .mdl +0 -0
- .msc +0 -0
- .mv +1 -0
- LICENSE +52 -0
- README.md +876 -0
- assets/.gitkeep +0 -0
- assets/kimi-logo.png +0 -0
- config.json +474 -0
- configuration.json +1 -0
- configuration_kimi_k3.py +285 -0
- cubic_quantization_report.json +105 -0
- encoding_k3.py +647 -0
- generation_config.json +4 -0
- kimi_k3_processor.py +187 -0
- kimi_k3_vision_processing.py +179 -0
- media_utils.py +376 -0
- model-00001-of-00341.safetensors +3 -0
- model-00002-of-00341.safetensors +3 -0
- model-00003-of-00341.safetensors +3 -0
- model-00004-of-00341.safetensors +3 -0
- model-00005-of-00341.safetensors +3 -0
- model-00006-of-00341.safetensors +3 -0
- model-00007-of-00341.safetensors +3 -0
- model-00008-of-00341.safetensors +3 -0
- model-00009-of-00341.safetensors +3 -0
- model-00010-of-00341.safetensors +3 -0
- model-00011-of-00341.safetensors +3 -0
- model-00012-of-00341.safetensors +3 -0
- model-00013-of-00341.safetensors +3 -0
- model-00014-of-00341.safetensors +3 -0
- model-00015-of-00341.safetensors +3 -0
- model-00016-of-00341.safetensors +3 -0
- model-00017-of-00341.safetensors +3 -0
- model-00018-of-00341.safetensors +3 -0
- model-00019-of-00341.safetensors +3 -0
- model-00020-of-00341.safetensors +3 -0
- model-00021-of-00341.safetensors +3 -0
- model-00022-of-00341.safetensors +3 -0
- model-00023-of-00341.safetensors +3 -0
- model-00024-of-00341.safetensors +3 -0
- model-00025-of-00341.safetensors +3 -0
- model-00026-of-00341.safetensors +3 -0
- model-00027-of-00341.safetensors +3 -0
- model-00028-of-00341.safetensors +3 -0
- model-00029-of-00341.safetensors +3 -0
- model-00030-of-00341.safetensors +3 -0
- model-00031-of-00341.safetensors +3 -0
- model-00032-of-00341.safetensors +3 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,48 @@
|
|
| 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
|
|
|
|
|
|
| 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 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.bz2 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 |
*.model filter=lfs diff=lfs merge=lfs -text
|
| 12 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
| 13 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 14 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 15 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 16 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
| 17 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 18 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 19 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 20 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 21 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 22 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 23 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 24 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.db* filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.ark* filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*.gguf* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.ggml filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.llamafile* filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.pt2 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 46 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 47 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
"/model.safetensors.index.json" filter=lfs diff=lfs merge=lfs -text
|
.ipynb_checkpoints/cubic_quantization_report-checkpoint.json
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"manifest": {
|
| 3 |
+
"source": "/root/private_data/model/moonshotai/Kimi-K3",
|
| 4 |
+
"output": "/root/private_data/model/tclf90/Kimi-K3-Cubic-2.5Bit",
|
| 5 |
+
"temporary_output": "/root/private_data/model/tclf90/Kimi-K3-Cubic-2.5Bit.incomplete",
|
| 6 |
+
"moe_schedule": "1-3:3@256,4-32:3@512,33-91:2@512,92:4@512",
|
| 7 |
+
"linear_schedule": "",
|
| 8 |
+
"devices": [
|
| 9 |
+
"cuda:0"
|
| 10 |
+
],
|
| 11 |
+
"shard_size_gib": 3.0,
|
| 12 |
+
"a8_carrier_aware": true,
|
| 13 |
+
"a8_correction_default": "enabled",
|
| 14 |
+
"fitting_objective": "groupwise-least-squares",
|
| 15 |
+
"reported_loss": "NRMSE = sqrt(joint SSE / source weight SSE)",
|
| 16 |
+
"row_chunk_size": -1,
|
| 17 |
+
"source_shards": 96,
|
| 18 |
+
"expert_payload_bits": 2.369565217391304,
|
| 19 |
+
"expert_effective_bits": 2.498641304347826,
|
| 20 |
+
"converted_tensor_effective_bits": 2.498641304347826,
|
| 21 |
+
"worker_scheduling": "dynamic_source_shard_queue",
|
| 22 |
+
"output_partitioning": "deterministic_source_shard_index",
|
| 23 |
+
"script": "/root/private_data/quantize_k3.py",
|
| 24 |
+
"script_sha256": "49a8ddded77fe5b0dbb9273341e357881a96f6d0dcb08d620d3597286849dfb2",
|
| 25 |
+
"source_config_sha256": "9710e121a58d03ac92c8d6da287a19541994319afbbe6d6202af001ffd379213",
|
| 26 |
+
"source_index_sha256": "a1c5210650ce71d2d3ae9ec5a101ac4afd3cf4b10091be589853437eb967febd",
|
| 27 |
+
"output_shards": 341,
|
| 28 |
+
"output_total_bytes": 964943224704,
|
| 29 |
+
"combined_report": "cubic_quantization_report.json"
|
| 30 |
+
},
|
| 31 |
+
"loss_statistics": {
|
| 32 |
+
"objective": "mean(continuous MSE, rounded-A8-carrier MSE)",
|
| 33 |
+
"normalization": "loss is sqrt(joint SSE / source weight SSE), i.e. NRMSE; the fitting objective itself remains least squares.",
|
| 34 |
+
"loss_metadata_precision": "FP32 scale and FP16 a/b",
|
| 35 |
+
"by_bit": {
|
| 36 |
+
"2": {
|
| 37 |
+
"bits": 2,
|
| 38 |
+
"loss": 0.4512510036043458,
|
| 39 |
+
"clipped_percent": 12.230740958337455,
|
| 40 |
+
"a8_correction_loss": 0.4512510036043458
|
| 41 |
+
},
|
| 42 |
+
"3": {
|
| 43 |
+
"bits": 3,
|
| 44 |
+
"loss": 0.1808832329572129,
|
| 45 |
+
"clipped_percent": 2.966870049061148,
|
| 46 |
+
"a8_correction_loss": 0.18091672432952213
|
| 47 |
+
},
|
| 48 |
+
"4": {
|
| 49 |
+
"bits": 4,
|
| 50 |
+
"loss": 0.0430471542191854,
|
| 51 |
+
"clipped_percent": 0.5635438119473101,
|
| 52 |
+
"a8_correction_loss": 0.04324462046872603
|
| 53 |
+
}
|
| 54 |
+
},
|
| 55 |
+
"by_bit_and_group_size": {
|
| 56 |
+
"2@512": {
|
| 57 |
+
"bits": 2,
|
| 58 |
+
"loss": 0.4512510036043458,
|
| 59 |
+
"clipped_percent": 12.230740958337455,
|
| 60 |
+
"a8_correction_loss": 0.4512510036043458,
|
| 61 |
+
"group_size": 512
|
| 62 |
+
},
|
| 63 |
+
"3@256": {
|
| 64 |
+
"bits": 3,
|
| 65 |
+
"loss": 0.17960834694437933,
|
| 66 |
+
"clipped_percent": 2.697093164208975,
|
| 67 |
+
"a8_correction_loss": 0.17957951946425452,
|
| 68 |
+
"group_size": 256
|
| 69 |
+
},
|
| 70 |
+
"3@512": {
|
| 71 |
+
"bits": 3,
|
| 72 |
+
"loss": 0.18100745846499253,
|
| 73 |
+
"clipped_percent": 2.9947780026665454,
|
| 74 |
+
"a8_correction_loss": 0.18104699761257,
|
| 75 |
+
"group_size": 512
|
| 76 |
+
},
|
| 77 |
+
"4@512": {
|
| 78 |
+
"bits": 4,
|
| 79 |
+
"loss": 0.0430471542191854,
|
| 80 |
+
"clipped_percent": 0.5635438119473101,
|
| 81 |
+
"a8_correction_loss": 0.04324462046872603,
|
| 82 |
+
"group_size": 512
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
},
|
| 86 |
+
"audit": {
|
| 87 |
+
"checkpoint": "/root/private_data/model/tclf90/Kimi-K3-Cubic-2.5Bit.incomplete",
|
| 88 |
+
"shards": 341,
|
| 89 |
+
"tensors": 991812,
|
| 90 |
+
"total_size": 964943224704,
|
| 91 |
+
"max_shard_bytes": 3221225472,
|
| 92 |
+
"widths_present": [
|
| 93 |
+
2,
|
| 94 |
+
3,
|
| 95 |
+
4
|
| 96 |
+
],
|
| 97 |
+
"converted_tensor_effective_bits": 2.498641304347826,
|
| 98 |
+
"dtype_counts": {
|
| 99 |
+
"BF16": 2122,
|
| 100 |
+
"F32": 247802,
|
| 101 |
+
"F16": 494592,
|
| 102 |
+
"U8": 247296
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
}
|
.mdl
ADDED
|
Binary file (41 Bytes). View file
|
|
|
.msc
ADDED
|
Binary file (9.77 kB). View file
|
|
|
.mv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Revision:master,CreatedAt:1785171841
|
LICENSE
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Kimi K3 License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Moonshot AI
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person (the "Licensee")
|
| 6 |
+
obtaining a copy of this software — including the model weights, parameters,
|
| 7 |
+
configuration files, inference and training code, and associated documentation
|
| 8 |
+
(collectively, the "Software") — to deal in the Software without restriction.
|
| 9 |
+
This includes, without limitation, the rights to use, copy, modify, merge,
|
| 10 |
+
publish, distribute, sublicense, and/or sell copies of the Software; to run,
|
| 11 |
+
deploy, fine-tune, or otherwise modify the Software and create derivative works
|
| 12 |
+
from it; and to permit persons to whom the Software is furnished to do so, in
|
| 13 |
+
each case subject to the following conditions:
|
| 14 |
+
|
| 15 |
+
1. The above copyright notice and this permission notice shall be included in
|
| 16 |
+
all copies or substantial portions of the Software. Licensee's use of the
|
| 17 |
+
Software must comply with applicable laws and regulations.
|
| 18 |
+
|
| 19 |
+
2. "Model as a Service" means giving a third party access to language model
|
| 20 |
+
inference or fine-tuning (e.g., via API) in a manner that allows such third
|
| 21 |
+
party to exercise meaningful control over the inputs, parameters, or training
|
| 22 |
+
data. This does not include (a) end-user products with model capabilities solely
|
| 23 |
+
embedded within specific features or harnesses, or (b) mere relaying of requests
|
| 24 |
+
to models hosted by others.
|
| 25 |
+
|
| 26 |
+
If the Licensee or any of its affiliates operates a Model as a Service business,
|
| 27 |
+
and the aggregate revenue of the Licensee and its affiliates exceeds 20 million
|
| 28 |
+
US dollars (or the equivalent in other currencies) in total over any consecutive
|
| 29 |
+
12 months, the Licensee must enter into a separate agreement with Moonshot AI
|
| 30 |
+
before using the Software or its derivative works for any commercial purpose.
|
| 31 |
+
|
| 32 |
+
3. If the Software (or any derivative works thereof) is used for any of the
|
| 33 |
+
Licensee's commercial products or services that have more than 100 million
|
| 34 |
+
monthly active users, or more than 20 million US dollars (or equivalent in other
|
| 35 |
+
currencies) in monthly revenue, "Kimi K3" must be prominently displayed on the
|
| 36 |
+
user interface of such product or service.
|
| 37 |
+
|
| 38 |
+
4. The requirements set forth in Sections 2 and 3 do not apply to: (a) internal
|
| 39 |
+
use of the Software, defined as any use that does not make the Software, its
|
| 40 |
+
outputs, or its underlying capabilities available to third parties; or (b) any
|
| 41 |
+
use of the Software accessed through Moonshot AI's official products or
|
| 42 |
+
certified inference partners.
|
| 43 |
+
|
| 44 |
+
5. THE SOFTWARE AND ANY OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS”
|
| 45 |
+
BASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
| 46 |
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
| 47 |
+
AND NONINFRINGEMENT. IN NO EVENT SHALL MOONSHOT AI OR ITS AFFILIATES OR
|
| 48 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 49 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 50 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 51 |
+
|
| 52 |
+
For any questions regarding this license, please contact <license@moonshot.ai>.
|
README.md
ADDED
|
@@ -0,0 +1,876 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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A16
|
| 13 |
+
- W3A16
|
| 14 |
+
- W4A16
|
| 15 |
+
- multimodal
|
| 16 |
+
base_model:
|
| 17 |
+
- moonshotai/Kimi-K3
|
| 18 |
+
base_model_relation: quantized
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# Kimi-K3-Cubic-2.5Bit
|
| 22 |
+
|
| 23 |
+
Base model: [moonshotai/Kimi-K3](https://huggingface.co/moonshotai/Kimi-K3)
|
| 24 |
+
|
| 25 |
+
**2.8T parameters · 2.5-bit experts · one 8 × H200 node · ~700K context**
|
| 26 |
+
|
| 27 |
+
Kimi-K3-Cubic-2.5Bit is the first public showcase of **Cubic quantization**,
|
| 28 |
+
exploring practical ultra-low-bit, high-concurrency LLM inference.
|
| 29 |
+
|
| 30 |
+
Cubic uses parameterized, non-uniform levels that adapt to each weight group,
|
| 31 |
+
designed to challenge conventional integer and floating-point formats at
|
| 32 |
+
ultra-low precision while relaxing the usual need for small group sizes; most
|
| 33 |
+
quantized layers in this model use group size 512.
|
| 34 |
+
|
| 35 |
+
- **57 output tok/s** — single-request short-context decode
|
| 36 |
+
- **800–900+ output tok/s** — 64-way concurrency, without dSpark or other
|
| 37 |
+
speculative decoding
|
| 38 |
+
- **W1–W8 runtime kernels** — native SM80/86/89/90/90a/100/120 coverage
|
| 39 |
+
|
| 40 |
+
The export is fully data-free: no calibration dataset or activation samples
|
| 41 |
+
were used. The complete converter is included as
|
| 42 |
+
[`quantize_k3.py`](./quantize_k3.py). The same packed checkpoint runs in either
|
| 43 |
+
weight-only A16 or dynamic-A8 mode through the
|
| 44 |
+
[QuantTrio vLLM Cubic runtime](https://github.com/QuantTrio/vllm-cubic).
|
| 45 |
+
This checkpoint itself uses mixed W2, W3, and W4 expert weights with an audited
|
| 46 |
+
effective width of **2.4986 bits**.
|
| 47 |
+
|
| 48 |
+
### 【Quantization Policy】
|
| 49 |
+
|
| 50 |
+
| Scope | Format |
|
| 51 |
+
|-------|--------|
|
| 52 |
+
| Dense layer 0 | Source dtype (BF16) |
|
| 53 |
+
| MoE layers 1–3 routed experts | Cubic W3, group size 256 |
|
| 54 |
+
| MoE layers 4–32 routed experts | Cubic W3, group size 512 |
|
| 55 |
+
| MoE layers 33–91 routed experts | Cubic W2, group size 512 |
|
| 56 |
+
| MoE layer 92 routed experts | Cubic W4, group size 512 |
|
| 57 |
+
| Attention/KDA/MLA weights | Source dtype (BF16) |
|
| 58 |
+
| Shared experts and ordinary MLP weights | Source dtype (BF16) |
|
| 59 |
+
| Vision tower, multimodal projector, embeddings, norms, and LM head | Source dtype |
|
| 60 |
+
|
| 61 |
+
`Loss` is the scale-free NRMSE of groupwise weight reconstruction, not a
|
| 62 |
+
downstream task-accuracy score.
|
| 63 |
+
|
| 64 |
+
| Format | Loss | Clipped values |
|
| 65 |
+
|--------|-----:|---------------:|
|
| 66 |
+
| W2, group size 512 | 0.451251 | 12.2307% |
|
| 67 |
+
| W3, group size 256 | 0.179608 | 2.6971% |
|
| 68 |
+
| W3, group size 512 | 0.181007 | 2.9948% |
|
| 69 |
+
| W4, group size 512 | 0.043047 | 0.5635% |
|
| 70 |
+
|
| 71 |
+
### 【Dependencies / Installation】
|
| 72 |
+
|
| 73 |
+
- Runtime: [vLLM Cubic v0.26.1+cubic.20260805](https://github.com/QuantTrio/vllm-cubic/releases/tag/v0.26.1%2Bcubic.20260805)
|
| 74 |
+
- Python: 3.10–3.14
|
| 75 |
+
- Platform: Linux x86-64, PyTorch 2.13.0, CUDA 13.0
|
| 76 |
+
- Verified: Python 3.12, 8 × H200, TP8 + EP
|
| 77 |
+
|
| 78 |
+
Install:
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
uv venv --python 3.12 .venv
|
| 82 |
+
source .venv/bin/activate
|
| 83 |
+
uv pip install \
|
| 84 |
+
'https://github.com/QuantTrio/vllm-cubic/releases/download/v0.26.1%2Bcubic.20260805/vllm-0.26.1%2Bcubic.20260805-cp38-abi3-linux_x86_64.whl'
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### 【Quantization Script】
|
| 88 |
+
|
| 89 |
+
- Script: [`quantize_k3.py`](./quantize_k3.py) ([source](https://github.com/QuantTrio/vllm-cubic/blob/main/examples/quantization/quantize_k3.py))
|
| 90 |
+
- Input: original `moonshotai/Kimi-K3` MXFP4 checkpoint
|
| 91 |
+
- Method: data-free; dynamic-A8 carrier correction on by default (`--disable-a8-correction` to disable)
|
| 92 |
+
- Time: approximately **35–40 minutes on 8 × H200** with fast local storage
|
| 93 |
+
- Dependencies: included with vLLM Cubic; standalone: `pip install torch safetensors regex`
|
| 94 |
+
- Output: destination path must not already exist
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
python -u quantize_k3.py \
|
| 98 |
+
--source __YOUR_PATH__/moonshotai/Kimi-K3 \
|
| 99 |
+
--output __YOUR_PATH__/Kimi-K3-Cubic-2.5Bit \
|
| 100 |
+
--devices cuda:0,cuda:1,cuda:2,cuda:3,cuda:4,cuda:5,cuda:6,cuda:7
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### 【vLLM Startup Command】
|
| 104 |
+
|
| 105 |
+
The following command enables dynamic A8 Cubic execution. Change
|
| 106 |
+
`VLLM_CUBIC_DYNAMIC_A8` to `0` to run the same checkpoint in weight-only A16
|
| 107 |
+
mode.
|
| 108 |
+
|
| 109 |
+
```bash
|
| 110 |
+
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
|
| 111 |
+
export VLLM_CUBIC_DYNAMIC_A8=1
|
| 112 |
+
|
| 113 |
+
vllm serve \
|
| 114 |
+
__YOUR_PATH__/Kimi-K3-Cubic-2.5Bit \
|
| 115 |
+
--served-model-name Kimi-K3-Cubic-2.5Bit \
|
| 116 |
+
--trust-remote-code \
|
| 117 |
+
--quantization cubic \
|
| 118 |
+
--kv-cache-dtype fp8_q16 \
|
| 119 |
+
--gpu-memory-utilization 0.985 \
|
| 120 |
+
--tensor-parallel-size 8 \
|
| 121 |
+
--enable-expert-parallel \
|
| 122 |
+
--mm-encoder-tp-mode data \
|
| 123 |
+
--max-model-len auto \
|
| 124 |
+
--max-num-seqs 128 \
|
| 125 |
+
--max-num-batched-tokens 2048 \
|
| 126 |
+
--enable-prefix-caching \
|
| 127 |
+
--enable-auto-tool-choice \
|
| 128 |
+
--tool-call-parser kimi_k3 \
|
| 129 |
+
--reasoning-parser kimi_k3 \
|
| 130 |
+
--host 0.0.0.0 \
|
| 131 |
+
--port 8000 \
|
| 132 |
+
--disable-uvicorn-access-log
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
Observed performance for this command on 8 × NVIDIA H200 141GB
|
| 136 |
+
(2026-08-05) is:
|
| 137 |
+
|
| 138 |
+
| Item | Observed value |
|
| 139 |
+
|------|---------------:|
|
| 140 |
+
| Dynamic Cubic mode | A8 |
|
| 141 |
+
| Parallel topology | TP8 + EP |
|
| 142 |
+
| KV-cache dtype | `fp8_q16` |
|
| 143 |
+
| Effective maximum model length | 728,640 tokens |
|
| 144 |
+
| Single-request short-context decode | approximately 57 output tok/s |
|
| 145 |
+
| 64-request aggregate decode | approximately 800–900+ output tok/s |
|
| 146 |
+
| Speculative decoding | None; dSpark was not used |
|
| 147 |
+
|
| 148 |
+
The throughput values are stable decode-window measurements from short-prompt,
|
| 149 |
+
long-output text requests, rather than end-to-end request throughput. Prompt
|
| 150 |
+
length, generated context length, sampling, concurrent prefill, GPU clocks, and
|
| 151 |
+
other workloads can change the result. Because `--max-model-len auto` derives
|
| 152 |
+
the limit from free memory measured during startup, the effective token count
|
| 153 |
+
can also vary slightly between launches.
|
| 154 |
+
|
| 155 |
+
`fp8_q16` is an optional query-preserving FP8 KV-cache mode from the Cubic
|
| 156 |
+
runtime. It keeps attention queries in the model dtype and automatically
|
| 157 |
+
selects a compatible attention backend. To use a conventional BF16 KV cache,
|
| 158 |
+
replace it with `--kv-cache-dtype auto`; this reduces the available context
|
| 159 |
+
length but provides the highest-precision KV storage.
|
| 160 |
+
|
| 161 |
+
The first launch may spend several minutes compiling Triton kernels,
|
| 162 |
+
calibrating Cubic kernel choices for the tensors and GPU type in use, and
|
| 163 |
+
capturing CUDA graphs. Calibration results are persisted in the Triton cache
|
| 164 |
+
and reused by later launches on compatible devices.
|
| 165 |
+
|
| 166 |
+
### 【Validation Status】
|
| 167 |
+
|
| 168 |
+
- 8 × H200 TP8 + EP model loading and text generation verified.
|
| 169 |
+
- Weight-only A16 and dynamic-A8 execution verified with the same checkpoint.
|
| 170 |
+
- `fp8_q16` and BF16 KV-cache serving paths verified.
|
| 171 |
+
- No formal downstream benchmark is claimed for this quantized checkpoint;
|
| 172 |
+
evaluate quality and performance for your own workloads before deployment.
|
| 173 |
+
|
| 174 |
+
### 【Model Files】
|
| 175 |
+
|
| 176 |
+
| Item | Value |
|
| 177 |
+
|------|-------|
|
| 178 |
+
| Model data | 899 GiB |
|
| 179 |
+
| Safetensors shards | 341 |
|
| 180 |
+
| Last updated | 2026-08-05 |
|
| 181 |
+
|
| 182 |
+
### 【Model Download】
|
| 183 |
+
|
| 184 |
+
```python
|
| 185 |
+
from huggingface_hub import snapshot_download
|
| 186 |
+
|
| 187 |
+
snapshot_download(
|
| 188 |
+
"QuantTrio/Kimi-K3-Cubic-2.5Bit",
|
| 189 |
+
local_dir="your_local_path/Kimi-K3-Cubic-2.5Bit",
|
| 190 |
+
)
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
### 【License】
|
| 194 |
+
|
| 195 |
+
This quantized checkpoint is derived from Kimi K3 and remains subject to the
|
| 196 |
+
[Kimi K3 License](https://huggingface.co/moonshotai/Kimi-K3/blob/main/LICENSE).
|
| 197 |
+
The QuantTrio vLLM Cubic runtime is distributed separately under its own
|
| 198 |
+
repository license.
|
| 199 |
+
|
| 200 |
+
### 【Base Model Overview】
|
| 201 |
+
|
| 202 |
+
The following material is reproduced from the upstream Kimi K3 model card and
|
| 203 |
+
describes the base model. Upstream MXFP4 deployment instructions do not apply
|
| 204 |
+
to this Cubic checkpoint; use the Cubic installation and launch command above.
|
| 205 |
+
|
| 206 |
+
<div align="center">
|
| 207 |
+
<picture>
|
| 208 |
+
<img src="assets/kimi-logo.png" width="30%" alt="Kimi K3">
|
| 209 |
+
</picture>
|
| 210 |
+
</div>
|
| 211 |
+
<hr>
|
| 212 |
+
<div align="center" style="line-height:1">
|
| 213 |
+
<a href="https://www.kimi.com" target="_blank"><img alt="Chat" src="https://img.shields.io/badge/🤖%20Chat-Kimi%20K3-ff6b6b?color=1783ff&logoColor=white"/></a>
|
| 214 |
+
<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>
|
| 215 |
+
</div>
|
| 216 |
+
|
| 217 |
+
<div align="center" style="line-height: 1;">
|
| 218 |
+
<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>
|
| 219 |
+
<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>
|
| 220 |
+
<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>
|
| 221 |
+
<a href="https://modelscope.cn/organization/moonshotai" target="_blank"><img alt="ModelScope" src="https://img.shields.io/badge/ModelScope-Moonshot%20AI-white?labelColor=rgb(99%2C%2074%2C%255)"/></a>
|
| 222 |
+
</div>
|
| 223 |
+
<div align="center" style="line-height: 1;">
|
| 224 |
+
<a href="https://huggingface.co/moonshotai/Kimi-K3/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Kimi_K3-f5de53?&color=f5de53"/></a>
|
| 225 |
+
</div>
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
<p align="center">
|
| 229 |
+
📰 <a href="https://www.kimi.com/blog/kimi-k3">Tech Blog</a> | <b>📄 <a href="https://github.com/MoonshotAI/Kimi-K3/blob/main/k3_tech_report.pdf">Full Report</a></b>
|
| 230 |
+
</p>
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
## 1. Model Introduction
|
| 235 |
+
|
| 236 |
+
Kimi K3 is an open-weight, native multimodal agentic model and our most capable model to date. It is a 2.8T-parameter model built on Kimi Delta Attention (KDA) and Attention Residuals (AttnRes), with native vision capabilities and a 1-million-token context window. It is the world's first open 3T-class model, designed for frontier intelligence across long-horizon coding, knowledge work, and reasoning.
|
| 237 |
+
|
| 238 |
+
### Key Features
|
| 239 |
+
- **New Architecture**: Kimi K3 is built on Kimi Delta Attention (KDA) and Attention Residuals (AttnRes), and scales up MoE sparsity with a Stable LatentMoE framework that activates 16 out of 896 experts — yielding an approximate 2.5× improvement in overall scaling efficiency over Kimi K2.
|
| 240 |
+
- **Long-Horizon Coding**: Operating with minimal human oversight, Kimi K3 sustains long engineering sessions, navigates massive repositories, and orchestrates terminal tools — from GPU kernel optimization and compiler development to vision-in-the-loop game dev, CAD, and even chip design.
|
| 241 |
+
- **Agentic Knowledge Work**: Kimi K3 advances end-to-end knowledge work, producing deep research with interactive visualizations, widgets and dashboards, and motion design and video editing, powered by its native multimodal architecture.
|
| 242 |
+
- **Native Multimodality & Long Context**: Kimi K3 understands text, images, and video within the same model, and supports a 1-million-token context window.
|
| 243 |
+
- **Open Frontier Weights**: We release the full Kimi K3 model weights under the Kimi K3 License, making frontier intelligence openly available for research, deployment, and further innovation.
|
| 244 |
+
## 2. Model Summary
|
| 245 |
+
|
| 246 |
+
<div align="center">
|
| 247 |
+
<table>
|
| 248 |
+
<tbody>
|
| 249 |
+
<tr>
|
| 250 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Architecture</strong></td>
|
| 251 |
+
<td align="center" style="vertical-align: middle; text-align: center">Mixture-of-Experts (MoE)</td>
|
| 252 |
+
</tr>
|
| 253 |
+
<tr>
|
| 254 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Total Parameters</strong></td>
|
| 255 |
+
<td align="center" style="vertical-align: middle; text-align: center">2.8T</td>
|
| 256 |
+
</tr>
|
| 257 |
+
<tr>
|
| 258 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Activated Parameters</strong></td>
|
| 259 |
+
<td align="center" style="vertical-align: middle; text-align: center">104B</td>
|
| 260 |
+
</tr>
|
| 261 |
+
<tr>
|
| 262 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Number of Layers</strong></td>
|
| 263 |
+
<td align="center" style="vertical-align: middle; text-align: center">93</td>
|
| 264 |
+
</tr>
|
| 265 |
+
<tr>
|
| 266 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Number of Dense Layers</strong></td>
|
| 267 |
+
<td align="center" style="vertical-align: middle; text-align: center">1</td>
|
| 268 |
+
</tr>
|
| 269 |
+
<tr>
|
| 270 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Attention-Layer Composition</strong></td>
|
| 271 |
+
<td align="center" style="vertical-align: middle; text-align: center">69 KDA + 24 Gated MLA</td>
|
| 272 |
+
</tr>
|
| 273 |
+
<tr>
|
| 274 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Attention Hidden Dimension</strong></td>
|
| 275 |
+
<td align="center" style="vertical-align: middle; text-align: center">7168</td>
|
| 276 |
+
</tr>
|
| 277 |
+
<tr>
|
| 278 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Number of Attention Heads</strong></td>
|
| 279 |
+
<td align="center" style="vertical-align: middle; text-align: center">96</td>
|
| 280 |
+
</tr>
|
| 281 |
+
<tr>
|
| 282 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Latent MoE Dimension</strong></td>
|
| 283 |
+
<td align="center" style="vertical-align: middle; text-align: center">3584</td>
|
| 284 |
+
</tr>
|
| 285 |
+
<tr>
|
| 286 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>MoE Hidden Dimension</strong> (per Expert)</td>
|
| 287 |
+
<td align="center" style="vertical-align: middle; text-align: center">3072</td>
|
| 288 |
+
</tr>
|
| 289 |
+
<tr>
|
| 290 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Number of Experts</strong></td>
|
| 291 |
+
<td align="center" style="vertical-align: middle; text-align: center">896</td>
|
| 292 |
+
</tr>
|
| 293 |
+
<tr>
|
| 294 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Selected Experts per Token</strong></td>
|
| 295 |
+
<td align="center" style="vertical-align: middle; text-align: center">16</td>
|
| 296 |
+
</tr>
|
| 297 |
+
<tr>
|
| 298 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Number of Shared Experts</strong></td>
|
| 299 |
+
<td align="center" style="vertical-align: middle; text-align: center">2</td>
|
| 300 |
+
</tr>
|
| 301 |
+
<tr>
|
| 302 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Vocabulary Size</strong></td>
|
| 303 |
+
<td align="center" style="vertical-align: middle; text-align: center">160K</td>
|
| 304 |
+
</tr>
|
| 305 |
+
<tr>
|
| 306 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Context Length</strong></td>
|
| 307 |
+
<td align="center" style="vertical-align: middle; text-align: center">1048576</td>
|
| 308 |
+
</tr>
|
| 309 |
+
<tr>
|
| 310 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Attention Mechanism</strong></td>
|
| 311 |
+
<td align="center" style="vertical-align: middle; text-align: center">KDA & Gated MLA</td>
|
| 312 |
+
</tr>
|
| 313 |
+
<tr>
|
| 314 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Activation Function</strong></td>
|
| 315 |
+
<td align="center" style="vertical-align: middle; text-align: center">SiTU-GLU</td>
|
| 316 |
+
</tr>
|
| 317 |
+
<tr>
|
| 318 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Vision Encoder</strong></td>
|
| 319 |
+
<td align="center" style="vertical-align: middle; text-align: center">MoonViT-V2</td>
|
| 320 |
+
</tr>
|
| 321 |
+
<tr>
|
| 322 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Parameters of Vision Encoder</strong></td>
|
| 323 |
+
<td align="center" style="vertical-align: middle; text-align: center">401M</td>
|
| 324 |
+
</tr>
|
| 325 |
+
<tr>
|
| 326 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Quantization</strong></td>
|
| 327 |
+
<td align="center" style="vertical-align: middle; text-align: center">MXFP4 weights / MXFP8 activations<br>(quantization-aware training)</td>
|
| 328 |
+
</tr>
|
| 329 |
+
<tr>
|
| 330 |
+
<td align="center" style="vertical-align: middle; text-align: center"><strong>Modality</strong></td>
|
| 331 |
+
<td align="center" style="vertical-align: middle; text-align: center">Text, Image</td>
|
| 332 |
+
</tr>
|
| 333 |
+
</tbody>
|
| 334 |
+
</table>
|
| 335 |
+
</div>
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
## 3. Evaluation Results
|
| 339 |
+
|
| 340 |
+
<div align="center">
|
| 341 |
+
<table>
|
| 342 |
+
<thead>
|
| 343 |
+
<tr>
|
| 344 |
+
<th align="center" style="text-align: center">Benchmark</th>
|
| 345 |
+
<th align="center" style="text-align: center"><sup>Kimi K3<br><sup>(max)</sup></sup></th>
|
| 346 |
+
<th align="center" style="text-align: center"><sup>Claude Fable 5<br><sup>(max, w/ fallback)</sup></sup></th>
|
| 347 |
+
<th align="center" style="text-align: center"><sup>GPT-5.6 Sol<br><sup>(max)</sup></sup></th>
|
| 348 |
+
<th align="center" style="text-align: center"><sup>Claude Opus 4.8<br><sup>(max)</sup></sup></th>
|
| 349 |
+
<th align="center" style="text-align: center"><sup>GPT-5.5<br><sup>(xhigh)</sup></sup></th>
|
| 350 |
+
<th align="center" style="text-align: center"><sup>GLM-5.2<br><sup>(max)</sup></sup></th>
|
| 351 |
+
</tr>
|
| 352 |
+
</thead>
|
| 353 |
+
<tbody>
|
| 354 |
+
<tr>
|
| 355 |
+
<td align="center" colspan=7 style="text-align: center"><strong>Reasoning & Knowledge</strong></td>
|
| 356 |
+
</tr>
|
| 357 |
+
<tr>
|
| 358 |
+
<td align="center" style="vertical-align: middle; text-align: center">GPQA Diamond</td>
|
| 359 |
+
<td align="center" style="vertical-align: middle; text-align: center">93.5</td>
|
| 360 |
+
<td align="center" style="vertical-align: middle; text-align: center">92.6</td>
|
| 361 |
+
<td align="center" style="vertical-align: middle; text-align: center">94.1</td>
|
| 362 |
+
<td align="center" style="vertical-align: middle; text-align: center">91.0</td>
|
| 363 |
+
<td align="center" style="vertical-align: middle; text-align: center">93.5</td>
|
| 364 |
+
<td align="center" style="vertical-align: middle; text-align: center">91.2</td>
|
| 365 |
+
</tr>
|
| 366 |
+
<tr>
|
| 367 |
+
<td align="center" style="vertical-align: middle; text-align: center">CritPt</td>
|
| 368 |
+
<td align="center" style="vertical-align: middle; text-align: center">23.4</td>
|
| 369 |
+
<td align="center" style="vertical-align: middle; text-align: center">28.6</td>
|
| 370 |
+
<td align="center" style="vertical-align: middle; text-align: center">32.3</td>
|
| 371 |
+
<td align="center" style="vertical-align: middle; text-align: center">20.9</td>
|
| 372 |
+
<td align="center" style="vertical-align: middle; text-align: center">27.1</td>
|
| 373 |
+
<td align="center" style="vertical-align: middle; text-align: center">20.9</td>
|
| 374 |
+
</tr>
|
| 375 |
+
<tr>
|
| 376 |
+
<td align="center" style="vertical-align: middle; text-align: center">AA-LCR</td>
|
| 377 |
+
<td align="center" style="vertical-align: middle; text-align: center">74.7</td>
|
| 378 |
+
<td align="center" style="vertical-align: middle; text-align: center">70.0</td>
|
| 379 |
+
<td align="center" style="vertical-align: middle; text-align: center">73.7</td>
|
| 380 |
+
<td align="center" style="vertical-align: middle; text-align: center">67.7</td>
|
| 381 |
+
<td align="center" style="vertical-align: middle; text-align: center">74.3</td>
|
| 382 |
+
<td align="center" style="vertical-align: middle; text-align: center">71.3</td>
|
| 383 |
+
</tr>
|
| 384 |
+
<tr>
|
| 385 |
+
<td align="center" style="vertical-align: middle; text-align: center">HLE-Full</td>
|
| 386 |
+
<td align="center" style="vertical-align: middle; text-align: center">43.5 / 56.0</td>
|
| 387 |
+
<td align="center" style="vertical-align: middle; text-align: center">53.3 / 63.0</td>
|
| 388 |
+
<td align="center" style="vertical-align: middle; text-align: center">44.5 / 58.0</td>
|
| 389 |
+
<td align="center" style="vertical-align: middle; text-align: center">49.8 / 57.9</td>
|
| 390 |
+
<td align="center" style="vertical-align: middle; text-align: center">41.4 / 52.2</td>
|
| 391 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 392 |
+
</tr>
|
| 393 |
+
<tr>
|
| 394 |
+
<td align="center" colspan=7 style="text-align: center"><strong>Coding</strong></td>
|
| 395 |
+
</tr>
|
| 396 |
+
<tr>
|
| 397 |
+
<td align="center" style="vertical-align: middle; text-align: center">DeepSWE</td>
|
| 398 |
+
<td align="center" style="vertical-align: middle; text-align: center">67.5</td>
|
| 399 |
+
<td align="center" style="vertical-align: middle; text-align: center">70.0</td>
|
| 400 |
+
<td align="center" style="vertical-align: middle; text-align: center">73.0</td>
|
| 401 |
+
<td align="center" style="vertical-align: middle; text-align: center">59.0</td>
|
| 402 |
+
<td align="center" style="vertical-align: middle; text-align: center">67.0</td>
|
| 403 |
+
<td align="center" style="vertical-align: middle; text-align: center">46.2</td>
|
| 404 |
+
</tr>
|
| 405 |
+
<tr>
|
| 406 |
+
<td align="center" style="vertical-align: middle; text-align: center">ProgramBench</td>
|
| 407 |
+
<td align="center" style="vertical-align: middle; text-align: center">77.8</td>
|
| 408 |
+
<td align="center" style="vertical-align: middle; text-align: center">76.8</td>
|
| 409 |
+
<td align="center" style="vertical-align: middle; text-align: center">77.6</td>
|
| 410 |
+
<td align="center" style="vertical-align: middle; text-align: center">71.9</td>
|
| 411 |
+
<td align="center" style="vertical-align: middle; text-align: center">70.8</td>
|
| 412 |
+
<td align="center" style="vertical-align: middle; text-align: center">63.7</td>
|
| 413 |
+
</tr>
|
| 414 |
+
<tr>
|
| 415 |
+
<td align="center" style="vertical-align: middle; text-align: center">Terminal-Bench 2.1</td>
|
| 416 |
+
<td align="center" style="vertical-align: middle; text-align: center">88.3</td>
|
| 417 |
+
<td align="center" style="vertical-align: middle; text-align: center">88.0</td>
|
| 418 |
+
<td align="center" style="vertical-align: middle; text-align: center">88.8</td>
|
| 419 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.6</td>
|
| 420 |
+
<td align="center" style="vertical-align: middle; text-align: center">83.4</td>
|
| 421 |
+
<td align="center" style="vertical-align: middle; text-align: center">82.7</td>
|
| 422 |
+
</tr>
|
| 423 |
+
<tr>
|
| 424 |
+
<td align="center" style="vertical-align: middle; text-align: center">FrontierSWE</td>
|
| 425 |
+
<td align="center" style="vertical-align: middle; text-align: center">81.2</td>
|
| 426 |
+
<td align="center" style="vertical-align: middle; text-align: center">86.6</td>
|
| 427 |
+
<td align="center" style="vertical-align: middle; text-align: center">71.3</td>
|
| 428 |
+
<td align="center" style="vertical-align: middle; text-align: center">66.7</td>
|
| 429 |
+
<td align="center" style="vertical-align: middle; text-align: center">64.9</td>
|
| 430 |
+
<td align="center" style="vertical-align: middle; text-align: center">67.3</td>
|
| 431 |
+
</tr>
|
| 432 |
+
<tr>
|
| 433 |
+
<td align="center" style="vertical-align: middle; text-align: center">SWE-Marathon</td>
|
| 434 |
+
<td align="center" style="vertical-align: middle; text-align: center">42.0</td>
|
| 435 |
+
<td align="center" style="vertical-align: middle; text-align: center">35.0</td>
|
| 436 |
+
<td align="center" style="vertical-align: middle; text-align: center">39.0</td>
|
| 437 |
+
<td align="center" style="vertical-align: middle; text-align: center">40.0</td>
|
| 438 |
+
<td align="center" style="vertical-align: middle; text-align: center">14.0</td>
|
| 439 |
+
<td align="center" style="vertical-align: middle; text-align: center">13.0</td>
|
| 440 |
+
</tr>
|
| 441 |
+
<tr>
|
| 442 |
+
<td align="center" style="vertical-align: middle; text-align: center">PostTrainBench</td>
|
| 443 |
+
<td align="center" style="vertical-align: middle; text-align: center">36.6</td>
|
| 444 |
+
<td align="center" style="vertical-align: middle; text-align: center">41.4</td>
|
| 445 |
+
<td align="center" style="vertical-align: middle; text-align: center">34.6</td>
|
| 446 |
+
<td align="center" style="vertical-align: middle; text-align: center">34.1</td>
|
| 447 |
+
<td align="center" style="vertical-align: middle; text-align: center">28.4</td>
|
| 448 |
+
<td align="center" style="vertical-align: middle; text-align: center">34.3</td>
|
| 449 |
+
</tr>
|
| 450 |
+
<tr>
|
| 451 |
+
<td align="center" style="vertical-align: middle; text-align: center">MLS-Bench-Lite</td>
|
| 452 |
+
<td align="center" style="vertical-align: middle; text-align: center">48.3</td>
|
| 453 |
+
<td align="center" style="vertical-align: middle; text-align: center">49.9</td>
|
| 454 |
+
<td align="center" style="vertical-align: middle; text-align: center">46.2</td>
|
| 455 |
+
<td align="center" style="vertical-align: middle; text-align: center">42.8</td>
|
| 456 |
+
<td align="center" style="vertical-align: middle; text-align: center">35.5</td>
|
| 457 |
+
<td align="center" style="vertical-align: middle; text-align: center">40.4</td>
|
| 458 |
+
</tr>
|
| 459 |
+
<tr>
|
| 460 |
+
<td align="center" style="vertical-align: middle; text-align: center">SciCode</td>
|
| 461 |
+
<td align="center" style="vertical-align: middle; text-align: center">58.7</td>
|
| 462 |
+
<td align="center" style="vertical-align: middle; text-align: center">60.2</td>
|
| 463 |
+
<td align="center" style="vertical-align: middle; text-align: center">56.1</td>
|
| 464 |
+
<td align="center" style="vertical-align: middle; text-align: center">53.5</td>
|
| 465 |
+
<td align="center" style="vertical-align: middle; text-align: center">56.1</td>
|
| 466 |
+
<td align="center" style="vertical-align: middle; text-align: center">50.5</td>
|
| 467 |
+
</tr>
|
| 468 |
+
<tr>
|
| 469 |
+
<td align="center" style="vertical-align: middle; text-align: center">Kimi Code Bench 2.0</td>
|
| 470 |
+
<td align="center" style="vertical-align: middle; text-align: center">72.9</td>
|
| 471 |
+
<td align="center" style="vertical-align: middle; text-align: center">76.9</td>
|
| 472 |
+
<td align="center" style="vertical-align: middle; text-align: center">64.8</td>
|
| 473 |
+
<td align="center" style="vertical-align: middle; text-align: center">71.7</td>
|
| 474 |
+
<td align="center" style="vertical-align: middle; text-align: center">69.0</td>
|
| 475 |
+
<td align="center" style="vertical-align: middle; text-align: center">64.2</td>
|
| 476 |
+
</tr>
|
| 477 |
+
<tr>
|
| 478 |
+
<td align="center" colspan=7 style="text-align: center"><strong>Agentic</strong></td>
|
| 479 |
+
</tr>
|
| 480 |
+
<tr>
|
| 481 |
+
<td align="center" style="vertical-align: middle; text-align: center">BrowseComp</td>
|
| 482 |
+
<td align="center" style="vertical-align: middle; text-align: center">91.2</td>
|
| 483 |
+
<td align="center" style="vertical-align: middle; text-align: center">88.0</td>
|
| 484 |
+
<td align="center" style="vertical-align: middle; text-align: center">90.4</td>
|
| 485 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.3</td>
|
| 486 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.4</td>
|
| 487 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 488 |
+
</tr>
|
| 489 |
+
<tr>
|
| 490 |
+
<td align="center" style="vertical-align: middle; text-align: center">DeepSearchQA (F1)</td>
|
| 491 |
+
<td align="center" style="vertical-align: middle; text-align: center">95.0</td>
|
| 492 |
+
<td align="center" style="vertical-align: middle; text-align: center">94.2</td>
|
| 493 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 494 |
+
<td align="center" style="vertical-align: middle; text-align: center">93.1</td>
|
| 495 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 496 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 497 |
+
</tr>
|
| 498 |
+
<tr>
|
| 499 |
+
<td align="center" style="vertical-align: middle; text-align: center">ResearchRubrics</td>
|
| 500 |
+
<td align="center" style="vertical-align: middle; text-align: center">76.2</td>
|
| 501 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 502 |
+
<td align="center" style="vertical-align: middle; text-align: center">73.8</td>
|
| 503 |
+
<td align="center" style="vertical-align: middle; text-align: center">73.5</td>
|
| 504 |
+
<td align="center" style="vertical-align: middle; text-align: center">64.0</td>
|
| 505 |
+
<td align="center" style="vertical-align: middle; text-align: center">71.1</td>
|
| 506 |
+
</tr>
|
| 507 |
+
<tr>
|
| 508 |
+
<td align="center" style="vertical-align: middle; text-align: center">GDPval-AA v2 (Elo)</td>
|
| 509 |
+
<td align="center" style="vertical-align: middle; text-align: center">1686</td>
|
| 510 |
+
<td align="center" style="vertical-align: middle; text-align: center">1747</td>
|
| 511 |
+
<td align="center" style="vertical-align: middle; text-align: center">1736</td>
|
| 512 |
+
<td align="center" style="vertical-align: middle; text-align: center">1593</td>
|
| 513 |
+
<td align="center" style="vertical-align: middle; text-align: center">1491</td>
|
| 514 |
+
<td align="center" style="vertical-align: middle; text-align: center">1510</td>
|
| 515 |
+
</tr>
|
| 516 |
+
<tr>
|
| 517 |
+
<td align="center" style="vertical-align: middle; text-align: center">Toolathlon-Verified</td>
|
| 518 |
+
<td align="center" style="vertical-align: middle; text-align: center">76.5</td>
|
| 519 |
+
<td align="center" style="vertical-align: middle; text-align: center">77.9</td>
|
| 520 |
+
<td align="center" style="vertical-align: middle; text-align: center">74.9</td>
|
| 521 |
+
<td align="center" style="vertical-align: middle; text-align: center">76.2</td>
|
| 522 |
+
<td align="center" style="vertical-align: middle; text-align: center">73.5</td>
|
| 523 |
+
<td align="center" style="vertical-align: middle; text-align: center">59.9</td>
|
| 524 |
+
</tr>
|
| 525 |
+
<tr>
|
| 526 |
+
<td align="center" style="vertical-align: middle; text-align: center">MCPMark-Verified</td>
|
| 527 |
+
<td align="center" style="vertical-align: middle; text-align: center">94.5</td>
|
| 528 |
+
<td align="center" style="vertical-align: middle; text-align: center">87.4</td>
|
| 529 |
+
<td align="center" style="vertical-align: middle; text-align: center">92.9</td>
|
| 530 |
+
<td align="center" style="vertical-align: middle; text-align: center">76.4</td>
|
| 531 |
+
<td align="center" style="vertical-align: middle; text-align: center">92.9</td>
|
| 532 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 533 |
+
</tr>
|
| 534 |
+
<tr>
|
| 535 |
+
<td align="center" style="vertical-align: middle; text-align: center">MCP-Atlas</td>
|
| 536 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.2</td>
|
| 537 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.7</td>
|
| 538 |
+
<td align="center" style="vertical-align: middle; text-align: center">83.6</td>
|
| 539 |
+
<td align="center" style="vertical-align: middle; text-align: center">83.6</td>
|
| 540 |
+
<td align="center" style="vertical-align: middle; text-align: center">82.8</td>
|
| 541 |
+
<td align="center" style="vertical-align: middle; text-align: center">82.6</td>
|
| 542 |
+
</tr>
|
| 543 |
+
<tr>
|
| 544 |
+
<td align="center" style="vertical-align: middle; text-align: center">AutomationBench</td>
|
| 545 |
+
<td align="center" style="vertical-align: middle; text-align: center">30.8</td>
|
| 546 |
+
<td align="center" style="vertical-align: middle; text-align: center">29.1</td>
|
| 547 |
+
<td align="center" style="vertical-align: middle; text-align: center">29.7</td>
|
| 548 |
+
<td align="center" style="vertical-align: middle; text-align: center">27.2</td>
|
| 549 |
+
<td align="center" style="vertical-align: middle; text-align: center">22.7</td>
|
| 550 |
+
<td align="center" style="vertical-align: middle; text-align: center">12.9</td>
|
| 551 |
+
</tr>
|
| 552 |
+
<tr>
|
| 553 |
+
<td align="center" style="vertical-align: middle; text-align: center">JobBench</td>
|
| 554 |
+
<td align="center" style="vertical-align: middle; text-align: center">54.3</td>
|
| 555 |
+
<td align="center" style="vertical-align: middle; text-align: center">57.4</td>
|
| 556 |
+
<td align="center" style="vertical-align: middle; text-align: center">45.4</td>
|
| 557 |
+
<td align="center" style="vertical-align: middle; text-align: center">48.4</td>
|
| 558 |
+
<td align="center" style="vertical-align: middle; text-align: center">38.3</td>
|
| 559 |
+
<td align="center" style="vertical-align: middle; text-align: center">43.4</td>
|
| 560 |
+
</tr>
|
| 561 |
+
<tr>
|
| 562 |
+
<td align="center" style="vertical-align: middle; text-align: center">AA-Briefcase (Elo)</td>
|
| 563 |
+
<td align="center" style="vertical-align: middle; text-align: center">1548</td>
|
| 564 |
+
<td align="center" style="vertical-align: middle; text-align: center">1583</td>
|
| 565 |
+
<td align="center" style="vertical-align: middle; text-align: center">1495</td>
|
| 566 |
+
<td align="center" style="vertical-align: middle; text-align: center">1354</td>
|
| 567 |
+
<td align="center" style="vertical-align: middle; text-align: center">1158</td>
|
| 568 |
+
<td align="center" style="vertical-align: middle; text-align: center">1260</td>
|
| 569 |
+
</tr>
|
| 570 |
+
<tr>
|
| 571 |
+
<td align="center" style="vertical-align: middle; text-align: center">Agents' Last Exam</td>
|
| 572 |
+
<td align="center" style="vertical-align: middle; text-align: center">28.3</td>
|
| 573 |
+
<td align="center" style="vertical-align: middle; text-align: center">25.7<sup>†</sup></td>
|
| 574 |
+
<td align="center" style="vertical-align: middle; text-align: center">29.6</td>
|
| 575 |
+
<td align="center" style="vertical-align: middle; text-align: center">27.0</td>
|
| 576 |
+
<td align="center" style="vertical-align: middle; text-align: center">26.6</td>
|
| 577 |
+
<td align="center" style="vertical-align: middle; text-align: center">20.4</td>
|
| 578 |
+
</tr>
|
| 579 |
+
<tr>
|
| 580 |
+
<td align="center" style="vertical-align: middle; text-align: center">APEX-Agents</td>
|
| 581 |
+
<td align="center" style="vertical-align: middle; text-align: center">41.0</td>
|
| 582 |
+
<td align="center" style="vertical-align: middle; text-align: center">43.3</td>
|
| 583 |
+
<td align="center" style="vertical-align: middle; text-align: center">39.9</td>
|
| 584 |
+
<td align="center" style="vertical-align: middle; text-align: center">39.4</td>
|
| 585 |
+
<td align="center" style="vertical-align: middle; text-align: center">38.5</td>
|
| 586 |
+
<td align="center" style="vertical-align: middle; text-align: center">35.6</td>
|
| 587 |
+
</tr>
|
| 588 |
+
<tr>
|
| 589 |
+
<td align="center" style="vertical-align: middle; text-align: center">OfficeQA Pro</td>
|
| 590 |
+
<td align="center" style="vertical-align: middle; text-align: center">63.3</td>
|
| 591 |
+
<td align="center" style="vertical-align: middle; text-align: center">69.9</td>
|
| 592 |
+
<td align="center" style="vertical-align: middle; text-align: center">63.2</td>
|
| 593 |
+
<td align="center" style="vertical-align: middle; text-align: center">63.9</td>
|
| 594 |
+
<td align="center" style="vertical-align: middle; text-align: center">60.9</td>
|
| 595 |
+
<td align="center" style="vertical-align: middle; text-align: center">41.4</td>
|
| 596 |
+
</tr>
|
| 597 |
+
<tr>
|
| 598 |
+
<td align="center" style="vertical-align: middle; text-align: center">SpreadsheetBench 2</td>
|
| 599 |
+
<td align="center" style="vertical-align: middle; text-align: center">34.8</td>
|
| 600 |
+
<td align="center" style="vertical-align: middle; text-align: center">34.7</td>
|
| 601 |
+
<td align="center" style="vertical-align: middle; text-align: center">32.4</td>
|
| 602 |
+
<td align="center" style="vertical-align: middle; text-align: center">31.6</td>
|
| 603 |
+
<td align="center" style="vertical-align: middle; text-align: center">29.1</td>
|
| 604 |
+
<td align="center" style="vertical-align: middle; text-align: center">28.1</td>
|
| 605 |
+
</tr>
|
| 606 |
+
<tr>
|
| 607 |
+
<td align="center" style="vertical-align: middle; text-align: center">OSWorld-Verified</td>
|
| 608 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.8</td>
|
| 609 |
+
<td align="center" style="vertical-align: middle; text-align: center">85.0</td>
|
| 610 |
+
<td align="center" style="vertical-align: middle; text-align: center">83.0</td>
|
| 611 |
+
<td align="center" style="vertical-align: middle; text-align: center">83.4</td>
|
| 612 |
+
<td align="center" style="vertical-align: middle; text-align: center">79.0</td>
|
| 613 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 614 |
+
</tr>
|
| 615 |
+
<tr>
|
| 616 |
+
<td align="center" style="vertical-align: middle; text-align: center">OSWorld 2.0</td>
|
| 617 |
+
<td align="center" style="vertical-align: middle; text-align: center">58.3</td>
|
| 618 |
+
<td align="center" style="vertical-align: middle; text-align: center">66.1</td>
|
| 619 |
+
<td align="center" style="vertical-align: middle; text-align: center">62.6</td>
|
| 620 |
+
<td align="center" style="vertical-align: middle; text-align: center">55.7</td>
|
| 621 |
+
<td align="center" style="vertical-align: middle; text-align: center">49.5</td>
|
| 622 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 623 |
+
</tr>
|
| 624 |
+
<tr>
|
| 625 |
+
<td align="center" style="vertical-align: middle; text-align: center">SaaS-Bench</td>
|
| 626 |
+
<td align="center" style="vertical-align: middle; text-align: center">60.1</td>
|
| 627 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 628 |
+
<td align="center" style="vertical-align: middle; text-align: center">61.4</td>
|
| 629 |
+
<td align="center" style="vertical-align: middle; text-align: center">56.1</td>
|
| 630 |
+
<td align="center" style="vertical-align: middle; text-align: center">43.8</td>
|
| 631 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 632 |
+
</tr>
|
| 633 |
+
<tr>
|
| 634 |
+
<td align="center" style="vertical-align: middle; text-align: center">τ³-Banking</td>
|
| 635 |
+
<td align="center" style="vertical-align: middle; text-align: center">33.4</td>
|
| 636 |
+
<td align="center" style="vertical-align: middle; text-align: center">26.8</td>
|
| 637 |
+
<td align="center" style="vertical-align: middle; text-align: center">33.0</td>
|
| 638 |
+
<td align="center" style="vertical-align: middle; text-align: center">27.6</td>
|
| 639 |
+
<td align="center" style="vertical-align: middle; text-align: center">31.3</td>
|
| 640 |
+
<td align="center" style="vertical-align: middle; text-align: center">26.8</td>
|
| 641 |
+
</tr>
|
| 642 |
+
<tr>
|
| 643 |
+
<td align="center" style="vertical-align: middle; text-align: center">Harvey Lab-AA</td>
|
| 644 |
+
<td align="center" style="vertical-align: middle; text-align: center">94.6</td>
|
| 645 |
+
<td align="center" style="vertical-align: middle; text-align: center">93.6</td>
|
| 646 |
+
<td align="center" style="vertical-align: middle; text-align: center">87.2</td>
|
| 647 |
+
<td align="center" style="vertical-align: middle; text-align: center">91.1</td>
|
| 648 |
+
<td align="center" style="vertical-align: middle; text-align: center">86.3</td>
|
| 649 |
+
<td align="center" style="vertical-align: middle; text-align: center">91.0</td>
|
| 650 |
+
</tr>
|
| 651 |
+
<tr>
|
| 652 |
+
<td align="center" style="vertical-align: middle; text-align: center">CorpFin v2</td>
|
| 653 |
+
<td align="center" style="vertical-align: middle; text-align: center">71.6</td>
|
| 654 |
+
<td align="center" style="vertical-align: middle; text-align: center">71.8</td>
|
| 655 |
+
<td align="center" style="vertical-align: middle; text-align: center">64.4</td>
|
| 656 |
+
<td align="center" style="vertical-align: middle; text-align: center">66.7</td>
|
| 657 |
+
<td align="center" style="vertical-align: middle; text-align: center">68.4</td>
|
| 658 |
+
<td align="center" style="vertical-align: middle; text-align: center">66.1</td>
|
| 659 |
+
</tr>
|
| 660 |
+
<tr>
|
| 661 |
+
<td align="center" style="vertical-align: middle; text-align: center">Finance Agent v2</td>
|
| 662 |
+
<td align="center" style="vertical-align: middle; text-align: center">54.4</td>
|
| 663 |
+
<td align="center" style="vertical-align: middle; text-align: center">56.3</td>
|
| 664 |
+
<td align="center" style="vertical-align: middle; text-align: center">53.8</td>
|
| 665 |
+
<td align="center" style="vertical-align: middle; text-align: center">53.9</td>
|
| 666 |
+
<td align="center" style="vertical-align: middle; text-align: center">51.8</td>
|
| 667 |
+
<td align="center" style="vertical-align: middle; text-align: center">49.7</td>
|
| 668 |
+
</tr>
|
| 669 |
+
<tr>
|
| 670 |
+
<td align="center" style="vertical-align: middle; text-align: center">Legal Research Bench</td>
|
| 671 |
+
<td align="center" style="vertical-align: middle; text-align: center">44.2</td>
|
| 672 |
+
<td align="center" style="vertical-align: middle; text-align: center">49.5</td>
|
| 673 |
+
<td align="center" style="vertical-align: middle; text-align: center">48.1</td>
|
| 674 |
+
<td align="center" style="vertical-align: middle; text-align: center">43.8</td>
|
| 675 |
+
<td align="center" style="vertical-align: middle; text-align: center">40.4</td>
|
| 676 |
+
<td align="center" style="vertical-align: middle; text-align: center">31.3</td>
|
| 677 |
+
</tr>
|
| 678 |
+
<tr>
|
| 679 |
+
<td align="center" colspan=7 style="text-align: center"><strong>Vision</strong></td>
|
| 680 |
+
</tr>
|
| 681 |
+
<tr>
|
| 682 |
+
<td align="center" style="vertical-align: middle; text-align: center">WorldVQA ForceAnswer</td>
|
| 683 |
+
<td align="center" style="vertical-align: middle; text-align: center">51.0</td>
|
| 684 |
+
<td align="center" style="vertical-align: middle; text-align: center">56.7</td>
|
| 685 |
+
<td align="center" style="vertical-align: middle; text-align: center">41.8</td>
|
| 686 |
+
<td align="center" style="vertical-align: middle; text-align: center">39.1</td>
|
| 687 |
+
<td align="center" style="vertical-align: middle; text-align: center">38.5</td>
|
| 688 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 689 |
+
</tr>
|
| 690 |
+
<tr>
|
| 691 |
+
<td align="center" style="vertical-align: middle; text-align: center">OmniDocBench</td>
|
| 692 |
+
<td align="center" style="vertical-align: middle; text-align: center">91.1</td>
|
| 693 |
+
<td align="center" style="vertical-align: middle; text-align: center">89.8</td>
|
| 694 |
+
<td align="center" style="vertical-align: middle; text-align: center">85.8</td>
|
| 695 |
+
<td align="center" style="vertical-align: middle; text-align: center">87.9</td>
|
| 696 |
+
<td align="center" style="vertical-align: middle; text-align: center">89.4</td>
|
| 697 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 698 |
+
</tr>
|
| 699 |
+
<tr>
|
| 700 |
+
<td align="center" style="vertical-align: middle; text-align: center">PerceptionBench</td>
|
| 701 |
+
<td align="center" style="vertical-align: middle; text-align: center">58.5</td>
|
| 702 |
+
<td align="center" style="vertical-align: middle; text-align: center">57.2</td>
|
| 703 |
+
<td align="center" style="vertical-align: middle; text-align: center">59.7</td>
|
| 704 |
+
<td align="center" style="vertical-align: middle; text-align: center">47.2</td>
|
| 705 |
+
<td align="center" style="vertical-align: middle; text-align: center">55.8</td>
|
| 706 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 707 |
+
</tr>
|
| 708 |
+
<tr>
|
| 709 |
+
<td align="center" style="vertical-align: middle; text-align: center">Video-MME (w. sub)</td>
|
| 710 |
+
<td align="center" style="vertical-align: middle; text-align: center">90.0</td>
|
| 711 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 712 |
+
<td align="center" style="vertical-align: middle; text-align: center">89.5</td>
|
| 713 |
+
<td align="center" style="vertical-align: middle; text-align: center">86.0</td>
|
| 714 |
+
<td align="center" style="vertical-align: middle; text-align: center">89.3</td>
|
| 715 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 716 |
+
</tr>
|
| 717 |
+
<tr>
|
| 718 |
+
<td align="center" style="vertical-align: middle; text-align: center">MMVU</td>
|
| 719 |
+
<td align="center" style="vertical-align: middle; text-align: center">82.1</td>
|
| 720 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 721 |
+
<td align="center" style="vertical-align: middle; text-align: center">81.2</td>
|
| 722 |
+
<td align="center" style="vertical-align: middle; text-align: center">79.2</td>
|
| 723 |
+
<td align="center" style="vertical-align: middle; text-align: center">81.7</td>
|
| 724 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 725 |
+
</tr>
|
| 726 |
+
<tr>
|
| 727 |
+
<td align="center" style="vertical-align: middle; text-align: center">BabyVision w/ python</td>
|
| 728 |
+
<td align="center" style="vertical-align: middle; text-align: center">85.7</td>
|
| 729 |
+
<td align="center" style="vertical-align: middle; text-align: center">90.5</td>
|
| 730 |
+
<td align="center" style="vertical-align: middle; text-align: center">88.9</td>
|
| 731 |
+
<td align="center" style="vertical-align: middle; text-align: center">81.2</td>
|
| 732 |
+
<td align="center" style="vertical-align: middle; text-align: center">83.6</td>
|
| 733 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 734 |
+
</tr>
|
| 735 |
+
<tr>
|
| 736 |
+
<td align="center" style="vertical-align: middle; text-align: center">MMMU-Pro</td>
|
| 737 |
+
<td align="center" style="vertical-align: middle; text-align: center">81.6 / 83.4</td>
|
| 738 |
+
<td align="center" style="vertical-align: middle; text-align: center">81.2 / 86.5</td>
|
| 739 |
+
<td align="center" style="vertical-align: middle; text-align: center">83.0 / 84.6</td>
|
| 740 |
+
<td align="center" style="vertical-align: middle; text-align: center">78.9 / 82.7</td>
|
| 741 |
+
<td align="center" style="vertical-align: middle; text-align: center">81.2 / 83.2</td>
|
| 742 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 743 |
+
</tr>
|
| 744 |
+
<tr>
|
| 745 |
+
<td align="center" style="vertical-align: middle; text-align: center">CharXiv (RQ)</td>
|
| 746 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.8 / 91.3</td>
|
| 747 |
+
<td align="center" style="vertical-align: middle; text-align: center">88.9 / 93.5</td>
|
| 748 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.6 / 89.1</td>
|
| 749 |
+
<td align="center" style="vertical-align: middle; text-align: center">80.5 / 89.9</td>
|
| 750 |
+
<td align="center" style="vertical-align: middle; text-align: center">84.1 / 89.0</td>
|
| 751 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 752 |
+
</tr>
|
| 753 |
+
<tr>
|
| 754 |
+
<td align="center" style="vertical-align: middle; text-align: center">MathVision</td>
|
| 755 |
+
<td align="center" style="vertical-align: middle; text-align: center">94.3 / 97.8</td>
|
| 756 |
+
<td align="center" style="vertical-align: middle; text-align: center">94.8 / 98.6</td>
|
| 757 |
+
<td align="center" style="vertical-align: middle; text-align: center">95.8 / 97.8</td>
|
| 758 |
+
<td align="center" style="vertical-align: middle; text-align: center">86.7 / 97.1</td>
|
| 759 |
+
<td align="center" style="vertical-align: middle; text-align: center">92.2 / 96.8</td>
|
| 760 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 761 |
+
</tr>
|
| 762 |
+
<tr>
|
| 763 |
+
<td align="center" style="vertical-align: middle; text-align: center">ZeroBench (pass@5)</td>
|
| 764 |
+
<td align="center" style="vertical-align: middle; text-align: center">23.0 / 41.0</td>
|
| 765 |
+
<td align="center" style="vertical-align: middle; text-align: center">23.0 / 46.0</td>
|
| 766 |
+
<td align="center" style="vertical-align: middle; text-align: center">17.0 / 35.0</td>
|
| 767 |
+
<td align="center" style="vertical-align: middle; text-align: center">17.0 / 34.0</td>
|
| 768 |
+
<td align="center" style="vertical-align: middle; text-align: center">22.0 / 41.0</td>
|
| 769 |
+
<td align="center" style="vertical-align: middle; text-align: center">—</td>
|
| 770 |
+
</tr>
|
| 771 |
+
</tbody>
|
| 772 |
+
</table>
|
| 773 |
+
</div>
|
| 774 |
+
|
| 775 |
+
<details>
|
| 776 |
+
<summary><b>Footnotes</b></summary>
|
| 777 |
+
|
| 778 |
+
All Kimi K3 results are obtained with reasoning effort set to 'max' and temperature = 1.0. For single-step tasks, such as GPQA Diamond, HLE-Full, and vision benchmarks without tools, we set top-p = 0.95; for agentic tasks, we set top-p = 1.0. For HLE-Full, MMMU-Pro, CharXiv (RQ), MathVision, and ZeroBench, each cell reports the scores without and with tool augmentation (general tools for HLE-Full, Python for the vision benchmarks), in that order.
|
| 779 |
+
|
| 780 |
+
1. **Reasoning & knowledge benchmarks**
|
| 781 |
+
- **CritPt and AA-LCR.** Scores are cited from [Artificial Analysis](https://artificialanalysis.ai/) as of July 23, 2026.
|
| 782 |
+
2. **Coding benchmarks**
|
| 783 |
+
- **DeepSWE.** Kimi K3 is evaluated with the Kimi Code harness. The GLM-5.2 score is taken from the [GLM-5.2 release blog](https://z.ai/blog/glm-5.2); all remaining scores are from the official [DeepSWE leaderboard](https://deepswe.datacurve.ai/), under which Kimi K3 attains 67.3 with the mini-SWE-agent harness. We report the DeepSWE v1.1 tasks.
|
| 784 |
+
- **Terminal-Bench 2.1.** Kimi K3 is evaluated with the Kimi Code harness. For all other models, we report the best score across harnesses: GLM-5.2 with Claude Code ([GLM-5.2 release blog](https://z.ai/blog/glm-5.2)); Claude Opus 4.8 and Claude Fable 5 with Terminus 2 ([Artificial Analysis](https://artificialanalysis.ai/evaluations/terminalbench-v2-1)); GPT-5.5 and GPT-5.6 Sol with Codex ([OpenAI](https://openai.com/index/previewing-gpt-5-6-sol/)).
|
| 785 |
+
- **ProgramBench.** Kimi K3 is evaluated with the Kimi Code harness. The GLM-5.2 score is from the [GLM-5.2 release blog](https://z.ai/blog/glm-5.2); all other scores are from [Vals AI](https://www.vals.ai/benchmarks/programbench).
|
| 786 |
+
- **SWE-Marathon.** Kimi K3, Claude Opus 4.8, and Claude Fable 5 are evaluated with the Claude Code harness; GPT-5.6 Sol is evaluated with the Codex harness. The GLM-5.2 score is from the [GLM-5.2 release blog](https://z.ai/blog/glm-5.2). Our evaluation is based on an H20-calibrated branch of the [official tasks](https://www.swe-marathon.org/) as of July 9, 2026, prior to the final v1.1 release: the Docker images, performance gates, and reference oracles for the GPU tasks have been recalibrated for H20, while the correctness and anti-cheat validators remain unchanged. Additionally, Claude Fable 5 hit fallbacks on 35% of the tasks in our evaluation, which may have negatively impacted its measured performance.
|
| 787 |
+
- **FrontierSWE.** Kimi K3 is evaluated with the Kimi Code harness and GPT-5.6 Sol with the Codex harness; all other results are from [FrontierSWE](https://www.frontierswe.com/). Dominance scores are recomputed from the raw scores using the official evaluation script and are current as of July 16, 2026.
|
| 788 |
+
- **PostTrainBench.** Scores for GLM-5.2, GPT-5.5, and Claude Opus 4.8 are adopted from the official [PostTrainBench](https://posttrainbench.com/) results. Kimi K3, Claude Fable 5, and GPT-5.6 Sol are evaluated with the official Harbor implementation at maximum reasoning effort, averaged over three runs on H20 GPUs (instead of H100 in the official setting) — Kimi K3 and Claude Fable 5 with the Claude Code harness, and GPT-5.6 Sol with the Codex harness.
|
| 789 |
+
- **MLS-Bench-Lite.** Kimi K3 is evaluated with the Kimi Code harness; GLM-5.2 and the Claude models with the Claude Code harness; GPT-5.5 and GPT-5.6 Sol with the Codex harness.
|
| 790 |
+
- **SciCode.** Scores are cited from [Artificial Analysis](https://artificialanalysis.ai/) as of July 23, 2026.
|
| 791 |
+
- **Kimi Code Bench 2.0 (in-house).** Kimi K3 is evaluated with the Kimi Code harness (it attains 73.7 with the Claude Code harness); GLM-5.2, Claude Opus 4.8, and Claude Fable 5 with the Claude Code harness; GPT-5.5 and GPT-5.6 Sol with the Codex harness. All models are evaluated at maximum reasoning effort, except GPT-5.5, which uses the "xhigh" setting. As the benchmark includes cybersecurity and safety-related tasks, we also disclose the fraction of refused or fallback tasks: Claude Fable 5 hit 13 fallbacks and 1 refusal out of 80 tasks; 10 refusals out of 80 tasks entered GPT-5.6 Sol's cyber guard; GPT-5.5 had 3 refusals out of 80 tasks.
|
| 792 |
+
3. **Agentic benchmarks**
|
| 793 |
+
- **OfficeQA Pro.** Each test case provides the agent with the entire PDF corpus, with all PDFs rendered as images and no machine-readable text available.
|
| 794 |
+
- **OfficeQA Pro and SpreadsheetBench 2.** Kimi K3, GLM-5.2, Claude Opus 4.8, and Claude Fable 5 are evaluated with the Claude Code harness; GPT-5.5 and GPT-5.6 Sol are evaluated with the Codex harness.
|
| 795 |
+
- **MCP-Atlas.** All models are evaluated on the 500-task public subset with a 100-turn limit, using Gemini 3.1 Pro as the judge.
|
| 796 |
+
- **AutomationBench.** All models are evaluated on the 600-task public subset, following the official GitHub setup in all other respects.
|
| 797 |
+
- **BrowseComp.** We adopt a context-compaction strategy triggered at 300K tokens. When evaluated with the full 1M-token context window and no context management, Kimi K3 achieves a score of 90.4. The results of Claude Fable 5, Claude Opus 4.8, GPT-5.6 Sol, and GPT-5.5 are cited from [Anthropic](https://www.anthropic.com/news/claude-fable-5-mythos-5) and [OpenAI](https://openai.com/index/gpt-5-6/).
|
| 798 |
+
- **GDPval-AA v2, AA-Briefcase, τ³-Banking, Harvey Lab-AA, and APEX-Agents.** Scores are cited from [Artificial Analysis](https://artificialanalysis.ai/) and the [APEX-Agents leaderboard](https://www.mercor.com/apex/apex-agents-leaderboard/) as of July 23, 2026. For Harvey Lab-AA, we report the criterion pass rate.
|
| 799 |
+
- **CorpFin v2, Finance Agent v2, and Legal Research Bench.** Scores are cited from [Vals AI](https://www.vals.ai/).
|
| 800 |
+
- **Agents' Last Exam.** Scores are cited from the [official leaderboard](https://agents-last-exam.org/leaderboard) as of July 23, 2026; we report the leaderboard's primary pass-rate metric. On the leaderboard, each model is paired with a specific harness: Kimi K3 with Kimi Code; GPT-5.6 Sol and GPT-5.5 with Codex; Claude Fable 5, Claude Opus 4.8, and GLM-5.2 with Claude Code. <sup>†</sup> The Claude Fable 5 entry runs at xhigh effort with 40% of tasks annotated as downgraded.
|
| 801 |
+
4. **Multimodal benchmarks**
|
| 802 |
+
- Except for ZeroBench, which follows the official setting and is run five times, all multimodal scores are averaged over three runs. MMMU-Pro is evaluated following the official protocol, preserving the original input order and prepending images to the text input.
|
| 803 |
+
- **PerceptionBench** is an in-house benchmark that focuses on atomic visual perception capabilities.
|
| 804 |
+
|
| 805 |
+
</details>
|
| 806 |
+
|
| 807 |
+
## 4. Native MXFP4 Quantization
|
| 808 |
+
|
| 809 |
+
Kimi K3 applies quantization-aware training from the SFT stage onward, using MXFP4 weights with MXFP8 activations for broad hardware compatibility.
|
| 810 |
+
|
| 811 |
+
## 5. Deployment
|
| 812 |
+
|
| 813 |
+
> [!Note]
|
| 814 |
+
> You can access Kimi K3's API on https://platform.kimi.ai by selecting `kimi-k3`, and we provide OpenAI/Anthropic-compatible API for you. Currently, Kimi K3 is recommended to run on the following inference engines:
|
| 815 |
+
|
| 816 |
+
- [vLLM](https://github.com/vllm-project/vllm) — see [recipes](https://recipes.vllm.ai/moonshotai/Kimi-K3)
|
| 817 |
+
- [SGLang](https://github.com/sgl-project/sglang) — see [cookbook](https://docs.sglang.io/cookbook/autoregressive/Moonshotai/Kimi-K3)
|
| 818 |
+
- [TokenSpeed](https://github.com/lightseekorg/tokenspeed) — see [recipes](https://lightseek.org/tokenspeed/recipes/models#kimi-k3)
|
| 819 |
+
|
| 820 |
+
---
|
| 821 |
+
## 6. Model Usage
|
| 822 |
+
|
| 823 |
+
Kimi K3 always has thinking enabled, and will return `reasoning_content`. Thinking effort is configured with the top-level `reasoning_effort` request field, which supports `"low"`, `"high"`, and `"max"` (default `"max"`).
|
| 824 |
+
|
| 825 |
+
Kimi K3 was trained in the preserved thinking history mode. For multi-turn conversations and tool calls, Kimi K3 requires the complete assistant message returned by the API to be passed back to `messages` as-is — including `reasoning_content` and `tool_calls`, not just `content`:
|
| 826 |
+
|
| 827 |
+
```python
|
| 828 |
+
import openai
|
| 829 |
+
|
| 830 |
+
def chat_with_preserved_thinking(client: openai.OpenAI, model_name: str):
|
| 831 |
+
messages = [
|
| 832 |
+
{
|
| 833 |
+
"role": "user",
|
| 834 |
+
"content": "Tell me three random numbers."
|
| 835 |
+
},
|
| 836 |
+
{
|
| 837 |
+
"role": "assistant",
|
| 838 |
+
"reasoning_content": "I'll start by listing five numbers: 473, 921, 235, 215, 222, and I'll tell you the first three.",
|
| 839 |
+
"content": "473, 921, 235"
|
| 840 |
+
},
|
| 841 |
+
{
|
| 842 |
+
"role": "user",
|
| 843 |
+
"content": "What are the other two numbers you have in mind?"
|
| 844 |
+
}
|
| 845 |
+
]
|
| 846 |
+
|
| 847 |
+
response = client.chat.completions.create(
|
| 848 |
+
model=model_name,
|
| 849 |
+
messages=messages,
|
| 850 |
+
stream=False,
|
| 851 |
+
max_tokens=4096,
|
| 852 |
+
reasoning_effort="max",
|
| 853 |
+
)
|
| 854 |
+
# the assistant should mention 215 and 222 that appear in the prior reasoning content
|
| 855 |
+
print(f"response: {response.choices[0].message.reasoning}")
|
| 856 |
+
return response.choices[0].message.content
|
| 857 |
+
```
|
| 858 |
+
|
| 859 |
+
For full guides and examples (vision input, structured output, partial mode, tool choice, dynamic tool loading, context caching), see the [Kimi K3 Quickstart](https://platform.kimi.ai/docs/guide/kimi-k3-quickstart) and [Thinking Effort](https://platform.kimi.ai/docs/guide/use-thinking-effort).
|
| 860 |
+
|
| 861 |
+
### Coding Agent Framework
|
| 862 |
+
|
| 863 |
+
Kimi K3 works best with [Kimi Code CLI](https://www.kimi.com/code) as its agent framework. We warmly invite you to give it a try — run Kimi Code in your terminal and select Kimi K3 using the `/model` command. We hope you enjoy building with Kimi K3, and we would love to hear your feedback!
|
| 864 |
+
|
| 865 |
+
|
| 866 |
+
---
|
| 867 |
+
|
| 868 |
+
## 7. License
|
| 869 |
+
|
| 870 |
+
Both the code repository and the model weights are released under the [Kimi K3 License](https://huggingface.co/moonshotai/Kimi-K3/blob/main/LICENSE).
|
| 871 |
+
|
| 872 |
+
---
|
| 873 |
+
|
| 874 |
+
## 8. Contact Us
|
| 875 |
+
|
| 876 |
+
If you have any questions, please reach out at [support@moonshot.ai](mailto:support@moonshot.ai).
|
assets/.gitkeep
ADDED
|
File without changes
|
assets/kimi-logo.png
ADDED
|
config.json
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name_or_path": "tclf90/Kimi-K3-Cubic-2.5Bit",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"KimiK3ForConditionalGeneration"
|
| 5 |
+
],
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "configuration_kimi_k3.KimiK3Config",
|
| 8 |
+
"AutoModel": "modeling_kimi_k3.KimiK3ForConditionalGeneration",
|
| 9 |
+
"AutoModelForCausalLM": "modeling_kimi_k3.KimiK3ForConditionalGeneration"
|
| 10 |
+
},
|
| 11 |
+
"bos_token_id": 163584,
|
| 12 |
+
"dtype": "bfloat16",
|
| 13 |
+
"eos_token_id": 163586,
|
| 14 |
+
"ignore_index": -100,
|
| 15 |
+
"image_placeholder": "<|kimi_image_placeholder|>",
|
| 16 |
+
"media_placeholder_token_id": 163605,
|
| 17 |
+
"model_type": "kimi_k3",
|
| 18 |
+
"pad_token_id": 163839,
|
| 19 |
+
"text_config": {
|
| 20 |
+
"_name_or_path": "",
|
| 21 |
+
"activation_situ_beta": 4.0,
|
| 22 |
+
"activation_situ_linear_beta": 25.0,
|
| 23 |
+
"add_cross_attention": false,
|
| 24 |
+
"architectures": [
|
| 25 |
+
"KimiLinearForCausalLM"
|
| 26 |
+
],
|
| 27 |
+
"attn_res_block_size": 12,
|
| 28 |
+
"auto_map": {
|
| 29 |
+
"AutoConfig": "configuration_kimi_k3.KimiLinearConfig",
|
| 30 |
+
"AutoModel": "modeling_kimi_linear.KimiLinearModel",
|
| 31 |
+
"AutoModelForCausalLM": "modeling_kimi_linear.KimiLinearForCausalLM"
|
| 32 |
+
},
|
| 33 |
+
"bad_words_ids": null,
|
| 34 |
+
"begin_suppress_tokens": null,
|
| 35 |
+
"bos_token_id": 163584,
|
| 36 |
+
"chunk_size_feed_forward": 0,
|
| 37 |
+
"cross_attention_hidden_size": null,
|
| 38 |
+
"decoder_start_token_id": null,
|
| 39 |
+
"diversity_penalty": 0.0,
|
| 40 |
+
"do_sample": false,
|
| 41 |
+
"dtype": "bfloat16",
|
| 42 |
+
"early_stopping": false,
|
| 43 |
+
"encoder_no_repeat_ngram_size": 0,
|
| 44 |
+
"eos_token_id": 163586,
|
| 45 |
+
"exponential_decay_length_penalty": null,
|
| 46 |
+
"finetuning_task": null,
|
| 47 |
+
"first_k_dense_replace": 1,
|
| 48 |
+
"forced_bos_token_id": null,
|
| 49 |
+
"forced_eos_token_id": null,
|
| 50 |
+
"hidden_act": "situ",
|
| 51 |
+
"hidden_size": 7168,
|
| 52 |
+
"id2label": {
|
| 53 |
+
"0": "LABEL_0",
|
| 54 |
+
"1": "LABEL_1"
|
| 55 |
+
},
|
| 56 |
+
"initializer_range": 0.02,
|
| 57 |
+
"intermediate_size": 33792,
|
| 58 |
+
"is_decoder": false,
|
| 59 |
+
"is_encoder_decoder": false,
|
| 60 |
+
"kv_lora_rank": 512,
|
| 61 |
+
"label2id": {
|
| 62 |
+
"LABEL_0": 0,
|
| 63 |
+
"LABEL_1": 1
|
| 64 |
+
},
|
| 65 |
+
"latent_moe_use_norm": true,
|
| 66 |
+
"length_penalty": 1.0,
|
| 67 |
+
"linear_attn_config": {
|
| 68 |
+
"full_attn_layers": [
|
| 69 |
+
4,
|
| 70 |
+
8,
|
| 71 |
+
12,
|
| 72 |
+
16,
|
| 73 |
+
20,
|
| 74 |
+
24,
|
| 75 |
+
28,
|
| 76 |
+
32,
|
| 77 |
+
36,
|
| 78 |
+
40,
|
| 79 |
+
44,
|
| 80 |
+
48,
|
| 81 |
+
52,
|
| 82 |
+
56,
|
| 83 |
+
60,
|
| 84 |
+
64,
|
| 85 |
+
68,
|
| 86 |
+
72,
|
| 87 |
+
76,
|
| 88 |
+
80,
|
| 89 |
+
84,
|
| 90 |
+
88,
|
| 91 |
+
92,
|
| 92 |
+
93
|
| 93 |
+
],
|
| 94 |
+
"gate_lower_bound": -5.0,
|
| 95 |
+
"head_dim": 128,
|
| 96 |
+
"kda_layers": [
|
| 97 |
+
1,
|
| 98 |
+
2,
|
| 99 |
+
3,
|
| 100 |
+
5,
|
| 101 |
+
6,
|
| 102 |
+
7,
|
| 103 |
+
9,
|
| 104 |
+
10,
|
| 105 |
+
11,
|
| 106 |
+
13,
|
| 107 |
+
14,
|
| 108 |
+
15,
|
| 109 |
+
17,
|
| 110 |
+
18,
|
| 111 |
+
19,
|
| 112 |
+
21,
|
| 113 |
+
22,
|
| 114 |
+
23,
|
| 115 |
+
25,
|
| 116 |
+
26,
|
| 117 |
+
27,
|
| 118 |
+
29,
|
| 119 |
+
30,
|
| 120 |
+
31,
|
| 121 |
+
33,
|
| 122 |
+
34,
|
| 123 |
+
35,
|
| 124 |
+
37,
|
| 125 |
+
38,
|
| 126 |
+
39,
|
| 127 |
+
41,
|
| 128 |
+
42,
|
| 129 |
+
43,
|
| 130 |
+
45,
|
| 131 |
+
46,
|
| 132 |
+
47,
|
| 133 |
+
49,
|
| 134 |
+
50,
|
| 135 |
+
51,
|
| 136 |
+
53,
|
| 137 |
+
54,
|
| 138 |
+
55,
|
| 139 |
+
57,
|
| 140 |
+
58,
|
| 141 |
+
59,
|
| 142 |
+
61,
|
| 143 |
+
62,
|
| 144 |
+
63,
|
| 145 |
+
65,
|
| 146 |
+
66,
|
| 147 |
+
67,
|
| 148 |
+
69,
|
| 149 |
+
70,
|
| 150 |
+
71,
|
| 151 |
+
73,
|
| 152 |
+
74,
|
| 153 |
+
75,
|
| 154 |
+
77,
|
| 155 |
+
78,
|
| 156 |
+
79,
|
| 157 |
+
81,
|
| 158 |
+
82,
|
| 159 |
+
83,
|
| 160 |
+
85,
|
| 161 |
+
86,
|
| 162 |
+
87,
|
| 163 |
+
89,
|
| 164 |
+
90,
|
| 165 |
+
91
|
| 166 |
+
],
|
| 167 |
+
"num_heads": 96,
|
| 168 |
+
"short_conv_kernel_size": 4,
|
| 169 |
+
"use_full_rank_gate": true
|
| 170 |
+
},
|
| 171 |
+
"max_length": 20,
|
| 172 |
+
"max_position_embeddings": 1048576,
|
| 173 |
+
"min_length": 0,
|
| 174 |
+
"mla_use_nope": true,
|
| 175 |
+
"mla_use_output_gate": true,
|
| 176 |
+
"model_type": "kimi_linear",
|
| 177 |
+
"moe_intermediate_size": 3072,
|
| 178 |
+
"moe_layer_freq": 1,
|
| 179 |
+
"moe_renormalize": true,
|
| 180 |
+
"moe_router_activation_func": "sigmoid",
|
| 181 |
+
"no_repeat_ngram_size": 0,
|
| 182 |
+
"num_attention_heads": 96,
|
| 183 |
+
"num_beam_groups": 1,
|
| 184 |
+
"num_beams": 1,
|
| 185 |
+
"num_expert_group": 1,
|
| 186 |
+
"num_experts": 896,
|
| 187 |
+
"num_experts_per_token": 16,
|
| 188 |
+
"num_hidden_layers": 93,
|
| 189 |
+
"num_key_value_heads": 96,
|
| 190 |
+
"num_nextn_predict_layers": 0,
|
| 191 |
+
"num_return_sequences": 1,
|
| 192 |
+
"num_shared_experts": 2,
|
| 193 |
+
"output_attentions": false,
|
| 194 |
+
"output_hidden_states": false,
|
| 195 |
+
"output_scores": false,
|
| 196 |
+
"pad_token_id": 163839,
|
| 197 |
+
"prefix": null,
|
| 198 |
+
"problem_type": null,
|
| 199 |
+
"pruned_heads": {},
|
| 200 |
+
"q_lora_rank": 1536,
|
| 201 |
+
"qk_nope_head_dim": 128,
|
| 202 |
+
"qk_rope_head_dim": 64,
|
| 203 |
+
"quantization_config": {
|
| 204 |
+
"quant_method": "cubic",
|
| 205 |
+
"format": "cubic-pack-quantized",
|
| 206 |
+
"quantization_status": "compressed",
|
| 207 |
+
"config_groups": {
|
| 208 |
+
"moe_layers_1_3": {
|
| 209 |
+
"targets": [
|
| 210 |
+
"re:.*\\.layers\\.(?:1|2|3)\\.block_sparse_moe\\.experts"
|
| 211 |
+
],
|
| 212 |
+
"input_activations": null,
|
| 213 |
+
"output_activations": null,
|
| 214 |
+
"weights": {
|
| 215 |
+
"num_bits": 3,
|
| 216 |
+
"group_size": 256,
|
| 217 |
+
"strategy": "group",
|
| 218 |
+
"symmetric": true,
|
| 219 |
+
"dynamic": false,
|
| 220 |
+
"scale_dtype": "torch.float32",
|
| 221 |
+
"param_dtype": "torch.float16",
|
| 222 |
+
"reserved_code": "zero",
|
| 223 |
+
"packing": "little-endian-bitstream"
|
| 224 |
+
}
|
| 225 |
+
},
|
| 226 |
+
"moe_layers_4_32": {
|
| 227 |
+
"targets": [
|
| 228 |
+
"re:.*\\.layers\\.(?:4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)\\.block_sparse_moe\\.experts"
|
| 229 |
+
],
|
| 230 |
+
"input_activations": null,
|
| 231 |
+
"output_activations": null,
|
| 232 |
+
"weights": {
|
| 233 |
+
"num_bits": 3,
|
| 234 |
+
"group_size": 512,
|
| 235 |
+
"strategy": "group",
|
| 236 |
+
"symmetric": true,
|
| 237 |
+
"dynamic": false,
|
| 238 |
+
"scale_dtype": "torch.float32",
|
| 239 |
+
"param_dtype": "torch.float16",
|
| 240 |
+
"reserved_code": "zero",
|
| 241 |
+
"packing": "little-endian-bitstream"
|
| 242 |
+
}
|
| 243 |
+
},
|
| 244 |
+
"moe_layers_33_91": {
|
| 245 |
+
"targets": [
|
| 246 |
+
"re:.*\\.layers\\.(?:33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91)\\.block_sparse_moe\\.experts"
|
| 247 |
+
],
|
| 248 |
+
"input_activations": null,
|
| 249 |
+
"output_activations": null,
|
| 250 |
+
"weights": {
|
| 251 |
+
"num_bits": 2,
|
| 252 |
+
"group_size": 512,
|
| 253 |
+
"strategy": "group",
|
| 254 |
+
"symmetric": true,
|
| 255 |
+
"dynamic": false,
|
| 256 |
+
"scale_dtype": "torch.float32",
|
| 257 |
+
"param_dtype": "torch.float16",
|
| 258 |
+
"reserved_code": "zero",
|
| 259 |
+
"packing": "little-endian-bitstream"
|
| 260 |
+
}
|
| 261 |
+
},
|
| 262 |
+
"moe_layers_92_92": {
|
| 263 |
+
"targets": [
|
| 264 |
+
"re:.*\\.layers\\.(?:92)\\.block_sparse_moe\\.experts"
|
| 265 |
+
],
|
| 266 |
+
"input_activations": null,
|
| 267 |
+
"output_activations": null,
|
| 268 |
+
"weights": {
|
| 269 |
+
"num_bits": 4,
|
| 270 |
+
"group_size": 512,
|
| 271 |
+
"strategy": "group",
|
| 272 |
+
"symmetric": true,
|
| 273 |
+
"dynamic": false,
|
| 274 |
+
"scale_dtype": "torch.float32",
|
| 275 |
+
"param_dtype": "torch.float16",
|
| 276 |
+
"reserved_code": "zero",
|
| 277 |
+
"packing": "little-endian-bitstream"
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
},
|
| 281 |
+
"ignore": [
|
| 282 |
+
"re:.*self_attn.*",
|
| 283 |
+
"re:.*shared_experts.*",
|
| 284 |
+
"re:.*mlp\\.(gate|up|gate_up|down)_proj.*",
|
| 285 |
+
"re:.*lm_head.*",
|
| 286 |
+
"re:.*vision_tower.*",
|
| 287 |
+
"re:.*mm_projector.*"
|
| 288 |
+
],
|
| 289 |
+
"runtime_weight_storage": "native_packed_bitstream",
|
| 290 |
+
"layer_bit_schedule": [
|
| 291 |
+
{
|
| 292 |
+
"start_layer": 1,
|
| 293 |
+
"end_layer": 3,
|
| 294 |
+
"num_bits": 3,
|
| 295 |
+
"group_size": 256
|
| 296 |
+
},
|
| 297 |
+
{
|
| 298 |
+
"start_layer": 4,
|
| 299 |
+
"end_layer": 32,
|
| 300 |
+
"num_bits": 3,
|
| 301 |
+
"group_size": 512
|
| 302 |
+
},
|
| 303 |
+
{
|
| 304 |
+
"start_layer": 33,
|
| 305 |
+
"end_layer": 91,
|
| 306 |
+
"num_bits": 2,
|
| 307 |
+
"group_size": 512
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"start_layer": 92,
|
| 311 |
+
"end_layer": 92,
|
| 312 |
+
"num_bits": 4,
|
| 313 |
+
"group_size": 512
|
| 314 |
+
}
|
| 315 |
+
],
|
| 316 |
+
"layer_group_size_overrides": {
|
| 317 |
+
"1": 256,
|
| 318 |
+
"2": 256,
|
| 319 |
+
"3": 256,
|
| 320 |
+
"4": 512,
|
| 321 |
+
"5": 512,
|
| 322 |
+
"6": 512,
|
| 323 |
+
"7": 512,
|
| 324 |
+
"8": 512,
|
| 325 |
+
"9": 512,
|
| 326 |
+
"10": 512,
|
| 327 |
+
"11": 512,
|
| 328 |
+
"12": 512,
|
| 329 |
+
"13": 512,
|
| 330 |
+
"14": 512,
|
| 331 |
+
"15": 512,
|
| 332 |
+
"16": 512,
|
| 333 |
+
"17": 512,
|
| 334 |
+
"18": 512,
|
| 335 |
+
"19": 512,
|
| 336 |
+
"20": 512,
|
| 337 |
+
"21": 512,
|
| 338 |
+
"22": 512,
|
| 339 |
+
"23": 512,
|
| 340 |
+
"24": 512,
|
| 341 |
+
"25": 512,
|
| 342 |
+
"26": 512,
|
| 343 |
+
"27": 512,
|
| 344 |
+
"28": 512,
|
| 345 |
+
"29": 512,
|
| 346 |
+
"30": 512,
|
| 347 |
+
"31": 512,
|
| 348 |
+
"32": 512,
|
| 349 |
+
"33": 512,
|
| 350 |
+
"34": 512,
|
| 351 |
+
"35": 512,
|
| 352 |
+
"36": 512,
|
| 353 |
+
"37": 512,
|
| 354 |
+
"38": 512,
|
| 355 |
+
"39": 512,
|
| 356 |
+
"40": 512,
|
| 357 |
+
"41": 512,
|
| 358 |
+
"42": 512,
|
| 359 |
+
"43": 512,
|
| 360 |
+
"44": 512,
|
| 361 |
+
"45": 512,
|
| 362 |
+
"46": 512,
|
| 363 |
+
"47": 512,
|
| 364 |
+
"48": 512,
|
| 365 |
+
"49": 512,
|
| 366 |
+
"50": 512,
|
| 367 |
+
"51": 512,
|
| 368 |
+
"52": 512,
|
| 369 |
+
"53": 512,
|
| 370 |
+
"54": 512,
|
| 371 |
+
"55": 512,
|
| 372 |
+
"56": 512,
|
| 373 |
+
"57": 512,
|
| 374 |
+
"58": 512,
|
| 375 |
+
"59": 512,
|
| 376 |
+
"60": 512,
|
| 377 |
+
"61": 512,
|
| 378 |
+
"62": 512,
|
| 379 |
+
"63": 512,
|
| 380 |
+
"64": 512,
|
| 381 |
+
"65": 512,
|
| 382 |
+
"66": 512,
|
| 383 |
+
"67": 512,
|
| 384 |
+
"68": 512,
|
| 385 |
+
"69": 512,
|
| 386 |
+
"70": 512,
|
| 387 |
+
"71": 512,
|
| 388 |
+
"72": 512,
|
| 389 |
+
"73": 512,
|
| 390 |
+
"74": 512,
|
| 391 |
+
"75": 512,
|
| 392 |
+
"76": 512,
|
| 393 |
+
"77": 512,
|
| 394 |
+
"78": 512,
|
| 395 |
+
"79": 512,
|
| 396 |
+
"80": 512,
|
| 397 |
+
"81": 512,
|
| 398 |
+
"82": 512,
|
| 399 |
+
"83": 512,
|
| 400 |
+
"84": 512,
|
| 401 |
+
"85": 512,
|
| 402 |
+
"86": 512,
|
| 403 |
+
"87": 512,
|
| 404 |
+
"88": 512,
|
| 405 |
+
"89": 512,
|
| 406 |
+
"90": 512,
|
| 407 |
+
"91": 512,
|
| 408 |
+
"92": 512
|
| 409 |
+
},
|
| 410 |
+
"tensor_bit_overrides": [],
|
| 411 |
+
"expert_payload_bits": 2.369565217391304,
|
| 412 |
+
"expert_effective_bits": 2.498641304347826,
|
| 413 |
+
"converted_tensor_effective_bits": 2.498641304347826
|
| 414 |
+
},
|
| 415 |
+
"remove_invalid_values": false,
|
| 416 |
+
"repetition_penalty": 1.0,
|
| 417 |
+
"return_dict": true,
|
| 418 |
+
"return_dict_in_generate": false,
|
| 419 |
+
"rms_norm_eps": 1e-05,
|
| 420 |
+
"routed_expert_hidden_size": 3584,
|
| 421 |
+
"routed_scaling_factor": 1.0,
|
| 422 |
+
"sep_token_id": null,
|
| 423 |
+
"suppress_tokens": null,
|
| 424 |
+
"task_specific_params": null,
|
| 425 |
+
"temperature": 1.0,
|
| 426 |
+
"tf_legacy_loss": false,
|
| 427 |
+
"tie_encoder_decoder": false,
|
| 428 |
+
"tie_word_embeddings": false,
|
| 429 |
+
"tokenizer_class": null,
|
| 430 |
+
"top_k": 50,
|
| 431 |
+
"top_p": 1.0,
|
| 432 |
+
"topk_group": 1,
|
| 433 |
+
"topk_method": "noaux_tc",
|
| 434 |
+
"torchscript": false,
|
| 435 |
+
"transformers_version": "4.56.2",
|
| 436 |
+
"typical_p": 1.0,
|
| 437 |
+
"use_bfloat16": false,
|
| 438 |
+
"use_cache": true,
|
| 439 |
+
"use_grouped_topk": true,
|
| 440 |
+
"v_head_dim": 128,
|
| 441 |
+
"vocab_size": 163840
|
| 442 |
+
},
|
| 443 |
+
"tie_word_embeddings": false,
|
| 444 |
+
"vision_config": {
|
| 445 |
+
"_attn_implementation": "flash_attention_2",
|
| 446 |
+
"activation_func": "gelu_pytorch_tanh",
|
| 447 |
+
"attn_bias": false,
|
| 448 |
+
"init_pos_emb_height": 64,
|
| 449 |
+
"init_pos_emb_time": 4,
|
| 450 |
+
"init_pos_emb_width": 64,
|
| 451 |
+
"linear_bias": false,
|
| 452 |
+
"merge_kernel_size": [
|
| 453 |
+
2,
|
| 454 |
+
2
|
| 455 |
+
],
|
| 456 |
+
"merge_type": "sd2_tpool",
|
| 457 |
+
"mlp_type": "mlp2",
|
| 458 |
+
"mm_hidden_size": 1024,
|
| 459 |
+
"mm_projector_type": "patchmergerv2",
|
| 460 |
+
"norm_type": "rmsnorm",
|
| 461 |
+
"patch_embed_proj_bias": false,
|
| 462 |
+
"patch_size": 14,
|
| 463 |
+
"pos_emb_interpolation_mode": "bilinear",
|
| 464 |
+
"pos_emb_type": "divided_fixed",
|
| 465 |
+
"projector_hidden_act": "gelu",
|
| 466 |
+
"projector_ln_eps": 1e-05,
|
| 467 |
+
"qkv_hidden_size": 1536,
|
| 468 |
+
"text_hidden_size": 7168,
|
| 469 |
+
"vt_hidden_size": 1024,
|
| 470 |
+
"vt_intermediate_size": 4096,
|
| 471 |
+
"vt_num_attention_heads": 12,
|
| 472 |
+
"vt_num_hidden_layers": 27
|
| 473 |
+
}
|
| 474 |
+
}
|
configuration.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"framework": "pytorch", "task": "text-generation", "allow_remote": true}
|
configuration_kimi_k3.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
|
| 3 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class KimiLinearConfig(PretrainedConfig):
|
| 7 |
+
model_type = "kimi_linear"
|
| 8 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 9 |
+
|
| 10 |
+
def __init__(
|
| 11 |
+
self,
|
| 12 |
+
model_type="kimi_linear",
|
| 13 |
+
vocab_size=163840,
|
| 14 |
+
hidden_size=4096,
|
| 15 |
+
head_dim=None,
|
| 16 |
+
intermediate_size=11008,
|
| 17 |
+
num_hidden_layers=32,
|
| 18 |
+
num_attention_heads=32,
|
| 19 |
+
num_key_value_heads=None,
|
| 20 |
+
hidden_act="silu",
|
| 21 |
+
initializer_range=0.02,
|
| 22 |
+
rms_norm_eps=1e-6,
|
| 23 |
+
use_cache=True,
|
| 24 |
+
pad_token_id=0,
|
| 25 |
+
bos_token_id=1,
|
| 26 |
+
eos_token_id=2,
|
| 27 |
+
rope_theta=10000.0,
|
| 28 |
+
rope_scaling=None,
|
| 29 |
+
tie_word_embeddings=False,
|
| 30 |
+
moe_intermediate_size: Optional[int] = None,
|
| 31 |
+
moe_renormalize: bool = True,
|
| 32 |
+
moe_router_activation_func: str = "sigmoid",
|
| 33 |
+
num_experts: Optional[int] = None,
|
| 34 |
+
num_experts_per_token: Optional[int] = None,
|
| 35 |
+
num_shared_experts: int = 0,
|
| 36 |
+
routed_scaling_factor: float = 1.0,
|
| 37 |
+
first_k_dense_replace: int = 0,
|
| 38 |
+
moe_layer_freq: int = 1,
|
| 39 |
+
use_grouped_topk: bool = True,
|
| 40 |
+
num_expert_group: int = 1,
|
| 41 |
+
topk_group: int = 1,
|
| 42 |
+
q_lora_rank: Optional[int] = None,
|
| 43 |
+
kv_lora_rank: Optional[int] = None,
|
| 44 |
+
qk_nope_head_dim: Optional[int] = None,
|
| 45 |
+
qk_rope_head_dim: Optional[int] = None,
|
| 46 |
+
v_head_dim: Optional[int] = None,
|
| 47 |
+
mla_use_nope: Optional[bool] = False,
|
| 48 |
+
mla_use_output_gate: Optional[bool] = False,
|
| 49 |
+
num_nextn_predict_layers: int = 0,
|
| 50 |
+
linear_attn_config: Optional[dict] = None,
|
| 51 |
+
attn_res_block_size: Optional[int] = None,
|
| 52 |
+
latent_moe_use_norm: bool = False,
|
| 53 |
+
activation_situ_beta: Optional[float] = None,
|
| 54 |
+
activation_situ_linear_beta: Optional[float] = None,
|
| 55 |
+
max_position_embeddings: int = 4096,
|
| 56 |
+
routed_expert_hidden_size: Optional[int] = None,
|
| 57 |
+
topk_method: str = "noaux_tc",
|
| 58 |
+
**kwargs,
|
| 59 |
+
):
|
| 60 |
+
self.model_type = model_type
|
| 61 |
+
self.vocab_size = vocab_size
|
| 62 |
+
self.hidden_size = hidden_size
|
| 63 |
+
self.head_dim = (
|
| 64 |
+
head_dim if head_dim is not None else hidden_size // num_attention_heads
|
| 65 |
+
)
|
| 66 |
+
self.intermediate_size = intermediate_size
|
| 67 |
+
self.num_hidden_layers = num_hidden_layers
|
| 68 |
+
self.num_attention_heads = num_attention_heads
|
| 69 |
+
|
| 70 |
+
# for backward compatibility
|
| 71 |
+
if num_key_value_heads is None:
|
| 72 |
+
num_key_value_heads = num_attention_heads
|
| 73 |
+
|
| 74 |
+
self.num_key_value_heads = num_key_value_heads
|
| 75 |
+
self.hidden_act = hidden_act
|
| 76 |
+
self.initializer_range = initializer_range
|
| 77 |
+
self.rms_norm_eps = rms_norm_eps
|
| 78 |
+
self.use_cache = use_cache
|
| 79 |
+
self.rope_theta = rope_theta
|
| 80 |
+
self.rope_scaling = rope_scaling
|
| 81 |
+
|
| 82 |
+
self.q_lora_rank = q_lora_rank
|
| 83 |
+
self.kv_lora_rank = kv_lora_rank
|
| 84 |
+
self.qk_nope_head_dim = qk_nope_head_dim
|
| 85 |
+
self.qk_rope_head_dim = qk_rope_head_dim
|
| 86 |
+
self.v_head_dim = v_head_dim
|
| 87 |
+
self.mla_use_nope = mla_use_nope
|
| 88 |
+
self.mla_use_output_gate = mla_use_output_gate
|
| 89 |
+
# moe config
|
| 90 |
+
self.num_experts = num_experts
|
| 91 |
+
self.num_experts_per_token = num_experts_per_token
|
| 92 |
+
self.moe_renormalize = moe_renormalize
|
| 93 |
+
self.num_shared_experts = num_shared_experts
|
| 94 |
+
self.routed_scaling_factor = routed_scaling_factor
|
| 95 |
+
self.moe_router_activation_func = moe_router_activation_func
|
| 96 |
+
assert self.moe_router_activation_func in ("softmax", "sigmoid")
|
| 97 |
+
self.moe_intermediate_size = moe_intermediate_size
|
| 98 |
+
self.first_k_dense_replace = first_k_dense_replace
|
| 99 |
+
self.moe_layer_freq = moe_layer_freq
|
| 100 |
+
self.use_grouped_topk = use_grouped_topk
|
| 101 |
+
self.num_expert_group = num_expert_group
|
| 102 |
+
self.topk_group = topk_group
|
| 103 |
+
self.num_nextn_predict_layers = num_nextn_predict_layers
|
| 104 |
+
|
| 105 |
+
self.attn_res_block_size = attn_res_block_size
|
| 106 |
+
self.latent_moe_use_norm = latent_moe_use_norm
|
| 107 |
+
self.activation_situ_beta = activation_situ_beta
|
| 108 |
+
self.activation_situ_linear_beta = activation_situ_linear_beta
|
| 109 |
+
self.max_position_embeddings = max_position_embeddings
|
| 110 |
+
self.routed_expert_hidden_size = routed_expert_hidden_size
|
| 111 |
+
self.topk_method = topk_method
|
| 112 |
+
|
| 113 |
+
if linear_attn_config is not None:
|
| 114 |
+
assert linear_attn_config["kda_layers"] is not None
|
| 115 |
+
assert linear_attn_config["full_attn_layers"] is not None
|
| 116 |
+
self.linear_attn_config = linear_attn_config
|
| 117 |
+
|
| 118 |
+
super().__init__(
|
| 119 |
+
pad_token_id=pad_token_id,
|
| 120 |
+
bos_token_id=bos_token_id,
|
| 121 |
+
eos_token_id=eos_token_id,
|
| 122 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 123 |
+
**kwargs,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
@property
|
| 127 |
+
def is_mla(self):
|
| 128 |
+
return (
|
| 129 |
+
self.q_lora_rank is not None
|
| 130 |
+
or self.kv_lora_rank is not None
|
| 131 |
+
or self.qk_nope_head_dim is not None
|
| 132 |
+
or self.qk_rope_head_dim is not None
|
| 133 |
+
or self.v_head_dim is not None
|
| 134 |
+
or self.mla_use_nope is True
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
@property
|
| 138 |
+
def is_moe(self):
|
| 139 |
+
return self.num_experts is not None
|
| 140 |
+
|
| 141 |
+
@property
|
| 142 |
+
def is_linear_attn(self) -> bool:
|
| 143 |
+
return not (
|
| 144 |
+
self.linear_attn_config is None
|
| 145 |
+
or (
|
| 146 |
+
isinstance(self.linear_attn_config, dict)
|
| 147 |
+
and self.linear_attn_config["kda_layers"] is not None
|
| 148 |
+
and len(self.linear_attn_config["kda_layers"]) == 0
|
| 149 |
+
)
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
def is_kda_layer(self, layer_idx: int):
|
| 153 |
+
return (
|
| 154 |
+
self.linear_attn_config is not None
|
| 155 |
+
and (layer_idx + 1) in self.linear_attn_config["kda_layers"]
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
class KimiK3VisionConfig(PretrainedConfig):
|
| 160 |
+
|
| 161 |
+
def __init__(
|
| 162 |
+
self,
|
| 163 |
+
patch_size: int = 14,
|
| 164 |
+
init_pos_emb_height: int = 64,
|
| 165 |
+
init_pos_emb_width: int = 64,
|
| 166 |
+
init_pos_emb_time: int = 4,
|
| 167 |
+
pos_emb_type: str = 'divided_fixed',
|
| 168 |
+
vt_num_attention_heads: int = 12,
|
| 169 |
+
vt_num_hidden_layers: int = 27,
|
| 170 |
+
vt_hidden_size: int = 1024,
|
| 171 |
+
vt_intermediate_size: int = 4096,
|
| 172 |
+
merge_kernel_size: tuple = (2, 2),
|
| 173 |
+
merge_type: str = 'sd2_tpool',
|
| 174 |
+
_attn_implementation: str = 'flash_attention_2',
|
| 175 |
+
# MM Projector parameters
|
| 176 |
+
mm_projector_type: str = 'patchmergerv2',
|
| 177 |
+
mm_hidden_size: int | None = None,
|
| 178 |
+
projector_hidden_act: str = "gelu",
|
| 179 |
+
projector_ln_eps: float = 1e-5,
|
| 180 |
+
# vision tower parameters
|
| 181 |
+
qkv_hidden_size: int = 1536,
|
| 182 |
+
norm_type: str = 'rmsnorm',
|
| 183 |
+
attn_bias: bool = False,
|
| 184 |
+
patch_embed_proj_bias: bool = False,
|
| 185 |
+
mlp_type: str = 'mlp2',
|
| 186 |
+
linear_bias: bool = False,
|
| 187 |
+
activation_func: str = 'gelu_pytorch_tanh',
|
| 188 |
+
pos_emb_interpolation_mode: str = 'bilinear',
|
| 189 |
+
# Other parameters
|
| 190 |
+
ignore_index: int = -100,
|
| 191 |
+
media_placeholder_token_id: int = 163605,
|
| 192 |
+
pad_token_id: int = 0,
|
| 193 |
+
text_hidden_size=7168,
|
| 194 |
+
**kwargs):
|
| 195 |
+
|
| 196 |
+
self.patch_size = patch_size
|
| 197 |
+
self.init_pos_emb_height = init_pos_emb_height
|
| 198 |
+
self.init_pos_emb_width = init_pos_emb_width
|
| 199 |
+
self.init_pos_emb_time = init_pos_emb_time
|
| 200 |
+
self.pos_emb_type = pos_emb_type
|
| 201 |
+
self.vt_num_attention_heads = vt_num_attention_heads
|
| 202 |
+
self.vt_num_hidden_layers = vt_num_hidden_layers
|
| 203 |
+
self.vt_hidden_size = vt_hidden_size
|
| 204 |
+
self.vt_intermediate_size = vt_intermediate_size
|
| 205 |
+
self.merge_kernel_size = merge_kernel_size
|
| 206 |
+
self.merge_type = merge_type
|
| 207 |
+
self._attn_implementation = _attn_implementation
|
| 208 |
+
|
| 209 |
+
# MM Projector config
|
| 210 |
+
self.mm_projector_type = mm_projector_type
|
| 211 |
+
self.mm_hidden_size = mm_hidden_size if mm_hidden_size is not None else vt_hidden_size
|
| 212 |
+
self.projector_hidden_act = projector_hidden_act
|
| 213 |
+
self.projector_ln_eps = projector_ln_eps
|
| 214 |
+
self.text_hidden_size = text_hidden_size
|
| 215 |
+
|
| 216 |
+
# vision tower parameters
|
| 217 |
+
self.qkv_hidden_size = qkv_hidden_size
|
| 218 |
+
self.norm_type = norm_type
|
| 219 |
+
self.attn_bias = attn_bias
|
| 220 |
+
self.patch_embed_proj_bias = patch_embed_proj_bias
|
| 221 |
+
self.mlp_type = mlp_type
|
| 222 |
+
self.linear_bias = linear_bias
|
| 223 |
+
self.activation_func = activation_func
|
| 224 |
+
self.pos_emb_interpolation_mode = pos_emb_interpolation_mode
|
| 225 |
+
|
| 226 |
+
super().__init__(**kwargs)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
class KimiK3Config(PretrainedConfig):
|
| 230 |
+
"""Kimi-K3 model configuration.
|
| 231 |
+
|
| 232 |
+
Args:
|
| 233 |
+
text_config (dict | KimiLinearConfig): Configuration for the text model.
|
| 234 |
+
|
| 235 |
+
Vision Tower Parameters (from MoonViT3dConfig):
|
| 236 |
+
patch_size (int): Patch size for vision tower.
|
| 237 |
+
init_pos_emb_height (int): Initial position embedding height.
|
| 238 |
+
init_pos_emb_width (int): Initial position embedding width.
|
| 239 |
+
init_pos_emb_time (int): Initial position embedding time dimension.
|
| 240 |
+
pos_emb_type (str): Type of position embedding.
|
| 241 |
+
vt_num_attention_heads (int): Number of attention heads in vision tower.
|
| 242 |
+
vt_num_hidden_layers (int): Number of hidden layers in vision tower.
|
| 243 |
+
vt_hidden_size (int): Hidden size of vision tower.
|
| 244 |
+
vt_intermediate_size (int): Intermediate size in vision tower FFN.
|
| 245 |
+
merge_kernel_size (tuple): Kernel size for patch merging.
|
| 246 |
+
merge_type (str): Type of merge operation.
|
| 247 |
+
_attn_implementation (str): Attention implementation type.
|
| 248 |
+
|
| 249 |
+
MM Projector Parameters (from MultiModalProjectorConfig):
|
| 250 |
+
mm_projector_type (str): Type of multimodal projector.
|
| 251 |
+
mm_hidden_size (int): Hidden size from vision tower (should match vt_hidden_size).
|
| 252 |
+
projector_hidden_act (str): Activation function for projector.
|
| 253 |
+
projector_ln_eps (float): Layer norm epsilon for projector.
|
| 254 |
+
|
| 255 |
+
Other Parameters:
|
| 256 |
+
ignore_index (int): The ignore index for the loss function.
|
| 257 |
+
media_placeholder_token_id (int): The token ID to use for media placeholders.
|
| 258 |
+
pad_token_id (int): The token ID to use for padding.
|
| 259 |
+
"""
|
| 260 |
+
|
| 261 |
+
model_type = "kimi_k3"
|
| 262 |
+
|
| 263 |
+
def __init__(
|
| 264 |
+
self,
|
| 265 |
+
text_config: dict | KimiLinearConfig = None,
|
| 266 |
+
vision_config: dict | KimiK3VisionConfig = None,
|
| 267 |
+
# Other parameters
|
| 268 |
+
ignore_index: int = -100,
|
| 269 |
+
media_placeholder_token_id: int = 163605,
|
| 270 |
+
pad_token_id: int = 0,
|
| 271 |
+
**kwargs,
|
| 272 |
+
):
|
| 273 |
+
if isinstance(text_config, dict):
|
| 274 |
+
text_config = KimiLinearConfig(**text_config)
|
| 275 |
+
if isinstance(vision_config, dict):
|
| 276 |
+
vision_config = KimiK3VisionConfig(**vision_config)
|
| 277 |
+
self.text_config = text_config
|
| 278 |
+
self.vision_config = vision_config
|
| 279 |
+
# Other config
|
| 280 |
+
self.ignore_index = ignore_index
|
| 281 |
+
self.media_placeholder_token_id = media_placeholder_token_id
|
| 282 |
+
if getattr(self.text_config, "quantization_config", None) is not None:
|
| 283 |
+
self.quantization_config = self.text_config.quantization_config
|
| 284 |
+
|
| 285 |
+
super().__init__(pad_token_id=pad_token_id, **kwargs)
|
cubic_quantization_report.json
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"manifest": {
|
| 3 |
+
"source": "moonshotai/Kimi-K3",
|
| 4 |
+
"output": "Kimi-K3-Cubic-2.5Bit",
|
| 5 |
+
"moe_schedule": "1-3:3@256,4-32:3@512,33-91:2@512,92:4@512",
|
| 6 |
+
"linear_schedule": "",
|
| 7 |
+
"conversion_hardware": {
|
| 8 |
+
"device_type": "cuda",
|
| 9 |
+
"device_count": 8
|
| 10 |
+
},
|
| 11 |
+
"shard_size_gib": 3.0,
|
| 12 |
+
"a8_carrier_aware": true,
|
| 13 |
+
"a8_correction_default": "enabled",
|
| 14 |
+
"fitting_objective": "groupwise-least-squares",
|
| 15 |
+
"reported_loss": "NRMSE = sqrt(joint SSE / source weight SSE)",
|
| 16 |
+
"row_chunk_size": -1,
|
| 17 |
+
"source_shards": 96,
|
| 18 |
+
"expert_payload_bits": 2.369565217391304,
|
| 19 |
+
"expert_effective_bits": 2.498641304347826,
|
| 20 |
+
"converted_tensor_effective_bits": 2.498641304347826,
|
| 21 |
+
"worker_scheduling": "dynamic_source_shard_queue",
|
| 22 |
+
"output_partitioning": "deterministic_source_shard_index",
|
| 23 |
+
"script": "quantize_k3.py",
|
| 24 |
+
"script_sha256": "89fe8836bb407a027a2663637bc0380bd1adb29ffb2778f0879e606dc8ed31f3",
|
| 25 |
+
"source_config_sha256": "9710e121a58d03ac92c8d6da287a19541994319afbbe6d6202af001ffd379213",
|
| 26 |
+
"source_index_sha256": "a1c5210650ce71d2d3ae9ec5a101ac4afd3cf4b10091be589853437eb967febd",
|
| 27 |
+
"output_shards": 341,
|
| 28 |
+
"output_total_bytes": 964943224704,
|
| 29 |
+
"combined_report": "cubic_quantization_report.json"
|
| 30 |
+
},
|
| 31 |
+
"loss_statistics": {
|
| 32 |
+
"objective": "mean(continuous MSE, rounded-A8-carrier MSE)",
|
| 33 |
+
"normalization": "loss is sqrt(joint SSE / source weight SSE), i.e. NRMSE; the fitting objective itself remains least squares.",
|
| 34 |
+
"metadata_precision": "FP32 scale and FP16 a/b before recomputation",
|
| 35 |
+
"by_bit": {
|
| 36 |
+
"2": {
|
| 37 |
+
"bits": 2,
|
| 38 |
+
"loss": 0.4512510057287302,
|
| 39 |
+
"clipped_percent": 12.230740958337455,
|
| 40 |
+
"a8_correction_loss": 0.4512510057287302
|
| 41 |
+
},
|
| 42 |
+
"3": {
|
| 43 |
+
"bits": 3,
|
| 44 |
+
"loss": 0.18088323398973324,
|
| 45 |
+
"clipped_percent": 2.966870055819044,
|
| 46 |
+
"a8_correction_loss": 0.18091672638061443
|
| 47 |
+
},
|
| 48 |
+
"4": {
|
| 49 |
+
"bits": 4,
|
| 50 |
+
"loss": 0.0430471542191854,
|
| 51 |
+
"clipped_percent": 0.5635432713156114,
|
| 52 |
+
"a8_correction_loss": 0.04324462046872603
|
| 53 |
+
}
|
| 54 |
+
},
|
| 55 |
+
"by_bit_and_group_size": {
|
| 56 |
+
"2@512": {
|
| 57 |
+
"bits": 2,
|
| 58 |
+
"loss": 0.4512510057287302,
|
| 59 |
+
"clipped_percent": 12.230740958337455,
|
| 60 |
+
"a8_correction_loss": 0.4512510057287302,
|
| 61 |
+
"group_size": 512
|
| 62 |
+
},
|
| 63 |
+
"3@256": {
|
| 64 |
+
"bits": 3,
|
| 65 |
+
"loss": 0.17960835023454785,
|
| 66 |
+
"clipped_percent": 2.6970932295353056,
|
| 67 |
+
"a8_correction_loss": 0.1795795260456478,
|
| 68 |
+
"group_size": 256
|
| 69 |
+
},
|
| 70 |
+
"3@512": {
|
| 71 |
+
"bits": 3,
|
| 72 |
+
"loss": 0.18100745927884193,
|
| 73 |
+
"clipped_percent": 2.994778003365638,
|
| 74 |
+
"a8_correction_loss": 0.18104699922459405,
|
| 75 |
+
"group_size": 512
|
| 76 |
+
},
|
| 77 |
+
"4@512": {
|
| 78 |
+
"bits": 4,
|
| 79 |
+
"loss": 0.0430471542191854,
|
| 80 |
+
"clipped_percent": 0.5635432713156114,
|
| 81 |
+
"a8_correction_loss": 0.04324462046872603,
|
| 82 |
+
"group_size": 512
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
},
|
| 86 |
+
"audit": {
|
| 87 |
+
"checkpoint": "Kimi-K3-Cubic-2.5Bit",
|
| 88 |
+
"shards": 341,
|
| 89 |
+
"tensors": 991812,
|
| 90 |
+
"total_size": 964943224704,
|
| 91 |
+
"max_shard_bytes": 3221225472,
|
| 92 |
+
"widths_present": [
|
| 93 |
+
2,
|
| 94 |
+
3,
|
| 95 |
+
4
|
| 96 |
+
],
|
| 97 |
+
"converted_tensor_effective_bits": 2.498641304347826,
|
| 98 |
+
"dtype_counts": {
|
| 99 |
+
"BF16": 2122,
|
| 100 |
+
"F32": 247802,
|
| 101 |
+
"F16": 494592,
|
| 102 |
+
"U8": 247296
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
}
|
encoding_k3.py
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Kimi K3 XTML encoding helpers.
|
| 2 |
+
|
| 3 |
+
This module keeps chat rendering in Python.
|
| 4 |
+
Callers that need token IDs should consume ``EncodeSegment`` objects directly:
|
| 5 |
+
structural markers may be encoded as tiktoken special tokens, while user/tool
|
| 6 |
+
text and attribute values are encoded as ordinary text.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import json
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
from typing import Any, Iterable, Optional
|
| 14 |
+
|
| 15 |
+
OPEN_TOKEN = "<|open|>"
|
| 16 |
+
CLOSE_TOKEN = "<|close|>"
|
| 17 |
+
SEP_TOKEN = "<|sep|>"
|
| 18 |
+
END_OF_MSG_TOKEN = "<|end_of_msg|>"
|
| 19 |
+
IMAGE_PLACEHOLDER = "<|kimi_image_placeholder|>"
|
| 20 |
+
|
| 21 |
+
_VALID_THINKING_EFFORTS = {"low", "high", "max"}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@dataclass(frozen=True)
|
| 25 |
+
class EncodeSegment:
|
| 26 |
+
text: str
|
| 27 |
+
allow_special: bool = False
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class _ImagePromptState:
|
| 31 |
+
def __init__(self, image_prompts: Optional[list[str]] = None):
|
| 32 |
+
self.image_prompts = image_prompts
|
| 33 |
+
self.index = 0
|
| 34 |
+
|
| 35 |
+
def next_prompt(self) -> str:
|
| 36 |
+
if self.image_prompts is None:
|
| 37 |
+
return IMAGE_PLACEHOLDER
|
| 38 |
+
if self.index >= len(self.image_prompts):
|
| 39 |
+
raise ValueError("More image placeholders than image prompts.")
|
| 40 |
+
prompt = self.image_prompts[self.index]
|
| 41 |
+
self.index += 1
|
| 42 |
+
return prompt
|
| 43 |
+
|
| 44 |
+
def assert_consumed(self) -> None:
|
| 45 |
+
if self.image_prompts is None:
|
| 46 |
+
return
|
| 47 |
+
if self.index != len(self.image_prompts):
|
| 48 |
+
raise ValueError(
|
| 49 |
+
f"image prompt count {len(self.image_prompts)} != "
|
| 50 |
+
f"consumed placeholder count {self.index}"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _segment(text: Any, *, allow_special: bool = False) -> list[EncodeSegment]:
|
| 55 |
+
text = str(text)
|
| 56 |
+
if not text:
|
| 57 |
+
return []
|
| 58 |
+
return [EncodeSegment(text, allow_special=allow_special)]
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _control(text: str) -> list[EncodeSegment]:
|
| 62 |
+
return _segment(text, allow_special=True)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def _text(text: Any) -> list[EncodeSegment]:
|
| 66 |
+
return _segment(text, allow_special=False)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _append_text(
|
| 70 |
+
segments: list[EncodeSegment],
|
| 71 |
+
text: Any,
|
| 72 |
+
image_state: _ImagePromptState,
|
| 73 |
+
) -> None:
|
| 74 |
+
text = str(text)
|
| 75 |
+
if text == "":
|
| 76 |
+
return
|
| 77 |
+
if image_state.image_prompts is None or IMAGE_PLACEHOLDER not in text:
|
| 78 |
+
segments.extend(_text(text))
|
| 79 |
+
return
|
| 80 |
+
|
| 81 |
+
parts = text.split(IMAGE_PLACEHOLDER)
|
| 82 |
+
for i, part in enumerate(parts):
|
| 83 |
+
segments.extend(_text(part))
|
| 84 |
+
if i < len(parts) - 1:
|
| 85 |
+
segments.extend(_segment(image_state.next_prompt(),
|
| 86 |
+
allow_special=True))
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def _escape_attr_value(value: Any) -> str:
|
| 90 |
+
return str(value).replace("&", "&").replace('"', """)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def _attr(key: str, value: Any) -> list[EncodeSegment]:
|
| 94 |
+
return (
|
| 95 |
+
_text(f" {key}")
|
| 96 |
+
+ _text('="')
|
| 97 |
+
+ _text(_escape_attr_value(value))
|
| 98 |
+
+ _text('"')
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _open_tag(tag: str, attrs: Iterable[tuple[str, Any]] = ()) -> list[EncodeSegment]:
|
| 103 |
+
segments: list[EncodeSegment] = []
|
| 104 |
+
segments.extend(_control(OPEN_TOKEN))
|
| 105 |
+
segments.extend(_text(tag))
|
| 106 |
+
for key, value in attrs:
|
| 107 |
+
segments.extend(_attr(key, value))
|
| 108 |
+
segments.extend(_control(SEP_TOKEN))
|
| 109 |
+
return segments
|
| 110 |
+
|
| 111 |
+
def _close_tag(tag: str) -> list[EncodeSegment]:
|
| 112 |
+
segments: list[EncodeSegment] = []
|
| 113 |
+
segments.extend(_control(CLOSE_TOKEN))
|
| 114 |
+
segments.extend(_text(tag))
|
| 115 |
+
segments.extend(_control(SEP_TOKEN))
|
| 116 |
+
return segments
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def _end_of_msg() -> list[EncodeSegment]:
|
| 120 |
+
return _control(END_OF_MSG_TOKEN)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def _json_compact(value: Any) -> str:
|
| 124 |
+
return json.dumps(value, ensure_ascii=False, separators=(",", ":"))
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _is_mapping(value: Any) -> bool:
|
| 128 |
+
return isinstance(value, dict)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _xtml_type(value: Any) -> str:
|
| 132 |
+
if isinstance(value, bool):
|
| 133 |
+
return "boolean"
|
| 134 |
+
if value is None:
|
| 135 |
+
return "null"
|
| 136 |
+
if isinstance(value, (int, float)) and not isinstance(value, bool):
|
| 137 |
+
return "number"
|
| 138 |
+
if isinstance(value, str):
|
| 139 |
+
return "string"
|
| 140 |
+
if _is_mapping(value):
|
| 141 |
+
return "object"
|
| 142 |
+
return "array"
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def _xtml_value(value: Any) -> str:
|
| 146 |
+
if isinstance(value, str):
|
| 147 |
+
return value
|
| 148 |
+
return json.dumps(value, ensure_ascii=False)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def _get_value(obj: Any, key: str, default: Any = None) -> Any:
|
| 152 |
+
if isinstance(obj, dict):
|
| 153 |
+
return obj.get(key, default)
|
| 154 |
+
return getattr(obj, key, default)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def extract_response_schema(response_format: Any) -> Any:
|
| 158 |
+
if response_format is None:
|
| 159 |
+
return None
|
| 160 |
+
|
| 161 |
+
json_schema = _get_value(response_format, "json_schema")
|
| 162 |
+
if json_schema is None:
|
| 163 |
+
return None
|
| 164 |
+
|
| 165 |
+
if isinstance(json_schema, dict):
|
| 166 |
+
return json_schema.get(
|
| 167 |
+
"schema",
|
| 168 |
+
json_schema.get("json_schema", json_schema),
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
schema = _get_value(json_schema, "schema")
|
| 172 |
+
if schema is not None:
|
| 173 |
+
return schema
|
| 174 |
+
|
| 175 |
+
schema = _get_value(json_schema, "json_schema")
|
| 176 |
+
if schema is not None:
|
| 177 |
+
return schema
|
| 178 |
+
|
| 179 |
+
return json_schema
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def deep_sort_dict(obj: Any) -> Any:
|
| 183 |
+
if isinstance(obj, dict):
|
| 184 |
+
return {k: deep_sort_dict(v) for k, v in sorted(obj.items())}
|
| 185 |
+
if isinstance(obj, list):
|
| 186 |
+
return [deep_sort_dict(item) for item in obj]
|
| 187 |
+
return obj
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def normalize_tool_arguments(arguments: Any) -> tuple[dict[str, Any], Optional[str]]:
|
| 191 |
+
if arguments is None:
|
| 192 |
+
return {}, None
|
| 193 |
+
if isinstance(arguments, dict):
|
| 194 |
+
return arguments, None
|
| 195 |
+
if isinstance(arguments, str):
|
| 196 |
+
if not arguments.strip():
|
| 197 |
+
return {}, None
|
| 198 |
+
try:
|
| 199 |
+
parsed = json.loads(arguments)
|
| 200 |
+
except json.JSONDecodeError:
|
| 201 |
+
return {}, arguments
|
| 202 |
+
if not isinstance(parsed, dict):
|
| 203 |
+
raise ValueError("Kimi K3 tool call arguments must be a JSON object.")
|
| 204 |
+
return parsed, None
|
| 205 |
+
raise TypeError(
|
| 206 |
+
"Kimi K3 tool call arguments must be a dict or a JSON object string."
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def normalize_message(message: Any) -> Any:
|
| 211 |
+
if not isinstance(message, dict):
|
| 212 |
+
return message
|
| 213 |
+
|
| 214 |
+
normalized = dict(message)
|
| 215 |
+
|
| 216 |
+
tools = normalized.get("tools")
|
| 217 |
+
if tools is not None:
|
| 218 |
+
normalized["tools"] = deep_sort_dict(tools)
|
| 219 |
+
|
| 220 |
+
tool_calls = normalized.get("tool_calls")
|
| 221 |
+
if not tool_calls:
|
| 222 |
+
return normalized
|
| 223 |
+
|
| 224 |
+
normalized_calls = []
|
| 225 |
+
for tool_call in tool_calls:
|
| 226 |
+
if not isinstance(tool_call, dict):
|
| 227 |
+
normalized_calls.append(tool_call)
|
| 228 |
+
continue
|
| 229 |
+
|
| 230 |
+
tc = dict(tool_call)
|
| 231 |
+
function = tc.get("function")
|
| 232 |
+
if isinstance(function, dict):
|
| 233 |
+
fn = dict(function)
|
| 234 |
+
arguments, json_block = normalize_tool_arguments(fn.get("arguments"))
|
| 235 |
+
fn["arguments"] = arguments
|
| 236 |
+
if json_block is None:
|
| 237 |
+
fn.pop("_xtml_json_block", None)
|
| 238 |
+
else:
|
| 239 |
+
fn["_xtml_json_block"] = json_block
|
| 240 |
+
tc["function"] = fn
|
| 241 |
+
else:
|
| 242 |
+
arguments, json_block = normalize_tool_arguments(tc.get("arguments"))
|
| 243 |
+
tc["arguments"] = arguments
|
| 244 |
+
if json_block is None:
|
| 245 |
+
tc.pop("_xtml_json_block", None)
|
| 246 |
+
else:
|
| 247 |
+
tc["_xtml_json_block"] = json_block
|
| 248 |
+
normalized_calls.append(tc)
|
| 249 |
+
|
| 250 |
+
normalized["tool_calls"] = normalized_calls
|
| 251 |
+
return normalized
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def normalize_conversation(conversation: Any) -> Any:
|
| 255 |
+
if not isinstance(conversation, list):
|
| 256 |
+
return conversation
|
| 257 |
+
|
| 258 |
+
def normalize_messages(messages: list[Any]) -> list[Any]:
|
| 259 |
+
return [normalize_message(message) for message in messages]
|
| 260 |
+
|
| 261 |
+
if conversation and isinstance(conversation[0], list):
|
| 262 |
+
return [normalize_messages(messages) for messages in conversation]
|
| 263 |
+
return normalize_messages(conversation)
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _tool_call_id_index(tool_calls: Any) -> dict:
|
| 267 |
+
"""Map assistant ``tool_calls[].id`` to ``(1-based position, function name)``.
|
| 268 |
+
|
| 269 |
+
The position mirrors the chat template's enumeration over ``tool_calls``
|
| 270 |
+
(every entry advances the position, even an id-less one). Duplicate ids keep
|
| 271 |
+
their first occurrence.
|
| 272 |
+
"""
|
| 273 |
+
index: dict = {}
|
| 274 |
+
if not isinstance(tool_calls, list):
|
| 275 |
+
return index
|
| 276 |
+
for position, tool_call in enumerate(tool_calls, start=1):
|
| 277 |
+
if not isinstance(tool_call, dict):
|
| 278 |
+
continue
|
| 279 |
+
call_id = tool_call.get("id")
|
| 280 |
+
if call_id is None:
|
| 281 |
+
continue
|
| 282 |
+
key = str(call_id)
|
| 283 |
+
if key in index:
|
| 284 |
+
continue
|
| 285 |
+
function = tool_call.get("function")
|
| 286 |
+
name = (
|
| 287 |
+
function.get("name") if isinstance(function, dict) else tool_call.get("name")
|
| 288 |
+
)
|
| 289 |
+
index[key] = (position, name)
|
| 290 |
+
return index
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def normalize_xtml_tool_result_messages(messages: list[Any]) -> list[Any]:
|
| 294 |
+
"""Re-sort K3 XTML tool results into assistant ``tool_calls`` order.
|
| 295 |
+
|
| 296 |
+
Serving frameworks generally deliver tool results already in call order. A
|
| 297 |
+
direct Transformers caller, however, may pass OpenAI-style tool messages in any
|
| 298 |
+
order, so each run of consecutive tool messages is matched against the most
|
| 299 |
+
recent preceding assistant ``tool_calls`` by opaque ``tool_call_id`` ==
|
| 300 |
+
``tool_calls[].id`` (K3 drops the ``func:index`` format requirement) and
|
| 301 |
+
sorted by the matched 1-based position. The matched call is authoritative,
|
| 302 |
+
so each matched message's ``tool`` is set to that call's function name --
|
| 303 |
+
this keeps an explicit (and possibly stale) ``tool``/``name`` from drifting
|
| 304 |
+
out of sync with the reordered position. ``index`` is still derived from the
|
| 305 |
+
rendered position by the chat template. A run that cannot be fully matched is
|
| 306 |
+
left untouched. Re-running is idempotent.
|
| 307 |
+
|
| 308 |
+
This function is side-effect free: matched tool messages are shallow-copied
|
| 309 |
+
before their ``tool``/``name`` is rewritten, and every other message is
|
| 310 |
+
appended to the output as-is. The input list and its message objects are
|
| 311 |
+
never mutated.
|
| 312 |
+
"""
|
| 313 |
+
if not isinstance(messages, list):
|
| 314 |
+
return messages
|
| 315 |
+
|
| 316 |
+
output: list[Any] = []
|
| 317 |
+
current_index: dict = {}
|
| 318 |
+
i = 0
|
| 319 |
+
n = len(messages)
|
| 320 |
+
|
| 321 |
+
while i < n:
|
| 322 |
+
message = messages[i]
|
| 323 |
+
|
| 324 |
+
if isinstance(message, dict) and message.get("role") == "assistant":
|
| 325 |
+
tool_calls = message.get("tool_calls")
|
| 326 |
+
current_index = _tool_call_id_index(tool_calls) if tool_calls else {}
|
| 327 |
+
output.append(message)
|
| 328 |
+
i += 1
|
| 329 |
+
continue
|
| 330 |
+
|
| 331 |
+
if not isinstance(message, dict) or message.get("role") != "tool":
|
| 332 |
+
output.append(message)
|
| 333 |
+
i += 1
|
| 334 |
+
continue
|
| 335 |
+
|
| 336 |
+
run: list[tuple] = [] # (position, original_offset, message, name)
|
| 337 |
+
unresolved = False
|
| 338 |
+
offset = 0
|
| 339 |
+
while (
|
| 340 |
+
i < n and isinstance(messages[i], dict) and messages[i].get("role") == "tool"
|
| 341 |
+
):
|
| 342 |
+
tool_message = messages[i]
|
| 343 |
+
call_id = tool_message.get("tool_call_id", tool_message.get("id"))
|
| 344 |
+
matched = current_index.get(str(call_id)) if call_id is not None else None
|
| 345 |
+
if matched is None:
|
| 346 |
+
unresolved = True
|
| 347 |
+
run.append((None, offset, tool_message, None))
|
| 348 |
+
else:
|
| 349 |
+
position, name = matched
|
| 350 |
+
run.append((position, offset, tool_message, name))
|
| 351 |
+
offset += 1
|
| 352 |
+
i += 1
|
| 353 |
+
|
| 354 |
+
if unresolved:
|
| 355 |
+
output.extend(item[2] for item in run)
|
| 356 |
+
else:
|
| 357 |
+
run.sort(key=lambda item: (item[0], item[1]))
|
| 358 |
+
for _, _, tool_message, name in run:
|
| 359 |
+
if name is None:
|
| 360 |
+
output.append(tool_message)
|
| 361 |
+
continue
|
| 362 |
+
# The id-matched call is authoritative: align tool (and any
|
| 363 |
+
# explicit name) so the rendered XTML tool attribute cannot
|
| 364 |
+
# disagree with the reordered position. Copy first so the
|
| 365 |
+
# caller's message object is never mutated.
|
| 366 |
+
resolved = dict(tool_message)
|
| 367 |
+
resolved["tool"] = name
|
| 368 |
+
if "name" in resolved:
|
| 369 |
+
resolved["name"] = name
|
| 370 |
+
output.append(resolved)
|
| 371 |
+
|
| 372 |
+
return output
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
def is_batched_conversation(conversation: Any) -> bool:
|
| 376 |
+
return (
|
| 377 |
+
isinstance(conversation, list)
|
| 378 |
+
and bool(conversation)
|
| 379 |
+
and isinstance(conversation[0], list)
|
| 380 |
+
)
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def _render_content_segments(
|
| 384 |
+
content: Any,
|
| 385 |
+
image_state: _ImagePromptState,
|
| 386 |
+
) -> list[EncodeSegment]:
|
| 387 |
+
segments: list[EncodeSegment] = []
|
| 388 |
+
if isinstance(content, str):
|
| 389 |
+
_append_text(segments, content, image_state)
|
| 390 |
+
elif content is not None:
|
| 391 |
+
for part in content:
|
| 392 |
+
if part["type"] in ["image", "image_url"]:
|
| 393 |
+
segments.extend(
|
| 394 |
+
_segment(image_state.next_prompt(), allow_special=True))
|
| 395 |
+
else:
|
| 396 |
+
_append_text(segments, part["text"], image_state)
|
| 397 |
+
return segments
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
def _internal_system_message(message_type: str, body: str) -> list[EncodeSegment]:
|
| 401 |
+
segments: list[EncodeSegment] = []
|
| 402 |
+
segments.extend(_open_tag("message", [("role", "system"), ("type", message_type)]))
|
| 403 |
+
segments.extend(_text(body.strip()))
|
| 404 |
+
segments.extend(_close_tag("message"))
|
| 405 |
+
segments.extend(_end_of_msg())
|
| 406 |
+
return segments
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
def _render_assistant_segments(
|
| 410 |
+
message: dict[str, Any],
|
| 411 |
+
image_state: _ImagePromptState,
|
| 412 |
+
thinking: bool = True,
|
| 413 |
+
) -> list[EncodeSegment]:
|
| 414 |
+
segments: list[EncodeSegment] = []
|
| 415 |
+
# The <think> channel is structural: in thinking mode every assistant
|
| 416 |
+
# message carries the open/close tags even when there is no reasoning
|
| 417 |
+
# content to fill in. In non-thinking mode the channel is dropped
|
| 418 |
+
# entirely.
|
| 419 |
+
if thinking:
|
| 420 |
+
reasoning_content = message.get("reasoning_content") or message.get(
|
| 421 |
+
"reasoning"
|
| 422 |
+
)
|
| 423 |
+
segments.extend(_open_tag("think"))
|
| 424 |
+
if reasoning_content is not None and str(reasoning_content).strip():
|
| 425 |
+
_append_text(segments, reasoning_content, image_state)
|
| 426 |
+
segments.extend(_close_tag("think"))
|
| 427 |
+
|
| 428 |
+
segments.extend(_open_tag("response"))
|
| 429 |
+
segments.extend(_render_content_segments(message.get("content"), image_state))
|
| 430 |
+
segments.extend(_close_tag("response"))
|
| 431 |
+
|
| 432 |
+
tool_calls = message.get("tool_calls")
|
| 433 |
+
if tool_calls:
|
| 434 |
+
segments.extend(_open_tag("tools"))
|
| 435 |
+
for index, tool_call in enumerate(tool_calls, start=1):
|
| 436 |
+
fn = tool_call.get("function", tool_call)
|
| 437 |
+
segments.extend(
|
| 438 |
+
_open_tag("call", [("tool", fn["name"]), ("index", index)])
|
| 439 |
+
)
|
| 440 |
+
args = fn.get("arguments", {})
|
| 441 |
+
json_block = fn.get("_xtml_json_block")
|
| 442 |
+
if json_block is not None:
|
| 443 |
+
segments.extend(_open_tag("json", [("type", "object")]))
|
| 444 |
+
_append_text(segments, json_block, image_state)
|
| 445 |
+
segments.extend(_close_tag("json"))
|
| 446 |
+
elif _is_mapping(args):
|
| 447 |
+
for key, value in args.items():
|
| 448 |
+
segments.extend(
|
| 449 |
+
_open_tag(
|
| 450 |
+
"argument",
|
| 451 |
+
[("key", key), ("type", _xtml_type(value))],
|
| 452 |
+
)
|
| 453 |
+
)
|
| 454 |
+
_append_text(segments, _xtml_value(value), image_state)
|
| 455 |
+
segments.extend(_close_tag("argument"))
|
| 456 |
+
segments.extend(_close_tag("call"))
|
| 457 |
+
segments.extend(_close_tag("tools"))
|
| 458 |
+
|
| 459 |
+
return segments
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
def _render_tool_declare(tools: Any, *, dynamic: bool = False) -> list[EncodeSegment]:
|
| 463 |
+
if dynamic:
|
| 464 |
+
body = (
|
| 465 |
+
"## New Tools Available\n"
|
| 466 |
+
"The system dynamically extends the toolset via lazy-loading.\n"
|
| 467 |
+
"You have access to all existing and extended tools.\n"
|
| 468 |
+
"Here are the specs for the extended tools.\n\n"
|
| 469 |
+
"```json\n"
|
| 470 |
+
f"{_json_compact(tools)}\n"
|
| 471 |
+
"```"
|
| 472 |
+
)
|
| 473 |
+
else:
|
| 474 |
+
body = (
|
| 475 |
+
"# Tools\n"
|
| 476 |
+
"Here are the available tools, described in JSONSchema.\n\n"
|
| 477 |
+
"```json\n"
|
| 478 |
+
f"{_json_compact(tools)}\n"
|
| 479 |
+
"```"
|
| 480 |
+
)
|
| 481 |
+
segments: list[EncodeSegment] = []
|
| 482 |
+
segments.extend(_open_tag("message", [("role", "system"), ("type", "tool-declare")]))
|
| 483 |
+
segments.extend(_text(body))
|
| 484 |
+
segments.extend(_close_tag("message"))
|
| 485 |
+
segments.extend(_end_of_msg())
|
| 486 |
+
return segments
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def build_chat_segments(
|
| 490 |
+
messages: list[Any],
|
| 491 |
+
tools: Optional[list[dict]] = None,
|
| 492 |
+
*,
|
| 493 |
+
add_generation_prompt: bool = True,
|
| 494 |
+
thinking: bool = True,
|
| 495 |
+
image_prompts: Optional[list[str]] = None,
|
| 496 |
+
**kwargs: Any,
|
| 497 |
+
) -> list[EncodeSegment]:
|
| 498 |
+
# Re-sort tool results by tool_call_id at the lowest layer so every caller
|
| 499 |
+
# (processor or direct tokenizer) gets correctly ordered XTML. The helper is
|
| 500 |
+
# side-effect free, so the caller's message objects are left untouched.
|
| 501 |
+
messages = normalize_xtml_tool_result_messages(messages)
|
| 502 |
+
messages = normalize_conversation(messages)
|
| 503 |
+
tools = deep_sort_dict(tools)
|
| 504 |
+
|
| 505 |
+
kwargs = dict(kwargs)
|
| 506 |
+
response_format = kwargs.get("response_format")
|
| 507 |
+
if "response_schema" not in kwargs:
|
| 508 |
+
response_schema = extract_response_schema(response_format)
|
| 509 |
+
if response_schema is not None:
|
| 510 |
+
kwargs["response_schema"] = response_schema
|
| 511 |
+
if kwargs.get("response_schema") is not None:
|
| 512 |
+
kwargs["response_schema"] = deep_sort_dict(kwargs["response_schema"])
|
| 513 |
+
|
| 514 |
+
image_state = _ImagePromptState(image_prompts)
|
| 515 |
+
segments: list[EncodeSegment] = []
|
| 516 |
+
|
| 517 |
+
tool_calls = None
|
| 518 |
+
tool_index = 0
|
| 519 |
+
|
| 520 |
+
if tools:
|
| 521 |
+
segments.extend(_render_tool_declare(tools))
|
| 522 |
+
|
| 523 |
+
thinking_effort = kwargs.get("thinking_effort")
|
| 524 |
+
if thinking and thinking_effort is not None:
|
| 525 |
+
assert thinking_effort in _VALID_THINKING_EFFORTS, (
|
| 526 |
+
f"Unsupported thinking_effort={thinking_effort!r}; "
|
| 527 |
+
f"supported values are {sorted(_VALID_THINKING_EFFORTS)}."
|
| 528 |
+
)
|
| 529 |
+
if thinking and thinking_effort in _VALID_THINKING_EFFORTS:
|
| 530 |
+
segments.extend(
|
| 531 |
+
_internal_system_message(
|
| 532 |
+
"thinking-effort",
|
| 533 |
+
"`thinking_effort` guides on how much to think in your "
|
| 534 |
+
"thinking channel (not including the response channel), "
|
| 535 |
+
"supported values include `low`, `medium`, `high`, and `max`.\n"
|
| 536 |
+
f"Now the system is invoked with `thinking_effort={thinking_effort}`.",
|
| 537 |
+
)
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
for message_index, message in enumerate(messages):
|
| 541 |
+
if not isinstance(message, dict):
|
| 542 |
+
continue
|
| 543 |
+
|
| 544 |
+
role = message["role"]
|
| 545 |
+
if role == "user":
|
| 546 |
+
attrs = [("role", "user")]
|
| 547 |
+
if message.get("name"):
|
| 548 |
+
attrs.append(("name", message["name"]))
|
| 549 |
+
segments.extend(_open_tag("message", attrs))
|
| 550 |
+
segments.extend(_render_content_segments(message.get("content"), image_state))
|
| 551 |
+
segments.extend(_close_tag("message"))
|
| 552 |
+
segments.extend(_end_of_msg())
|
| 553 |
+
elif role == "system" and message.get("tools"):
|
| 554 |
+
segments.extend(_render_tool_declare(message["tools"], dynamic=True))
|
| 555 |
+
elif role == "system":
|
| 556 |
+
attrs = [("role", "system")]
|
| 557 |
+
if message.get("name"):
|
| 558 |
+
attrs.append(("name", message["name"]))
|
| 559 |
+
segments.extend(_open_tag("message", attrs))
|
| 560 |
+
segments.extend(_render_content_segments(message.get("content"), image_state))
|
| 561 |
+
segments.extend(_close_tag("message"))
|
| 562 |
+
segments.extend(_end_of_msg())
|
| 563 |
+
elif role == "tool":
|
| 564 |
+
tool_index += 1
|
| 565 |
+
tool_name = message.get("tool", message.get("name"))
|
| 566 |
+
if (
|
| 567 |
+
tool_name is None
|
| 568 |
+
and tool_calls is not None
|
| 569 |
+
and tool_index <= len(tool_calls)
|
| 570 |
+
):
|
| 571 |
+
tc = tool_calls[tool_index - 1]
|
| 572 |
+
fn = tc.get("function", tc)
|
| 573 |
+
tool_name = fn["name"]
|
| 574 |
+
if tool_name is None:
|
| 575 |
+
raise ValueError(
|
| 576 |
+
"Kimi K3 tool messages need a resolvable tool name: "
|
| 577 |
+
"carry `tool`/`name`, or match a preceding assistant "
|
| 578 |
+
"tool_call by order."
|
| 579 |
+
)
|
| 580 |
+
segments.extend(
|
| 581 |
+
_open_tag(
|
| 582 |
+
"message",
|
| 583 |
+
[("role", "tool"), ("tool", tool_name), ("index", tool_index)],
|
| 584 |
+
)
|
| 585 |
+
)
|
| 586 |
+
segments.extend(_render_content_segments(message.get("content"), image_state))
|
| 587 |
+
segments.extend(_close_tag("message"))
|
| 588 |
+
segments.extend(_end_of_msg())
|
| 589 |
+
elif role == "assistant":
|
| 590 |
+
tool_calls = message.get("tool_calls")
|
| 591 |
+
tool_index = 0
|
| 592 |
+
attrs = [("role", "assistant")]
|
| 593 |
+
if message.get("name"):
|
| 594 |
+
attrs.append(("name", message["name"]))
|
| 595 |
+
segments.extend(_open_tag("message", attrs))
|
| 596 |
+
segments.extend(_render_assistant_segments(message, image_state, thinking))
|
| 597 |
+
segments.extend(_close_tag("message"))
|
| 598 |
+
segments.extend(_end_of_msg())
|
| 599 |
+
|
| 600 |
+
tool_choice = kwargs.get("tool_choice")
|
| 601 |
+
if tool_choice == "required":
|
| 602 |
+
segments.extend(
|
| 603 |
+
_internal_system_message(
|
| 604 |
+
"tool-choice",
|
| 605 |
+
"The system is invoked with `tool_choice=required`.\n"
|
| 606 |
+
"You MUST call tools in the next message.",
|
| 607 |
+
)
|
| 608 |
+
)
|
| 609 |
+
elif tool_choice == "none":
|
| 610 |
+
segments.extend(
|
| 611 |
+
_internal_system_message(
|
| 612 |
+
"tool-choice",
|
| 613 |
+
"The system is invoked with `tool_choice=none`.\n"
|
| 614 |
+
"You MUST NOT call any tools in the next message.",
|
| 615 |
+
)
|
| 616 |
+
)
|
| 617 |
+
|
| 618 |
+
rf = kwargs.get("response_format")
|
| 619 |
+
rf_type = _get_value(rf, "type", rf) if isinstance(rf, dict) else rf
|
| 620 |
+
if rf_type == "json_object":
|
| 621 |
+
segments.extend(
|
| 622 |
+
_internal_system_message(
|
| 623 |
+
"response-format",
|
| 624 |
+
"The system is invoked with `response_format=json_object`.\n"
|
| 625 |
+
"Your response must be raw JSON data without markdown code "
|
| 626 |
+
"blocks (```json) or any additional formatting.",
|
| 627 |
+
)
|
| 628 |
+
)
|
| 629 |
+
elif rf_type == "json_schema":
|
| 630 |
+
schema = _json_compact(kwargs.get("response_schema"))
|
| 631 |
+
segments.extend(
|
| 632 |
+
_internal_system_message(
|
| 633 |
+
"response-format",
|
| 634 |
+
"The system is invoked with `response_format=json_schema`.\n"
|
| 635 |
+
"Your response must be raw JSON data without markdown code "
|
| 636 |
+
"blocks (```json) or any additional formatting.\n"
|
| 637 |
+
"The JSON data must match the following schema:\n"
|
| 638 |
+
f"```json\n{schema}\n```",
|
| 639 |
+
)
|
| 640 |
+
)
|
| 641 |
+
|
| 642 |
+
if add_generation_prompt:
|
| 643 |
+
segments.extend(_open_tag("message", [("role", "assistant")]))
|
| 644 |
+
segments.extend(_open_tag("think" if thinking else "response"))
|
| 645 |
+
|
| 646 |
+
image_state.assert_consumed()
|
| 647 |
+
return segments
|
generation_config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"max_length": 1048576,
|
| 3 |
+
"eos_token_id": 163586
|
| 4 |
+
}
|
kimi_k3_processor.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Kimi-K3 processor: wraps vision processor + tokenizer into a single interface.
|
| 2 |
+
|
| 3 |
+
Chat rendering (including XTML tool-result ordering) is handled by the
|
| 4 |
+
tokenizer's Python encoder; this processor adds multimodal media preprocessing.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from transformers.feature_extraction_utils import BatchFeature
|
| 8 |
+
from transformers.processing_utils import ProcessorMixin
|
| 9 |
+
from transformers.utils import logging
|
| 10 |
+
|
| 11 |
+
from .media_utils import ensure_media_type
|
| 12 |
+
|
| 13 |
+
logger = logging.get_logger(__name__)
|
| 14 |
+
|
| 15 |
+
# ── KimiK3Processor ───────────────────────────────────────────────────
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class KimiK3Processor(ProcessorMixin):
|
| 19 |
+
r"""
|
| 20 |
+
Constructs a KimiK3 processor which wraps a KimiK3 image processor
|
| 21 |
+
and a tokenizer into a single processor.
|
| 22 |
+
|
| 23 |
+
[`KimiK3Processor`] offers all the functionalities of
|
| 24 |
+
[`KimiK3VisionProcessor`] and [`TikTokenTokenizer`].
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
image_processor ([`KimiK3VisionProcessor`], *optional*):
|
| 28 |
+
The image processor is a required input.
|
| 29 |
+
tokenizer ([`TikTokenTokenizer`], *optional*):
|
| 30 |
+
The tokenizer is a required input.
|
| 31 |
+
chat_template (`str`, *optional*): Kept for ProcessorMixin
|
| 32 |
+
compatibility. Kimi K3 chat encoding is implemented in Python by
|
| 33 |
+
the tokenizer.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
attributes = ["image_processor", "tokenizer"]
|
| 37 |
+
valid_kwargs = ["chat_template"]
|
| 38 |
+
image_processor_class = "AutoImageProcessor"
|
| 39 |
+
tokenizer_class = "AutoTokenizer"
|
| 40 |
+
|
| 41 |
+
def __init__(
|
| 42 |
+
self,
|
| 43 |
+
image_processor=None,
|
| 44 |
+
tokenizer=None,
|
| 45 |
+
chat_template=None,
|
| 46 |
+
**kwargs,
|
| 47 |
+
):
|
| 48 |
+
super().__init__(image_processor,
|
| 49 |
+
tokenizer,
|
| 50 |
+
chat_template=chat_template)
|
| 51 |
+
self.media_processor = image_processor
|
| 52 |
+
self.image_placeholder = "<|kimi_image_placeholder|>"
|
| 53 |
+
|
| 54 |
+
# ── Media preprocessing ────────────────────────────────────────────
|
| 55 |
+
|
| 56 |
+
def update_raw_text(self, text: str, image_prompts: list[str]) -> str:
|
| 57 |
+
# Replace image placeholders
|
| 58 |
+
image_count = text.count(self.image_placeholder)
|
| 59 |
+
if image_count > 0:
|
| 60 |
+
assert image_count == len(image_prompts), (
|
| 61 |
+
f"image placeholder count {image_count} != "
|
| 62 |
+
f"image_prompts count {len(image_prompts)}")
|
| 63 |
+
text_parts = text.split(self.image_placeholder)
|
| 64 |
+
assert len(text_parts) == len(image_prompts) + 1
|
| 65 |
+
text = "".join([
|
| 66 |
+
text_parts[i] + image_prompts[i]
|
| 67 |
+
for i in range(len(image_prompts))
|
| 68 |
+
])
|
| 69 |
+
text += text_parts[-1]
|
| 70 |
+
|
| 71 |
+
return text
|
| 72 |
+
|
| 73 |
+
def preprocess_medias(self,
|
| 74 |
+
medias: list[dict]) -> tuple[list[dict], list[str]]:
|
| 75 |
+
"""Process media items and generate corresponding prompts.
|
| 76 |
+
|
| 77 |
+
Returns:
|
| 78 |
+
A tuple of (updated_medias, image_prompts).
|
| 79 |
+
"""
|
| 80 |
+
updated_medias = []
|
| 81 |
+
image_prompts = []
|
| 82 |
+
for media in medias:
|
| 83 |
+
if media['type'] == 'image':
|
| 84 |
+
updated_medias.append(media)
|
| 85 |
+
img = ensure_media_type(
|
| 86 |
+
media,
|
| 87 |
+
transparent_bg_config=self.media_processor.
|
| 88 |
+
_transparent_bg_config,
|
| 89 |
+
transparent_bg_fill_stage=self.media_processor.
|
| 90 |
+
_transparent_bg_fill_stage,
|
| 91 |
+
)['image']
|
| 92 |
+
w, h = img.size
|
| 93 |
+
image_prompts.append(
|
| 94 |
+
self.media_processor.make_image_prompt(w, h))
|
| 95 |
+
else:
|
| 96 |
+
raise ValueError(f"unsupported media type: {media['type']}")
|
| 97 |
+
return updated_medias, image_prompts
|
| 98 |
+
|
| 99 |
+
# ── Main entry points ──────────────────────────────────────────────
|
| 100 |
+
|
| 101 |
+
def __call__(self,
|
| 102 |
+
messages: list[dict] = None,
|
| 103 |
+
medias: list[dict] = None,
|
| 104 |
+
text: str = None,
|
| 105 |
+
return_tensors: str = "pt",
|
| 106 |
+
**kwargs) -> BatchFeature:
|
| 107 |
+
"""
|
| 108 |
+
Process multimodal inputs for Kimi-K3 model.
|
| 109 |
+
|
| 110 |
+
Args:
|
| 111 |
+
messages: List of message dicts with 'role' and 'content' fields.
|
| 112 |
+
If provided, medias and text will be extracted automatically.
|
| 113 |
+
medias: Pre-extracted list of media dicts.
|
| 114 |
+
text: Pre-formatted text string.
|
| 115 |
+
return_tensors: Format of returned tensors. Default: 'pt'.
|
| 116 |
+
**kwargs: Additional arguments passed to apply_chat_template.
|
| 117 |
+
|
| 118 |
+
Returns:
|
| 119 |
+
BatchFeature with fields: input_ids, attention_mask,
|
| 120 |
+
pixel_values, grid_thws.
|
| 121 |
+
"""
|
| 122 |
+
if messages is None and (medias is None or text is None):
|
| 123 |
+
raise ValueError(
|
| 124 |
+
"Provide either 'messages' or both 'medias' and 'text'")
|
| 125 |
+
|
| 126 |
+
if medias is not None and text is not None:
|
| 127 |
+
updated_medias, image_prompts = (self.preprocess_medias(medias))
|
| 128 |
+
preprocessed = self.media_processor.preprocess(
|
| 129 |
+
updated_medias, return_tensors=return_tensors)
|
| 130 |
+
text = self.update_raw_text(text, image_prompts)
|
| 131 |
+
text_inputs = self.tokenizer(text, return_tensors=return_tensors)
|
| 132 |
+
return BatchFeature(data={**text_inputs, **preprocessed.data})
|
| 133 |
+
|
| 134 |
+
if medias is None:
|
| 135 |
+
medias = self._extract_medias_from_messages(messages)
|
| 136 |
+
updated_medias, image_prompts = (self.preprocess_medias(medias))
|
| 137 |
+
preprocessed = self.media_processor.preprocess(
|
| 138 |
+
updated_medias, return_tensors=return_tensors)
|
| 139 |
+
|
| 140 |
+
if text is None:
|
| 141 |
+
text_inputs = self.tokenizer.apply_chat_template(
|
| 142 |
+
messages,
|
| 143 |
+
tokenize=True,
|
| 144 |
+
return_tensors=return_tensors,
|
| 145 |
+
return_dict=True,
|
| 146 |
+
image_prompts=image_prompts,
|
| 147 |
+
**kwargs)
|
| 148 |
+
return BatchFeature(data={**text_inputs, **preprocessed.data})
|
| 149 |
+
|
| 150 |
+
text = self.update_raw_text(text, image_prompts)
|
| 151 |
+
text_inputs = self.tokenizer(text, return_tensors=return_tensors)
|
| 152 |
+
return BatchFeature(data={**text_inputs, **preprocessed.data})
|
| 153 |
+
|
| 154 |
+
@staticmethod
|
| 155 |
+
def _extract_medias_from_messages(messages: list[dict]) -> list[dict]:
|
| 156 |
+
"""Extract media items from messages in a single pass."""
|
| 157 |
+
medias = []
|
| 158 |
+
for msg in messages:
|
| 159 |
+
if msg['role'] != 'user' or not msg.get('content'):
|
| 160 |
+
continue
|
| 161 |
+
|
| 162 |
+
for content_part in msg['content']:
|
| 163 |
+
if not isinstance(content_part, dict):
|
| 164 |
+
continue
|
| 165 |
+
|
| 166 |
+
content_type = content_part.get('type')
|
| 167 |
+
if content_type in ['image_url', 'image']:
|
| 168 |
+
image_data = content_part.get(content_type)
|
| 169 |
+
assert image_data is not None, f"image data is missing for content part: {content_part}"
|
| 170 |
+
medias.append({
|
| 171 |
+
'type': 'image',
|
| 172 |
+
'image': image_data,
|
| 173 |
+
})
|
| 174 |
+
return medias
|
| 175 |
+
|
| 176 |
+
def apply_chat_template(self, messages, **kwargs):
|
| 177 |
+
return self.tokenizer.apply_chat_template(messages, **kwargs)
|
| 178 |
+
|
| 179 |
+
def batch_decode(self, *args, **kwargs):
|
| 180 |
+
return self.tokenizer.batch_decode(*args, **kwargs)
|
| 181 |
+
|
| 182 |
+
def decode(self, *args, **kwargs):
|
| 183 |
+
return self.tokenizer.decode(*args, **kwargs)
|
| 184 |
+
|
| 185 |
+
@property
|
| 186 |
+
def model_input_names(self):
|
| 187 |
+
return ['input_ids', 'attention_mask', 'pixel_values', 'grid_thws']
|
kimi_k3_vision_processing.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 10 |
+
from transformers.image_processing_utils import (BaseImageProcessor,
|
| 11 |
+
BatchFeature)
|
| 12 |
+
from transformers.utils import TensorType
|
| 13 |
+
|
| 14 |
+
from .media_utils import (MediaInput, TransparentBgConfig, _to_tensor,
|
| 15 |
+
ensure_media_type, image_to_np, navit_patchify,
|
| 16 |
+
navit_resize_image, normalize)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class KimiK3VisionProcessor(BaseImageProcessor):
|
| 20 |
+
model_type = "kimi_k3"
|
| 21 |
+
|
| 22 |
+
def __init__(
|
| 23 |
+
self,
|
| 24 |
+
media_proc_cfg: dict,
|
| 25 |
+
**kwargs,
|
| 26 |
+
):
|
| 27 |
+
super().__init__(**kwargs)
|
| 28 |
+
self.media_proc_cfg = media_proc_cfg
|
| 29 |
+
|
| 30 |
+
@property
|
| 31 |
+
def _transparent_bg_config(self) -> Optional[TransparentBgConfig]:
|
| 32 |
+
cfg = self.media_proc_cfg.get("transparent_bg_config")
|
| 33 |
+
if cfg is None:
|
| 34 |
+
return None
|
| 35 |
+
if isinstance(cfg, TransparentBgConfig):
|
| 36 |
+
return cfg
|
| 37 |
+
return TransparentBgConfig(**cfg)
|
| 38 |
+
|
| 39 |
+
@property
|
| 40 |
+
def _transparent_bg_fill_stage(self) -> str:
|
| 41 |
+
return self.media_proc_cfg.get("transparent_bg_fill_stage",
|
| 42 |
+
"before_resize")
|
| 43 |
+
|
| 44 |
+
def media_tokens_calculator(self, media: MediaInput):
|
| 45 |
+
media = ensure_media_type(
|
| 46 |
+
media,
|
| 47 |
+
transparent_bg_config=self._transparent_bg_config,
|
| 48 |
+
transparent_bg_fill_stage=self._transparent_bg_fill_stage,
|
| 49 |
+
)
|
| 50 |
+
ret = self.get_resize_config(media)
|
| 51 |
+
return ret['num_tokens']
|
| 52 |
+
|
| 53 |
+
@classmethod
|
| 54 |
+
def make_image_prompt(cls, width: int, height: int) -> str:
|
| 55 |
+
"""Build the K3 image placeholder with resolution info."""
|
| 56 |
+
return (f"<|media_begin|>image {width}x{height}"
|
| 57 |
+
f"<|media_content|><|media_pad|><|media_end|>")
|
| 58 |
+
|
| 59 |
+
def get_resize_config(self, media_input: MediaInput) -> dict:
|
| 60 |
+
if media_input['type'] == 'image':
|
| 61 |
+
w, h = media_input['image'].size
|
| 62 |
+
ret = navit_resize_image(
|
| 63 |
+
w, h, self.media_proc_cfg['patch_size'],
|
| 64 |
+
self.media_proc_cfg['merge_kernel_size'],
|
| 65 |
+
self.media_proc_cfg['in_patch_limit'],
|
| 66 |
+
self.media_proc_cfg['patch_limit_on_one_side'],
|
| 67 |
+
self.media_proc_cfg['fixed_output_tokens'])
|
| 68 |
+
return ret
|
| 69 |
+
else:
|
| 70 |
+
raise ValueError("Unsupported type: {}".format(
|
| 71 |
+
media_input['type']))
|
| 72 |
+
|
| 73 |
+
def resize_image(self, image: Image.Image, new_width: int, new_height: int,
|
| 74 |
+
pad_width: int, pad_height: int) -> np.ndarray:
|
| 75 |
+
image_np = image_to_np(
|
| 76 |
+
image,
|
| 77 |
+
(new_width, new_height),
|
| 78 |
+
"resize",
|
| 79 |
+
transparent_bg_config=self._transparent_bg_config,
|
| 80 |
+
transparent_bg_fill_stage=self._transparent_bg_fill_stage,
|
| 81 |
+
)
|
| 82 |
+
image_np = np.pad(
|
| 83 |
+
image_np,
|
| 84 |
+
((0, pad_height), (0, pad_width), (0, 0)),
|
| 85 |
+
mode="constant",
|
| 86 |
+
constant_values=0,
|
| 87 |
+
)
|
| 88 |
+
return image_np
|
| 89 |
+
|
| 90 |
+
def preprocess(
|
| 91 |
+
self,
|
| 92 |
+
medias: list[MediaInput],
|
| 93 |
+
return_tensors: Optional[Union[str, TensorType]] = None,
|
| 94 |
+
) -> BatchFeature:
|
| 95 |
+
"""
|
| 96 |
+
Preprocess a atom vision input (images) into model-ready tensors.
|
| 97 |
+
|
| 98 |
+
Args:
|
| 99 |
+
medias: List of MediaInput.
|
| 100 |
+
return_tensors: Desired output format ('pt', 'np', 'tf', or None).
|
| 101 |
+
|
| 102 |
+
Returns:
|
| 103 |
+
BatchFeature containing 'pixel_values' and 'grid_thws' tensors.
|
| 104 |
+
"""
|
| 105 |
+
if not isinstance(medias, list):
|
| 106 |
+
medias = [medias]
|
| 107 |
+
if medias:
|
| 108 |
+
pixel_values = []
|
| 109 |
+
for item in medias:
|
| 110 |
+
item = ensure_media_type(
|
| 111 |
+
item,
|
| 112 |
+
transparent_bg_config=self._transparent_bg_config,
|
| 113 |
+
transparent_bg_fill_stage=self._transparent_bg_fill_stage,
|
| 114 |
+
)
|
| 115 |
+
resize_config = self.get_resize_config(item)
|
| 116 |
+
new_width, new_height, pad_width, pad_height = resize_config[
|
| 117 |
+
'new_width'], resize_config['new_height'], resize_config[
|
| 118 |
+
'pad_width'], resize_config['pad_height']
|
| 119 |
+
if item['type'] == 'image':
|
| 120 |
+
image = item['image']
|
| 121 |
+
image_np = self.resize_image(image, new_width, new_height,
|
| 122 |
+
pad_width, pad_height)
|
| 123 |
+
pixel_values.append(np.expand_dims(image_np, axis=0))
|
| 124 |
+
else:
|
| 125 |
+
raise ValueError("Unsupported type: {}".format(
|
| 126 |
+
item['type']))
|
| 127 |
+
normalized_pixel_values = []
|
| 128 |
+
image_std_inv = 1.0 / np.array(self.media_proc_cfg['image_std'])
|
| 129 |
+
image_mean = np.array(self.media_proc_cfg['image_mean'])
|
| 130 |
+
for pixels in pixel_values:
|
| 131 |
+
pixels = normalize(pixels, image_mean, image_std_inv)
|
| 132 |
+
pixels_and_thw = navit_patchify(
|
| 133 |
+
pixels,
|
| 134 |
+
self.media_proc_cfg['patch_size'],
|
| 135 |
+
)
|
| 136 |
+
normalized_pixel_values.append(pixels_and_thw)
|
| 137 |
+
|
| 138 |
+
pixel_values = torch.cat([
|
| 139 |
+
_to_tensor(pixel_value['pixel_values'])
|
| 140 |
+
for pixel_value in normalized_pixel_values
|
| 141 |
+
])
|
| 142 |
+
grid_thws = torch.cat([
|
| 143 |
+
_to_tensor(pixel_value['grid_thw'],
|
| 144 |
+
dtype=torch.int64).unsqueeze(0)
|
| 145 |
+
for pixel_value in normalized_pixel_values
|
| 146 |
+
])
|
| 147 |
+
|
| 148 |
+
data = {
|
| 149 |
+
'pixel_values': pixel_values,
|
| 150 |
+
'grid_thws': grid_thws,
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
else:
|
| 154 |
+
data = {}
|
| 155 |
+
|
| 156 |
+
return BatchFeature(data=data, tensor_type=return_tensors)
|
| 157 |
+
|
| 158 |
+
def __repr__(self):
|
| 159 |
+
return f"KimiK3VisionProcessor(media_proc_cfg={self.media_proc_cfg})"
|
| 160 |
+
|
| 161 |
+
def to_dict(self) -> Dict[str, Any]:
|
| 162 |
+
output = super().to_dict()
|
| 163 |
+
output["media_proc_cfg"] = self.media_proc_cfg
|
| 164 |
+
if "media_processor" in output:
|
| 165 |
+
del output["media_processor"]
|
| 166 |
+
return output
|
| 167 |
+
|
| 168 |
+
@classmethod
|
| 169 |
+
def from_dict(cls, config_dict: Dict[str, Any], **kwargs):
|
| 170 |
+
config = config_dict.copy()
|
| 171 |
+
media_proc_cfg = config.pop("media_proc_cfg", {})
|
| 172 |
+
return cls(media_proc_cfg=media_proc_cfg, **config, **kwargs)
|
| 173 |
+
|
| 174 |
+
def to_json_string(self):
|
| 175 |
+
dictionary = self.to_dict()
|
| 176 |
+
for key, value in dictionary.items():
|
| 177 |
+
if hasattr(value, 'tolist'):
|
| 178 |
+
dictionary[key] = value.tolist()
|
| 179 |
+
return json.dumps(dictionary, indent=2, sort_keys=True) + "\n"
|
media_utils.py
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import base64
|
| 2 |
+
import functools
|
| 3 |
+
import io
|
| 4 |
+
import math
|
| 5 |
+
from dataclasses import dataclass
|
| 6 |
+
from typing import Literal, TypedDict
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
from PIL import Image
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class ImageInput(TypedDict):
|
| 13 |
+
type: Literal['image']
|
| 14 |
+
image: Image.Image
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
MediaInput = ImageInput
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@dataclass
|
| 21 |
+
class TransparentBgConfig:
|
| 22 |
+
"""The config of the transparent background."""
|
| 23 |
+
|
| 24 |
+
pattern: Literal["white", "black", "gray", "chessboard"] = "black"
|
| 25 |
+
"""The pattern of the transparent background."""
|
| 26 |
+
|
| 27 |
+
chessboard_square_size: int = 16
|
| 28 |
+
"""The size of the squares in the chessboard background."""
|
| 29 |
+
|
| 30 |
+
chessboard_square_on_top_left: bool = True
|
| 31 |
+
"""Whether to start the chessboard with a white square on the top left."""
|
| 32 |
+
|
| 33 |
+
chessboard_white_value: int = 255
|
| 34 |
+
"""The value of the white pixels in the background."""
|
| 35 |
+
|
| 36 |
+
chessboard_gray_value: int = 200
|
| 37 |
+
"""The value of the gray pixels in the background."""
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@functools.lru_cache(maxsize=256)
|
| 41 |
+
def _create_chessboard_background(
|
| 42 |
+
height: int,
|
| 43 |
+
width: int,
|
| 44 |
+
square_size: int,
|
| 45 |
+
square_on_top_left: bool,
|
| 46 |
+
white_value: int,
|
| 47 |
+
gray_value: int,
|
| 48 |
+
) -> np.ndarray:
|
| 49 |
+
"""Create a chessboard background."""
|
| 50 |
+
bg = np.ones((height, width, 3), dtype=np.uint8) * white_value
|
| 51 |
+
for y in range(0, height, square_size):
|
| 52 |
+
for x in range(0, width, square_size):
|
| 53 |
+
if (y // square_size + x // square_size) % 2 == (
|
| 54 |
+
1 if square_on_top_left else 0):
|
| 55 |
+
bg[y:y + square_size, x:x + square_size] = gray_value
|
| 56 |
+
return bg
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def fill_transparent_bg_with(
|
| 60 |
+
image: Image.Image,
|
| 61 |
+
transparent_bg_config: TransparentBgConfig | None = None,
|
| 62 |
+
) -> Image.Image:
|
| 63 |
+
"""Composite a (possibly) transparent image onto a configured background.
|
| 64 |
+
|
| 65 |
+
When ``transparent_bg_config`` is ``None``, the image is simply converted
|
| 66 |
+
to RGB (preserving the historical behavior). Otherwise the alpha channel
|
| 67 |
+
is alpha-composited over a background generated according to the config.
|
| 68 |
+
"""
|
| 69 |
+
if transparent_bg_config is None:
|
| 70 |
+
return image.convert("RGB")
|
| 71 |
+
|
| 72 |
+
if image.mode == "RGB":
|
| 73 |
+
return image
|
| 74 |
+
|
| 75 |
+
has_alpha = "A" in image.getbands() or "transparency" in image.info
|
| 76 |
+
if not has_alpha:
|
| 77 |
+
return image.convert("RGB")
|
| 78 |
+
|
| 79 |
+
img = np.array(image.convert("RGBA"))
|
| 80 |
+
height, width = img.shape[:2]
|
| 81 |
+
bg_pattern = transparent_bg_config.pattern
|
| 82 |
+
if bg_pattern == "white":
|
| 83 |
+
bg = np.full((height, width, 3), 255, dtype=np.uint8)
|
| 84 |
+
elif bg_pattern == "black":
|
| 85 |
+
bg = np.zeros((height, width, 3), dtype=np.uint8)
|
| 86 |
+
elif bg_pattern == "gray":
|
| 87 |
+
bg = np.full((height, width, 3), 128, dtype=np.uint8)
|
| 88 |
+
elif bg_pattern == "chessboard":
|
| 89 |
+
bg = _create_chessboard_background(
|
| 90 |
+
height,
|
| 91 |
+
width,
|
| 92 |
+
transparent_bg_config.chessboard_square_size,
|
| 93 |
+
transparent_bg_config.chessboard_square_on_top_left,
|
| 94 |
+
transparent_bg_config.chessboard_white_value,
|
| 95 |
+
transparent_bg_config.chessboard_gray_value,
|
| 96 |
+
)
|
| 97 |
+
else:
|
| 98 |
+
raise ValueError(f"Invalid background pattern: {bg_pattern}")
|
| 99 |
+
|
| 100 |
+
alpha = img[:, :, 3]
|
| 101 |
+
img_rgb = img[:, :, :3]
|
| 102 |
+
alpha_normalized = alpha.astype(np.float32) / 255.0
|
| 103 |
+
alpha_3d = np.stack([alpha_normalized] * 3, axis=2)
|
| 104 |
+
result = alpha_3d * img_rgb + (1 - alpha_3d) * bg
|
| 105 |
+
result = result.astype(np.uint8)
|
| 106 |
+
return Image.fromarray(result)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def navit_resize_image(
|
| 110 |
+
width: int,
|
| 111 |
+
height: int,
|
| 112 |
+
patch_size: int,
|
| 113 |
+
merge_kernel_size: int,
|
| 114 |
+
in_patch_limit: int,
|
| 115 |
+
patch_limit_on_one_side: int,
|
| 116 |
+
fixed_output_tokens: int | None,
|
| 117 |
+
):
|
| 118 |
+
# Apply the patch limits.
|
| 119 |
+
s1 = math.sqrt(
|
| 120 |
+
in_patch_limit /
|
| 121 |
+
(max(1.0, width // patch_size) * max(1.0, height // patch_size)))
|
| 122 |
+
s2 = patch_limit_on_one_side * patch_size / width
|
| 123 |
+
s3 = patch_limit_on_one_side * patch_size / height
|
| 124 |
+
scale = min(1.0, s1, s2, s3)
|
| 125 |
+
new_w, new_h = max(1, int(width * scale)), max(1, int(height * scale))
|
| 126 |
+
new_w = min(new_w, patch_limit_on_one_side * patch_size)
|
| 127 |
+
new_h = min(new_h, patch_limit_on_one_side * patch_size)
|
| 128 |
+
|
| 129 |
+
# Calculate the padding to make the height and width divisible by the merge kernel size and patch size.
|
| 130 |
+
factor = merge_kernel_size * patch_size
|
| 131 |
+
|
| 132 |
+
pad_height = (factor - new_h % factor) % factor
|
| 133 |
+
pad_width = (factor - new_w % factor) % factor
|
| 134 |
+
|
| 135 |
+
if fixed_output_tokens is not None:
|
| 136 |
+
num_tokens = fixed_output_tokens
|
| 137 |
+
else:
|
| 138 |
+
# Calculate new dimensions after padding and patching
|
| 139 |
+
token_height = (new_h + pad_height) // factor
|
| 140 |
+
token_width = (new_w + pad_width) // factor
|
| 141 |
+
|
| 142 |
+
assert token_height * merge_kernel_size <= patch_limit_on_one_side, (
|
| 143 |
+
f"token_height {token_height} * merge_kernel_size {merge_kernel_size} > patch_limit_on_one_side {patch_limit_on_one_side}"
|
| 144 |
+
)
|
| 145 |
+
assert token_width * merge_kernel_size <= patch_limit_on_one_side, (
|
| 146 |
+
f"token_width {token_width} * merge_kernel_size {merge_kernel_size} > patch_limit_on_one_side {patch_limit_on_one_side}"
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
num_tokens = token_height * token_width
|
| 150 |
+
return {
|
| 151 |
+
"num_tokens": num_tokens,
|
| 152 |
+
"new_width": new_w,
|
| 153 |
+
"new_height": new_h,
|
| 154 |
+
"pad_width": pad_width,
|
| 155 |
+
"pad_height": pad_height,
|
| 156 |
+
"sampled_nframes": 1,
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _to_pil(
|
| 161 |
+
data: str | bytes | Image.Image,
|
| 162 |
+
transparent_bg_config: TransparentBgConfig | None = None,
|
| 163 |
+
to_rgb: bool = True,
|
| 164 |
+
) -> Image.Image:
|
| 165 |
+
"""Load an image and (optionally) composite its transparent background.
|
| 166 |
+
|
| 167 |
+
Args:
|
| 168 |
+
data: A PIL Image, a base64 ``data:`` URL, a file path, or raw bytes.
|
| 169 |
+
transparent_bg_config: The config used to fill the transparent
|
| 170 |
+
background. ``None`` keeps the historical behavior of converting
|
| 171 |
+
to RGB without compositing.
|
| 172 |
+
to_rgb: If ``False`` the image is returned as-is (the
|
| 173 |
+
``transparent_bg_config`` is ignored). The caller is then
|
| 174 |
+
expected to call :func:`fill_transparent_bg_with` later — e.g.
|
| 175 |
+
after a resize.
|
| 176 |
+
"""
|
| 177 |
+
if isinstance(data, Image.Image):
|
| 178 |
+
image = data
|
| 179 |
+
elif isinstance(data, str):
|
| 180 |
+
if data.startswith("data:"):
|
| 181 |
+
raw_base64 = data.split(",")[1]
|
| 182 |
+
image = Image.open(io.BytesIO(base64.b64decode(raw_base64)))
|
| 183 |
+
else:
|
| 184 |
+
image = Image.open(data)
|
| 185 |
+
elif isinstance(data, bytes):
|
| 186 |
+
image = Image.open(io.BytesIO(data))
|
| 187 |
+
else:
|
| 188 |
+
raise ValueError(f"Unsupported data type: {type(data)}")
|
| 189 |
+
|
| 190 |
+
if not to_rgb:
|
| 191 |
+
return image
|
| 192 |
+
|
| 193 |
+
return fill_transparent_bg_with(image, transparent_bg_config)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def ensure_media_type(
|
| 197 |
+
media: MediaInput,
|
| 198 |
+
transparent_bg_config: TransparentBgConfig | None = None,
|
| 199 |
+
transparent_bg_fill_stage: Literal["before_resize",
|
| 200 |
+
"after_resize"] = "before_resize",
|
| 201 |
+
) -> MediaInput:
|
| 202 |
+
if media['type'] == 'image':
|
| 203 |
+
media['image'] = _to_pil(
|
| 204 |
+
media['image'],
|
| 205 |
+
transparent_bg_config=transparent_bg_config,
|
| 206 |
+
to_rgb=transparent_bg_fill_stage == "before_resize",
|
| 207 |
+
)
|
| 208 |
+
return media
|
| 209 |
+
else:
|
| 210 |
+
raise ValueError(f"Unsupported media type: {media['type']}")
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def image_to_np(
|
| 214 |
+
image: Image.Image,
|
| 215 |
+
resize_to: tuple[int, int] | None = None,
|
| 216 |
+
mode: str = "resize",
|
| 217 |
+
raise_error_for_ill_resize: bool = True,
|
| 218 |
+
transparent_bg_config: TransparentBgConfig | None = None,
|
| 219 |
+
transparent_bg_fill_stage: Literal["before_resize",
|
| 220 |
+
"after_resize"] = "before_resize",
|
| 221 |
+
) -> np.ndarray:
|
| 222 |
+
"""Convert an image to a numpy array.
|
| 223 |
+
|
| 224 |
+
Args:
|
| 225 |
+
content: The image to convert.
|
| 226 |
+
resize_to: The size to resize the image to.
|
| 227 |
+
mode: The mode to resize the image to.
|
| 228 |
+
raise_error_for_ill_resize: Whether to raise an error for ill-sized resize.
|
| 229 |
+
transparent_bg_config: The config of the transparent background. Only
|
| 230 |
+
used when ``transparent_bg_fill_stage == "after_resize"`` (the
|
| 231 |
+
caller is responsible for filling before resize otherwise).
|
| 232 |
+
transparent_bg_fill_stage: When to composite the transparent
|
| 233 |
+
background — before or after the resize step.
|
| 234 |
+
|
| 235 |
+
Returns:
|
| 236 |
+
A numpy array.
|
| 237 |
+
"""
|
| 238 |
+
assert isinstance(image, Image.Image), "image must be a PIL Image"
|
| 239 |
+
if resize_to is not None:
|
| 240 |
+
if mode == "resize":
|
| 241 |
+
image = image.resize(resize_to, resample=Image.Resampling.BICUBIC)
|
| 242 |
+
if transparent_bg_fill_stage == "after_resize":
|
| 243 |
+
image = fill_transparent_bg_with(image, transparent_bg_config)
|
| 244 |
+
|
| 245 |
+
elif mode == "rescale_and_pad_to_center":
|
| 246 |
+
scale = min(resize_to[0] / image.width,
|
| 247 |
+
resize_to[1] / image.height, 1.0)
|
| 248 |
+
new_width = round(image.width * scale)
|
| 249 |
+
new_height = round(image.height * scale)
|
| 250 |
+
if new_width == 0 or new_height == 0:
|
| 251 |
+
if raise_error_for_ill_resize:
|
| 252 |
+
raise ValueError(
|
| 253 |
+
f"Invalid resize to: {resize_to}, from image size: {image.size}"
|
| 254 |
+
)
|
| 255 |
+
else:
|
| 256 |
+
return np.zeros((resize_to[1], resize_to[0], 3),
|
| 257 |
+
dtype=np.uint8)
|
| 258 |
+
|
| 259 |
+
image = image.resize((new_width, new_height),
|
| 260 |
+
resample=Image.Resampling.BICUBIC)
|
| 261 |
+
if transparent_bg_fill_stage == "after_resize":
|
| 262 |
+
image = fill_transparent_bg_with(image, transparent_bg_config)
|
| 263 |
+
padding_left = (resize_to[0] - new_width) // 2
|
| 264 |
+
padding_right = resize_to[0] - new_width - padding_left
|
| 265 |
+
padding_top = (resize_to[1] - new_height) // 2
|
| 266 |
+
padding_bottom = resize_to[1] - new_height - padding_top
|
| 267 |
+
image = np.asarray(image)
|
| 268 |
+
image = np.pad(
|
| 269 |
+
image,
|
| 270 |
+
((padding_top, padding_bottom), (padding_left, padding_right),
|
| 271 |
+
(0, 0)),
|
| 272 |
+
mode="constant",
|
| 273 |
+
constant_values=0,
|
| 274 |
+
)
|
| 275 |
+
assert image.shape == (resize_to[1], resize_to[0], 3)
|
| 276 |
+
|
| 277 |
+
elif mode == "rescale_and_pad_to_rightbottom":
|
| 278 |
+
scale = min(resize_to[0] / image.width,
|
| 279 |
+
resize_to[1] / image.height, 1.0)
|
| 280 |
+
new_width = round(image.width * scale)
|
| 281 |
+
new_height = round(image.height * scale)
|
| 282 |
+
if new_width == 0 or new_height == 0:
|
| 283 |
+
if raise_error_for_ill_resize:
|
| 284 |
+
raise ValueError(
|
| 285 |
+
f"Invalid resize to: {resize_to}, from image size: {image.size}"
|
| 286 |
+
)
|
| 287 |
+
else:
|
| 288 |
+
return np.zeros((resize_to[1], resize_to[0], 3),
|
| 289 |
+
dtype=np.uint8)
|
| 290 |
+
|
| 291 |
+
image = image.resize((new_width, new_height),
|
| 292 |
+
resample=Image.Resampling.BICUBIC)
|
| 293 |
+
if transparent_bg_fill_stage == "after_resize":
|
| 294 |
+
image = fill_transparent_bg_with(image, transparent_bg_config)
|
| 295 |
+
padding_right = resize_to[0] - new_width
|
| 296 |
+
padding_bottom = resize_to[1] - new_height
|
| 297 |
+
image = np.asarray(image)
|
| 298 |
+
image = np.pad(
|
| 299 |
+
image,
|
| 300 |
+
((0, padding_bottom), (0, padding_right), (0, 0)),
|
| 301 |
+
mode="constant",
|
| 302 |
+
constant_values=0,
|
| 303 |
+
)
|
| 304 |
+
assert image.shape == (resize_to[1], resize_to[0], 3)
|
| 305 |
+
|
| 306 |
+
else:
|
| 307 |
+
raise ValueError(f"Invalid mode: {mode}")
|
| 308 |
+
|
| 309 |
+
if isinstance(image, Image.Image):
|
| 310 |
+
return np.asarray(image)
|
| 311 |
+
else:
|
| 312 |
+
return image
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
def navit_patchify(pixel_values: np.ndarray,
|
| 316 |
+
patch_size: int) -> dict[str, np.ndarray]:
|
| 317 |
+
"""Reshape the pixel values to a navit shape.
|
| 318 |
+
|
| 319 |
+
Args:
|
| 320 |
+
pixel_values: np.ndarray, shape (t, h, w, c)
|
| 321 |
+
patch_size: int
|
| 322 |
+
|
| 323 |
+
Returns:
|
| 324 |
+
dict[str, np.ndarray]
|
| 325 |
+
- patches: np.ndarray, shape (t * h//patch_size * w//patch_size, c, patch_size, patch_size)
|
| 326 |
+
- grid_thw: np.ndarray, (t, h//patch_size, w//patch_size)
|
| 327 |
+
"""
|
| 328 |
+
T, H, W, C = pixel_values.shape
|
| 329 |
+
assert C == 3, "pixel_values must have 3 channels"
|
| 330 |
+
|
| 331 |
+
patches = pixel_values.reshape(T, H // patch_size, patch_size,
|
| 332 |
+
W // patch_size, patch_size, C)
|
| 333 |
+
# (T, H//patch_size, W//patch_size, C, patch_size, patch_size)
|
| 334 |
+
patches = patches.transpose(0, 1, 3, 5, 2, 4)
|
| 335 |
+
patches = patches.reshape(-1, C, patch_size, patch_size)
|
| 336 |
+
grid_thw = np.array([T, H // patch_size, W // patch_size])
|
| 337 |
+
return {"pixel_values": patches, "grid_thw": grid_thw}
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
def normalize(x: np.ndarray,
|
| 341 |
+
mean,
|
| 342 |
+
std_inv,
|
| 343 |
+
pixels_dtype: np.dtype = np.float32) -> np.ndarray:
|
| 344 |
+
"""Normalize the image.
|
| 345 |
+
|
| 346 |
+
Args:
|
| 347 |
+
x: The image to normalize. The shape is (..., 3). The dtype is uint8. The range is [0, 255].
|
| 348 |
+
mean: The mean of the image.
|
| 349 |
+
std_inv: The inverse of the std of the image.
|
| 350 |
+
pixels_dtype: The dtype of the image.
|
| 351 |
+
Returns:
|
| 352 |
+
The normalized image. The shape is (..., 3). The dtype is determined by the pixels_dtype.
|
| 353 |
+
"""
|
| 354 |
+
x = (x / 255.0).astype(pixels_dtype)
|
| 355 |
+
x -= mean
|
| 356 |
+
x *= std_inv
|
| 357 |
+
return x
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
def _to_tensor(data, **kwargs):
|
| 361 |
+
import torch
|
| 362 |
+
|
| 363 |
+
if isinstance(data, np.ndarray):
|
| 364 |
+
return torch.from_numpy(data).to(**kwargs)
|
| 365 |
+
elif isinstance(data, torch.Tensor):
|
| 366 |
+
return data.to(**kwargs)
|
| 367 |
+
elif isinstance(data, list):
|
| 368 |
+
return [_to_tensor(item, **kwargs) for item in data]
|
| 369 |
+
elif isinstance(data, tuple):
|
| 370 |
+
return tuple(_to_tensor(item, **kwargs) for item in data)
|
| 371 |
+
elif isinstance(data, dict):
|
| 372 |
+
return {k: _to_tensor(v, **kwargs) for k, v in data.items()}
|
| 373 |
+
elif data is None:
|
| 374 |
+
return None
|
| 375 |
+
else:
|
| 376 |
+
raise ValueError(f"Unsupported data type: {type(data)}")
|
model-00001-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:975584c00f85a95fce8ae0f840af8cef69c2ef4db00d34cab3e2cbdfc60f6e51
|
| 3 |
+
size 2341216112
|
model-00002-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cfe50df5e9fdee2de430ea4bf9ad3cdd63169ac0029dd75d8818036b4578aef2
|
| 3 |
+
size 3151058336
|
model-00003-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ac64941b38413878b41ecebc3acb9c6a718a213fa634cf18f0ed879b7ece01aa
|
| 3 |
+
size 3153759128
|
model-00004-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a22f9a29d2d56c78d6f755f217636bb1333c58f871046e63e8616ed846b13327
|
| 3 |
+
size 3153759056
|
model-00005-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8baa9080692d3d44334538bca18dea6f52c320a1341b235b22b1d1edad7e1cb7
|
| 3 |
+
size 3153759152
|
model-00006-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d80191fa2c6cf2454322ee8630116f96c6b567adb0bb769cc6172892c99c94c1
|
| 3 |
+
size 679958376
|
model-00007-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d6e103684ff6e4d1178ded2b71dfdc20312861e4685e63f9acc16cd0e6cd6719
|
| 3 |
+
size 3151058336
|
model-00008-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8d3f7cfcf3c9f00eeb0d5dc193074e2a610a4b569b0ae46bce3a54bd3e88524b
|
| 3 |
+
size 3153759128
|
model-00009-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e8522c1de1948c2ce29649b53a0951dc675d56d31c0f681b7773f37ceaf960e0
|
| 3 |
+
size 3153759056
|
model-00010-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:99bf54e2ecc22b1b41e0fea66381dfdc8c0d02dcd596f54ba80dd15f10373574
|
| 3 |
+
size 3153759152
|
model-00011-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ffd9ebe10ba0a3f4562e0d638b066e7a10e7d173216b58d4947540bb60f0ae6a
|
| 3 |
+
size 679958376
|
model-00012-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8413527f55d82fcf7e30bb177da204f21ecb1b689f839f97d5c13c820cd434b3
|
| 3 |
+
size 3152622456
|
model-00013-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f29cf052b91e36a8e8bdac32070133f6f7e5df0a00f4b7312b6650b3e27bcb4f
|
| 3 |
+
size 3153759152
|
model-00014-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1b5861fedd81471f61f839982d7495295d236d9d94a5ad4d4642737d5af2ad38
|
| 3 |
+
size 3153759048
|
model-00015-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f71f4313344cb85587c8a9cd37215337335ce573b1c5aa0ff43fc828d605119e
|
| 3 |
+
size 3153759144
|
model-00016-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:801545ceacf2ce9d5ff64625fe2492bdd6e0036208698865731b60ecfb6ad094
|
| 3 |
+
size 254984256
|
model-00017-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:081f9c751f571001731b035fe48c23a402f8325307baa6f6b6957d9ff11cd062
|
| 3 |
+
size 3151755048
|
model-00018-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:22c53dc65484ccb86fed3a5521143b80a0560663ef493576f2920890c800c0d4
|
| 3 |
+
size 3152911016
|
model-00019-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:030b02bdfc6dd1746eb60ae1e63557154b979ed00f316f558869c672f91785d9
|
| 3 |
+
size 3152910944
|
model-00020-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:368ed37924eee1914a33ab16e36fb4785e13a7bcf939decae5eb2f5627cafeb7
|
| 3 |
+
size 3152911024
|
model-00021-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9fb5f522482fe0a2aa619e41f0db09420b001f02bdc106d9bd6dc9e72c1c7861
|
| 3 |
+
size 219369792
|
model-00022-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9dcf4930e2d1e3c3ab8a082f2cdcff42c9f9d99a341173a01ab030821de8aa3f
|
| 3 |
+
size 3151755048
|
model-00023-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d87a41a0cce02553fce05cc1a2c32c9cdfccd5f949885c59deecaedd0d889798
|
| 3 |
+
size 3152911016
|
model-00024-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:accf303ca172e242ff7ede846f676cf9ae7319c50595319bda56146c29efd6d4
|
| 3 |
+
size 3152910944
|
model-00025-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:77b73a697c99923a2c283c9866c73baa461340fa60a01a87374353b13cc57d58
|
| 3 |
+
size 3152911024
|
model-00026-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:690f46759192f6fe514bc611f5a81622454a7a405721cbf21ee92ee6a3670ae7
|
| 3 |
+
size 219369792
|
model-00027-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:af62e96a0d7a2ba6830eacf30c2bc8a336c70aa8123e83fc9c02f516fbc53ddd
|
| 3 |
+
size 3151755048
|
model-00028-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:84227790656ceb92b4234d375b143017015e9452e9b121f667348e1e8c57bf4c
|
| 3 |
+
size 3152911016
|
model-00029-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d556f70e73be466be23ba2dea39078769849bc4141bb5f75b40a455e8a728c8f
|
| 3 |
+
size 3152910944
|
model-00030-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8d6a91dfe9449c958061caf84d16e19985710b7f64785fa1ef3cb80a106339cf
|
| 3 |
+
size 3152911024
|
model-00031-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7bf393480ddc8049b4b0ac72a10e600f6a54d13c20ff29a5e2f52eb7ca882ca4
|
| 3 |
+
size 219369792
|
model-00032-of-00341.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0ffe7802a46e53fcf9e13a7993f1d955666ea9c37dc34a2b0f47f6d8d0aafe6a
|
| 3 |
+
size 3154180768
|