Instructions to use mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- LM Studio
- Pi new
How to use mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M"
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M
Run Hermes
hermes
- MLX LM
How to use mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M", "messages": [ {"role": "user", "content": "Hello"} ] }'
mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M
This model mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M was converted to MLX format from moonshotai/Kimi-K2-Instruct-0905 using mlx-lm version 0.26.3.
This is created for people using a single Apple Mac Studio M3 Ultra with 512 GB. The 4-bit version of Kimi K2 does not fit. Using research results, we aim to get 4-bit performance from a slightly smaller and smarter quantization. It should also not be so large that it leaves no memory for a useful context window.
You can find more similar MLX model quants for Apple Mac Studio with 512 GB at https://huggingface.co/bibproj
pip install mlx-lm
mlx_lm.generate --model mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M --temp 0.6 --min-p 0.01 --max-tokens 4096 --trust-remote-code --prompt "Hallo"
What is this DQ3_K_M?
In the Arxiv paper Quantitative Analysis of Performance Drop in DeepSeek Model Quantization the authors write,
We further propose
DQ3_K_M, a dynamic 3-bit quantization method that significantly outperforms traditionalQ3_K_Mvariant on various benchmarks, which is also comparable with 4-bit quantization (Q4_K_M) approach in most tasks.
and
dynamic 3-bit quantization method (
DQ3_K_M) that outperforms the 3-bit quantization implementation inllama.cppand achieves performance comparable to 4-bit quantization across multiple benchmarks.
The resulting multi-bitwidth quantization has been well tested and documented.
How can you create your own DQ3_K_M quants?
In the convert.py file of mlx-lm on your system ( you can see the original code here ), replace the code inside def mixed_quant_predicate() with something like
index = (
int(path.split(".")[layer_location])
if len(path.split(".")) > layer_location
else 0
)
# Build a mixed quant like "DQ3" of Arxiv paper https://arxiv.org/abs/2505.02390
# Quantitative Analysis of Performance Drop in DeepSeek Model Quantization
q_bits = 4
if "lm_head" in path:
q_bits = 6
#if "tokens" in path:
# q_bits = 4
if "attn.kv" in path:
q_bits = 6
#if "o_proj" in path:
# q_bits = 4
#if "attn.q" in path:
# q_bits = 4
# For all "mlp" and "shared experts"
if "down_proj" in path:
q_bits = 6
#if "up_proj" in path:
# q_bits = 4
#if "gate_proj" in path:
# q_bits = 4
# For "switch experts"
if "switch_mlp.up_proj" in path:
q_bits = 3
if "switch_mlp.gate_proj" in path:
q_bits = 3
if "switch_mlp.down_proj" in path:
q_bits = 3
# Blocks up to 5 are higher quality
if index < 5:
q_bits = 6
# Every 5th block is "medium" quality
if (index % 5) == 0:
q_bits = 4
#print("path:", path, "index:", index, "q_bits:", q_bits)
return {"group_size": group_size, "bits": q_bits}
Should you wish to squeeze more out of your quant, and you do not need to use a larger context window, you can change the last part of the above code to
if "switch_mlp.down_proj" in path:
q_bits = 4
# Blocks up to 5 are higher quality
if index < 5:
q_bits = 6
#print("path:", path, "index:", index, "q_bits:", q_bits)
return {"group_size": group_size, "bits": q_bits}
Then create your DQ3_K_M quant with
mlx_lm.convert --hf-path moonshotai/Kimi-K2-Instruct-0905 --mlx-path your-model-DQ3_K_M -q --quant-predicate mixed_3_4 --trust-remote-code
Enjoy!
- Downloads last month
- 994
4-bit
Model tree for mlx-community/Kimi-K2-Instruct-0905-mlx-DQ3_K_M
Base model
moonshotai/Kimi-K2-Instruct-0905