Run this model with HF Jobs
Run moonshotai/Kimi-K2-Instruct on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/moonshotai/Kimi-K2-Instruct. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/moonshotai/Kimi-K2-Instruct on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/moonshotai/Kimi-K2-Instruct. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/moonshotai/Kimi-K2-Instruct. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
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") - 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
wangzhengtao commited on
Commit ·
1ecacf8
1
Parent(s): 2a19363
update
Browse filesFiles changed (2)
12345678910111214 unmodified lines27282930313233{%- if tools -%}<|im_system|>tool_declare<|im_middle|># Tools{{ tools | tojson }}<|im_end|>{%- endif -%}{%- for message in messages -%}{%- if loop.first and messages[0]['role'] != 'system' -%}<|im_system|>system<|im_middle|>You are Kimi, an AI assistant created by Moonshot AI.<|im_end|>{%- endif -%}{%- set role_name = message.get('name') or message['role'] -%}{%- if message['role'] == 'user' -%}14 unmodified lines<|tool_calls_section_end|>{%- elif message['role'] == 'tool' -%}## Return of {{ message.tool_call_id }}{{ message['content'] }}{%- elif message['content'] is string -%}{{ message['content'] }}{%- elif message['content'] is not none -%}1234567891014 unmodified lines25262728293031{%- if tools -%}<|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>{%- endif -%}{% for message in messages %}{%- if loop.first and messages[0]['role'] != 'system' -%}<|im_system|>system<|im_middle|>You are Kimi, an AI assistant created by Moonshot AI.<|im_end|>{% endif %}{%- set role_name = message.get('name') or message['role'] -%}{%- if message['role'] == 'user' -%}14 unmodified lines<|tool_calls_section_end|>{%- elif message['role'] == 'tool' -%}## Return of {{ message.tool_call_id }}{{ message['content'] }}{%- elif message['content'] is string -%}{{ message['content'] }}{%- elif message['content'] is not none -%}
16 unmodified lines171819202122232425262728292 unmodified lines32132232316 unmodified linesfrom tokenizers import AddedToken, pre_tokenizers, Regexfrom transformers.tokenization_utils import PreTrainedTokenizerfrom transformers.models.gpt2.tokenization_gpt2 import bytes_to_unicodelogger = getLogger(__name__)VOCAB_FILES_NAMES = {"vocab_file": "tiktoken.model"}class TikTokenTokenizer(PreTrainedTokenizer):"""Tokenizing and encoding/decoding text using the Tiktoken tokenizer. See megatron/tokenizer/tiktoken_tokenizer.py.292 unmodified linescopyfile(self.vocab_file, out_vocab_file)return (out_vocab_file,)16 unmodified lines17181920212223242526272829292 unmodified lines32232332432532632732832933033133233333433533633733833934034116 unmodified linesfrom tokenizers import AddedToken, pre_tokenizers, Regexfrom transformers.tokenization_utils import PreTrainedTokenizerfrom transformers.models.gpt2.tokenization_gpt2 import bytes_to_unicodefrom typing import Anylogger = getLogger(__name__)VOCAB_FILES_NAMES = {"vocab_file": "tiktoken.model"}class TikTokenTokenizer(PreTrainedTokenizer):"""Tokenizing and encoding/decoding text using the Tiktoken tokenizer. See megatron/tokenizer/tiktoken_tokenizer.py.292 unmodified linescopyfile(self.vocab_file, out_vocab_file)return (out_vocab_file,)def apply_chat_template(self, conversation, tools: Optional[list[dict]] = None, **kwargs):tools = deep_sort_dict(tools)return super().apply_chat_template(conversation, tools=tools, **kwargs)def deep_sort_dict(obj: Any) -> Any:if isinstance(obj, dict):return {k: deep_sort_dict(v) for k, v in sorted(obj.items())}if isinstance(obj, list):return [deep_sort_dict(item) for item in obj]return obj
chat_template.jinja+5-7
tokenization_kimi.py+19-1