Instructions to use moonshotai/Kimi-K2-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use moonshotai/Kimi-K2-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="moonshotai/Kimi-K2-Instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("moonshotai/Kimi-K2-Instruct", trust_remote_code=True, device_map="auto") - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use moonshotai/Kimi-K2-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "moonshotai/Kimi-K2-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moonshotai/Kimi-K2-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/moonshotai/Kimi-K2-Instruct
- SGLang
How to use moonshotai/Kimi-K2-Instruct 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 "moonshotai/Kimi-K2-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moonshotai/Kimi-K2-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "moonshotai/Kimi-K2-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moonshotai/Kimi-K2-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use moonshotai/Kimi-K2-Instruct with Docker Model Runner:
docker model run hf.co/moonshotai/Kimi-K2-Instruct
Commit History
-
Add converted tokenizer (no trust_remote_code needed)
Verified signature## Tokenizer Conversion This PR adds a converted tokenizer that works without `trust_remote_code=True`. ### Conversion Details - Converted using: `python scripts/convert_tokenizer.py moonshotai/Kimi-K2-Instruct --push-to-hub` - Original tokenizer type: `TikTokenTokenizer` - Converted tokenizer type: `TokenizersBackend` ### Validation Results - Tested on XNLI dataset (500 samples) - **All samples match 1-1** ✓ ### Usage ```python from transformers import AutoTokenizer # Now works without trust_remote_code=True tokenizer = AutoTokenizer.from_pretrained("moonshotai/Kimi-K2-Instruct") ``` --- *Converted with [transformers](https://github.com/huggingface/transformers) tokenizer conversion script*ad1f5f7
-
Transformers v5 support (#62)
Verified signature- Transformers v5 support (ec9a6495e0b99948f029b0b04a53f4aaa72fc4ba) Co-authored-by: Harry Mellor <hmellor@users.noreply.huggingface.co>1cbe779
-
Adjust number of reserved tokens to match the model (#15)
Verified signature- Adjust number of reserved tokens to match the model (90f5c284285beb0427de55d72590c2c4b61867ee) Co-authored-by: Dmytro Dzhulgakov <dzhulgakov@users.noreply.huggingface.co>c2fee60
-
Update tokenization_kimi.py (#56)
Verified signature- Update tokenization_kimi.py (ab6cc91cba2420e9d57baeb85067755984696f2a) Co-authored-by: Lyuwen Fu <lfu@users.noreply.huggingface.co>49e03b0
-
remove-added-functions.-in-tool_call_id (#60)
Verified signature- remove-added-functions.-in-tool_call_id (358dd33617e3b036623a0b1ec8d889635478859a)0102674 -
fix-apply-chat-template (#59)
Verified signature- fix apply_chat_template (530d76e376287a239335cefa045cfe0f3198c319) - always check content type (4ccbb9334e2f65d4cfec72ae68825e9e7938b7e2) - remove automatically add functions in tool call id (4bc8f61a54779ba3db30c4d6bba0ca4a7be62eb0)cc61331
-
update chat-template and tokenizer (#58)
Verified signature- update (1ecacf8ec6347df14aecbff867fe70732439ca4e)874f2bb
-
Add `new_version` tag with the updated model (#57)
Verified signature- Add `new_version` tag with the updated model (4da2bf4dbc65d67430671a48ee8a23ed35b84b45) Co-authored-by: Apolinário from multimodal AI art <multimodalart@users.noreply.huggingface.co>2a19363
-
Update chat_template.jinja (#49)
Verified signature- Update chat_template.jinja (212aa08a44f2911db1c96e36e07008375c520a70)c52f808 -
Update README.md
Verified signaturec499175 -
standalone chat template (#47)
Verified signature- add standalone template, allow use name fileld (c9d83cc4e06d582b1fdbbcc6b6f2b50607d8de40) - fix (115cd5f0c7c8cb835f1d031a2532a1ff6e6d50b7)b215bf7
-
fix typo (#33)
Verified signature- fix typo (6fcc812fe6d32456c99a2c4e03a256ab57c503b8) Co-authored-by: Kyungmin Lee <lkm2835@users.noreply.huggingface.co>0826e83
-
Updated Readme with released Technical Report link (#35)
Verified signature- Updated Readme with released Technical Report link (467094705a369666a8271dac717f566ab057036b) Co-authored-by: casinca <casinca@users.noreply.huggingface.co>6129c6d
-
fix typos
wangzhengtaod2513b8
-
Update README.md
Verified signature4f23950 -
update chat template
wangzhengtao6a1f5e6
-
Update README.md
Verified signatured1e2b19 -
update tokenizer_config
wangzhengtao37a95d8 -
Update tokenizer_config.json (#13)
Verified signature- Update tokenizer_config.json (c8430fc94a8087b216fbea297475543ba97d88c8) - update tokenizer to include tool response format as well (25bc044c0790fac7ff4fad943fc257a597b9ad38) - upload (ab29892994e1d5398c0016a995123972df193461) Co-authored-by: Ben Chen <bchenfireworks@users.noreply.huggingface.co>6be65c0 -
Update tokenizer_config.json (#13)
Verified signature- Update tokenizer_config.json (c8430fc94a8087b216fbea297475543ba97d88c8) - update tokenizer to include tool response format as well (25bc044c0790fac7ff4fad943fc257a597b9ad38) - upload (ab29892994e1d5398c0016a995123972df193461) Co-authored-by: Ben Chen <bchenfireworks@users.noreply.huggingface.co>1221eb6 -
fix: allow tokenize special tokens
wangzhengtao02de71c
-
comming soon -> coming soon (#12)
Verified signature- comming soon -> coming soon (73872f71eb43da133e2cfc51bc1b6bf8bce11a47) Co-authored-by: Sebastian Raschka <rasbt@users.noreply.huggingface.co>841a184
-
add github link in readme
liushaowei23bdc5f
-
update third party notices
liushaowei2f7e011
-
update banner
liushaoweic9a3d34 -
Upload folder using huggingface_hub
Verified signatureb543046 -
update readme
liushaowei7f98307 -
Update docs/deploy_guidance.md
Verified signature2bfbc7b -
Update README.md
Verified signaturec46f181 -
Update README.md
Verified signaturedc4be28 -
Upload folder using huggingface_hub
Verified signatureb51274b -
Upload folder using huggingface_hub
Verified signature8a112f5 -
Add files using upload-large-folder tool
Verified signature22bf139 -
initial commit
Verified signature37b5512