--- quantized_by: ubergarm pipeline_tag: text-generation base_model: moonshotai/Kimi-K2-Instruct license: other license_name: modified-mit license_link: https://huggingface.co/moonshotai/Kimi-K2-Instruct/raw/main/LICENSE base_model_relation: quantized tags: - mla - imatrix - conversational - ik_llama.cpp --- ## `ik_llama.cpp` imatrix Quantizations of moonshotai/Kimi-K2-Instruct This quant collection **REQUIRES** [ik_llama.cpp](https://github.com/ikawrakow/ik_llama.cpp/) fork to support the ik's latest SOTA quants and optimizations! Do **not** download these big files and expect them to run on mainline vanilla llama.cpp, ollama, LM Studio, KoboldCpp, etc! *NOTE* `ik_llama.cpp` can also run your existing GGUFs from bartowski, unsloth, mradermacher, etc if you want to try it out before downloading my quants. Some of ik's new quants are supported with [Nexesenex/croco.cpp](https://github.com/Nexesenex/croco.cpp) fork of KoboldCPP. These quants provide best in class perplexity for the given memory footprint. ## Big Thanks Shout out to Wendell and the **Level1Techs** crew, the community [Forums](https://forum.level1techs.com/t/deepseek-deep-dive-r1-at-home/225826), [YouTube Channel](https://www.youtube.com/@Level1Techs)! **BIG thanks** for providing **BIG hardware** expertise and access to run these experiments and make these great quants available to the community!!! Also thanks to all the folks in the quanting and inferencing community on [BeaverAI Club Discord](https://huggingface.co/BeaverAI) and on [r/LocalLLaMA](https://www.reddit.com/r/LocalLLaMA/) for tips and tricks helping each other run, test, and benchmark all the fun new models! ## *UPDATED RECIPES* Updated new better lower perplexity recipes and worlds smallest Kimi-K2-Instruct-smol-IQ1_KT at 219.375 GIB (1.835) BPW. Please ask any questions in [this discussion here](https://huggingface.co/ubergarm/Kimi-K2-Instruct-GGUF/discussions/4), thanks! Old versions still available as described in the dicsussion at tag/revision v0.1. ## Quant Collection Compare with Perplexity of full size `Q8_0` 1016.623 GiB (8.504 BPW): Final estimate: PPL = 2.9507 +/- 0.01468 ![Perplexity Chart](images/perplexity.png "Chart showing Perplexity improving as BPW increases.") ### * v0.2 `IQ4_KS` 554.421 GiB (4.638 BPW) Final estimate: PPL = 2.9584 +/- 0.01473
👈 Secret Recipe Special mix of `IQ4_KS` `ffn_(gate|up)_exps` and `IQ5_KS` `ffn_down_exps` routed experts. ```bash #!/usr/bin/env bash custom=" ## Attention [0-60] (GPU) # Only ik's fork uses this, keep it q8_0 as its only for PP with -mla 3 blk\..*\.attn_kv_b\.weight=q8_0 # ideally k_b and v_b are smaller than q8_0 as they are is used for TG with -mla 3 (and ik's imatrix supports it) # blk.*.attn_k_b.weight is not divisible by 256 so only supports qN_0 or iq4_nl blk\..*\.attn_k_b\.weight=q8_0 # Balance of attn tensors blk\..*\.attn_.*=q8_0 ## First Single Dense Layer [0] (GPU) blk\..*\.ffn_down\.weight=q8_0 blk\..*\.ffn_(gate|up)\.weight=q8_0 ## Shared Expert [1-60] (GPU) blk\..*\.ffn_down_shexp\.weight=q8_0 blk\..*\.ffn_(gate|up)_shexp\.weight=q8_0 ## Routed Experts [1-60] (CPU) blk\..*\.ffn_down_exps\.weight=iq5_ks blk\..*\.ffn_(gate|up)_exps\.weight=iq4_ks ## Token embedding and output tensors (GPU) token_embd\.weight=iq6_k output\.weight=iq6_k " custom=$( echo "$custom" | grep -v '^#' | \ sed -Ez 's:\n+:,:g;s:,$::;s:^,::' ) numactl -N 1 -m 1 \ ./build/bin/llama-quantize \ --custom-q "$custom" \ --imatrix /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/imatrix-Kimi-K2-Instruct-Q8_0.dat \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-384x15B-Instruct-safetensors-BF16-00001-of-00045.gguf \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-Instruct-IQ4_KS.gguf \ IQ4_KS \ 192 ```
### * v0.2 `IQ3_KS` 430.908 GiB (3.604 BPW) Final estimate: PPL = 3.0226 +/- 0.01518
👈 Secret Recipe Special mix of `IQ3_KS` `ffn_(gate|up)_exps` and `IQ4_KS` `ffn_down_exps` routed experts. ```bash #!/usr/bin/env bash custom=" ## Attention [0-60] (GPU) # Only ik's fork uses this, keep it q8_0 as its only for PP with -mla 3 blk\..*\.attn_kv_b\.weight=q8_0 # ideally k_b and v_b are smaller than q8_0 as they are is used for TG with -mla 3 (and ik's imatrix supports it) # blk.*.attn_k_b.weight is not divisible by 256 so only supports qN_0 or iq4_nl blk\..*\.attn_k_b\.weight=q8_0 # Balance of attn tensors blk\..*\.attn_.*=q8_0 ## First Single Dense Layer [0] (GPU) blk\..*\.ffn_down\.weight=q8_0 blk\..*\.ffn_(gate|up)\.weight=q8_0 ## Shared Expert [1-60] (GPU) blk\..*\.ffn_down_shexp\.weight=q8_0 blk\..*\.ffn_(gate|up)_shexp\.weight=q8_0 ## Routed Experts [1-60] (CPU) blk\..*\.ffn_down_exps\.weight=iq4_ks blk\..*\.ffn_(gate|up)_exps\.weight=iq3_ks ## Token embedding and output tensors (GPU) token_embd\.weight=iq4_k output\.weight=iq6_k " custom=$( echo "$custom" | grep -v '^#' | \ sed -Ez 's:\n+:,:g;s:,$::;s:^,::' ) numactl -N 1 -m 1 \ ./build/bin/llama-quantize \ --custom-q "$custom" \ --imatrix /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/imatrix-Kimi-K2-Instruct-Q8_0.dat \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-384x15B-Instruct-safetensors-BF16-00001-of-00045.gguf \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-Instruct-IQ3_KS.gguf \ IQ3_KS \ 192 ```
### * v0.2 `IQ2_KL` 349.389 GiB (2.923 BPW) Final estimate: PPL = 3.1813 +/- 0.01619
👈 Secret Recipe Special mix with brand new *SOTA* `IQ2_KL` `ffn_(gate|up)_exps` and `IQ3_KS` `ffn_down_exps` routed experts. ```bash #!/usr/bin/env bash custom=" ## Attention [0-60] (GPU) # Only ik's fork uses this, keep it q8_0 as its only for PP with -mla 3 blk\..*\.attn_kv_b\.weight=q8_0 # ideally k_b and v_b are smaller than q8_0 as they are is used for TG with -mla 3 (and ik's imatrix supports it) # blk.*.attn_k_b.weight is not divisible by 256 so only supports qN_0 or iq4_nl blk\..*\.attn_k_b\.weight=q8_0 # Balance of attn tensors blk\..*\.attn_.*=q8_0 ## First Single Dense Layer [0] (GPU) blk\..*\.ffn_down\.weight=q8_0 blk\..*\.ffn_(gate|up)\.weight=q8_0 ## Shared Expert (1-60) (GPU) blk\..*\.ffn_down_shexp\.weight=q8_0 blk\..*\.ffn_(gate|up)_shexp\.weight=q8_0 ## Routed Experts (1-60) (CPU) blk\..*\.ffn_down_exps\.weight=iq3_ks blk\..*\.ffn_(gate|up)_exps\.weight=iq2_kl ## Token embedding and output tensors (GPU) token_embd\.weight=iq4_k output\.weight=iq6_k " custom=$( echo "$custom" | grep -v '^#' | \ sed -Ez 's:\n+:,:g;s:,$::;s:^,::' ) numactl -N 1 -m 1 \ ./build/bin/llama-quantize \ --custom-q "$custom" \ --imatrix /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/imatrix-Kimi-K2-Instruct-Q8_0.dat \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-384x15B-Instruct-safetensors-BF16-00001-of-00045.gguf \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-Instruct-IQ2_KL.gguf \ IQ2_KL \ 192 ```
### * v0.2 `smol-IQ2_KL` 329.702 GiB (2.758 BPW) Final estimate: PPL = 3.4086 +/- 0.01773
👈 Secret Recipe Special mix of `IQ2_KL` `ffn_(gate|up)_exps` and also `IQ2_KL` `ffn_down_exps` routed experts. ```bash #!/usr/bin/env bash custom=" ## Attention [0-60] (GPU) # Only ik's fork uses this, keep it q8_0 as its only for PP with -mla 3 blk\..*\.attn_kv_b\.weight=q8_0 # ideally k_b and v_b are smaller than q8_0 as they are is used for TG with -mla 3 (and ik's imatrix supports it) # blk.*.attn_k_b.weight is not divisible by 256 so only supports qN_0 or iq4_nl blk\..*\.attn_k_b\.weight=q8_0 # Balance of attn tensors blk\..*\.attn_.*=q8_0 ## First Single Dense Layer [0] (GPU) blk\..*\.ffn_down\.weight=q8_0 blk\..*\.ffn_(gate|up)\.weight=q8_0 ## Shared Expert (1-60) (GPU) blk\..*\.ffn_down_shexp\.weight=q8_0 blk\..*\.ffn_(gate|up)_shexp\.weight=q8_0 ## Routed Experts (1-60) (CPU) blk\..*\.ffn_down_exps\.weight=iq2_kl blk\..*\.ffn_(gate|up)_exps\.weight=iq2_kl ## Token embedding and output tensors (GPU) token_embd\.weight=iq4_k output\.weight=iq6_k " custom=$( echo "$custom" | grep -v '^#' | \ sed -Ez 's:\n+:,:g;s:,$::;s:^,::' ) numactl -N 1 -m 1 \ ./build/bin/llama-quantize \ --custom-q "$custom" \ --imatrix /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/imatrix-Kimi-K2-Instruct-Q8_0.dat \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-384x15B-Instruct-safetensors-BF16-00001-of-00045.gguf \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-Instruct-bigattnshexpdense-smol-IQ2_KL.gguf \ IQ2_KL \ 192 ```
### * v0.2 `IQ2_KS` 290.327 GiB (2.429 BPW) Final estimate: PPL = 3.6827 +/- 0.01957
👈 Secret Recipe Special mix with `IQ2_KS` `ffn_(gate|up)_exps` and band new SOTA `IQ2_KL` `ffn_down_exps` routed experts. ```bash custom=" ## Attention [0-60] (GPU) # Only ik's fork uses this, keep it q8_0 as its only for PP with -mla 3 blk\..*\.attn_kv_b\.weight=q8_0 # ideally k_b and v_b are smaller than q8_0 as they are is used for TG with -mla 3 (and ik's imatrix supports it) # blk.*.attn_k_b.weight is not divisible by 256 so only supports qN_0 or iq4_nl blk\..*\.attn_k_b\.weight=q8_0 # Balance of attn tensors blk\..*\.attn_.*=q8_0 ## First Single Dense Layer [0] (GPU) blk\..*\.ffn_down\.weight=q8_0 blk\..*\.ffn_(gate|up)\.weight=q8_0 ## Shared Expert [1-60] (GPU) blk\..*\.ffn_down_shexp\.weight=q8_0 blk\..*\.ffn_(gate|up)_shexp\.weight=q8_0 ## Routed Experts [1-60] (CPU) blk\..*\.ffn_down_exps\.weight=iq2_kl blk\..*\.ffn_(gate|up)_exps\.weight=iq2_ks ## Token embedding and output tensors (GPU) token_embd\.weight=iq4_k output\.weight=iq6_k " custom=$( echo "$custom" | grep -v '^#' | \ sed -Ez 's:\n+:,:g;s:,$::;s:^,::' ) numactl -N 1 -m 1 \ ./build/bin/llama-quantize \ --custom-q "$custom" \ --imatrix /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/imatrix-Kimi-K2-Instruct-Q8_0.dat \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-384x15B-Instruct-safetensors-BF16-00001-of-00045.gguf \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-Instruct-IQ2_KS.gguf \ IQ2_KS \ 192 ```
### * v0.2 `IQ1_KT` 234.141 GiB (1.959 BPW) Final estimate: PPL = 3.9734 +/- 0.02152
👈 Secret Recipe Special mix of `IQ1_KT` `ffn_(gate|up)_exps` and `IQ2_KT` `ffn_down_exps` routed experts. ```bash custom=" ## Attention [0-60] (GPU) # Only ik's fork uses this, keep it q8_0 as its only for PP with -mla 3 blk\..*\.attn_kv_b\.weight=q8_0 # ideally k_b and v_b are smaller than q8_0 as they are is used for TG with -mla 3 (and ik's imatrix supports it) # blk.*.attn_k_b.weight is not divisible by 256 so only supports qN_0 or iq4_nl blk\..*\.attn_k_b\.weight=q8_0 # Balance of attn tensors blk\..*\.attn_.*=q8_0 ## First Single Dense Layer [0] (GPU) blk\..*\.ffn_down\.weight=q8_0 blk\..*\.ffn_(gate|up)\.weight=q8_0 ## Shared Expert [1-60] (GPU) blk\..*\.ffn_down_shexp\.weight=q8_0 blk\..*\.ffn_(gate|up)_shexp\.weight=q8_0 ## Routed Experts [1-60] (CPU) blk\..*\.ffn_down_exps\.weight=iq2_kt blk\..*\.ffn_(gate|up)_exps\.weight=iq1_kt ## Token embedding and output tensors (GPU) token_embd\.weight=iq4_kt output\.weight=iq6_k " custom=$( echo "$custom" | grep -v '^#' | \ sed -Ez 's:\n+:,:g;s:,$::;s:^,::' ) numactl -N 1 -m 1 \ ./build/bin/llama-quantize \ --custom-q "$custom" \ --imatrix /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/imatrix-Kimi-K2-Instruct-Q8_0.dat \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-384x15B-Instruct-safetensors-BF16-00001-of-00045.gguf \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-Instruct-bigattnshexpdense-IQ1_KT.gguf \ IQ1_KT \ 192 ```
### * v0.2 `smol-IQ1_KT` 219.375 GiB (1.835 BPW) Final estimate: PPL = 4.2187 +/- 0.02325
👈 Secret Recipe Special mix of `IQ1_KT` `ffn_(gate|up)_exps` and also `IQ1_KT` `ffn_down_exps` routed experts. ```bash #!/usr/bin/env bash custom=" ## Attention [0-60] (GPU) # Only ik's fork uses this, keep it q8_0 as its only for PP with -mla 3 blk\..*\.attn_kv_b\.weight=q8_0 # ideally k_b and v_b are smaller than q8_0 as they are is used for TG with -mla 3 (and ik's imatrix supports it) # blk.*.attn_k_b.weight is not divisible by 256 so only supports qN_0 or iq4_nl blk\..*\.attn_k_b\.weight=q8_0 # Balance of attn tensors blk\..*\.attn_.*=q8_0 ## First Single Dense Layer [0] (GPU) blk\..*\.ffn_down\.weight=q8_0 blk\..*\.ffn_(gate|up)\.weight=q8_0 ## Shared Expert [1-60] (GPU) blk\..*\.ffn_down_shexp\.weight=q8_0 blk\..*\.ffn_(gate|up)_shexp\.weight=q8_0 ## Routed Experts [1-60] (CPU) blk\..*\.ffn_down_exps\.weight=iq1_kt blk\..*\.ffn_(gate|up)_exps\.weight=iq1_kt ## Token embedding and output tensors (GPU) token_embd\.weight=iq4_kt output\.weight=iq6_k " custom=$( echo "$custom" | grep -v '^#' | \ sed -Ez 's:\n+:,:g;s:,$::;s:^,::' ) numactl -N 1 -m 1 \ ./build/bin/llama-quantize \ --custom-q "$custom" \ --imatrix /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/imatrix-Kimi-K2-Instruct-Q8_0.dat \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-384x15B-Instruct-safetensors-BF16-00001-of-00045.gguf \ /mnt/raid/models/ubergarm/Kimi-K2-Instruct-GGUF/Kimi-K2-Instruct-bigattnshexpdense-smol-IQ1_KT.gguf \ IQ1_KT \ 192 ```
## Example Commands ### Hybrid (multiple) CUDA + CPU ```bash # Two CUDA devices with enough VRAM to offload more layers # Keep in mind Kimi-K2 starts at 1 unlike DeepSeek at 3 (first dense layers) ./build/bin/llama-server \ --model "$model"\ --alias ubergarm/Kimi-K2-Instruct \ --ctx-size 32768 \ -ctk q8_0 \ -fa -fmoe \ -mla 3 \ -ngl 99 \ -ot "blk\.(1|2|3)\.ffn_.*=CUDA0" \ -ot "blk\.(4|5|6)\.ffn_.*=CUDA1" \ -ot exps=CPU \ --parallel 1 \ --threads 48 \ --threads-batch 64 \ --host 127.0.0.1 \ --port 8080 ``` ### CPU-Only (no GPU) ```bash # compile cmake -B build -DGGML_CUDA=0 -DGGML_BLAS=0 -DGGML_VULKAN=0 cmake --build build --config Release -j $(nproc) # run server # single CPU of a dual socket rig configured one NUMA per socket numactl -N 0 -m 0 \ ./build/bin/llama-server \ --model "$model"\ --alias ubergarm/Kimi-K2-Instruct \ --ctx-size 98304 \ -ctk q8_0 \ -fa -fmoe \ -mla 3 \ --parallel 1 \ --threads 128 \ --threads-batch 192 \ --numa numactl \ --host 127.0.0.1 \ --port 8080 ``` ## References * [ik_llama.cpp](https://github.com/ikawrakow/ik_llama.cpp) * [Getting Started Guide (already out of date lol)](https://github.com/ikawrakow/ik_llama.cpp/discussions/258) * [mainline llama.cpp PR](https://github.com/ggml-org/llama.cpp/pull/14654) * [gabriellarsion PR author test repo discussion](https://huggingface.co/gabriellarson/Kimi-K2-Instruct-GGUF/discussions/1)