Instructions to use moonshotai/Kimi-K3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use moonshotai/Kimi-K3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="moonshotai/Kimi-K3", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("moonshotai/Kimi-K3", trust_remote_code=True, device_map="auto") - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use moonshotai/Kimi-K3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "moonshotai/Kimi-K3" # 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-K3", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/moonshotai/Kimi-K3
- SGLang
How to use moonshotai/Kimi-K3 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-K3" \ --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-K3", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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-K3" \ --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-K3", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use moonshotai/Kimi-K3 with Docker Model Runner:
docker model run hf.co/moonshotai/Kimi-K3
[RFC / Idea] Beyond Autoregressive Generation: Dynamic Backspace, In-Place Line Rewriting & Self-Healing Code Execution
Hi Kimi team and community,
Standard code LLMs are strictly forward-moving autoregressive systems ($P(x_t \mid x_{<t})$). When an LLM realizes it made a logical flaw 50 tokens earlier, it typically has to resort to conversational backtracking ("Sorry, let me rewrite that...") or append a correction at the very end. This wastes context, pollutes the code buffer, and breaks execution flow.
I would love to open a discussion on enabling a "Self-Healing / Non-Monotonic Generation" mechanism for code synthesis, where the model can emit dynamic editing primitives (like a virtual cursor/backspace) to mutate earlier lines after seeing subsequent logic or execution output.
The Core Problem
- Premature Commitments: A model defines an API signature or data structure on Line 2. By Line 25, it realizes a different structure or parameter is required. Current autoregressive generation cannot cleanly "backspace" Line 2.
- Execution Feedback: If an in-line REPL / test run fails midway, the model should heal the flawed block directly in-place rather than generating an entirely new code block.
Proposed Mechanics
1. Dynamic Cursor / Editing Primitives (Special Control Tokens)
Introduce dedicated editing tokens into the vocabulary:
<BACKSPACE_N>: Erase the previous $N$ characters/tokens.<EDIT_LINE_K> ... </EDIT_LINE_K>: Jump back to Line $K$, perform an in-place patch, and fast-forward back to the insertion point.<VERIFY_AND_REPAIR>: Trigger an execution checkpoint. If a runtime/syntax error occurs, roll back the generation pointer to the exact call site.
2. KV-Cache Truncation & Rollback
From an inference system perspective:
- Instead of running a fresh multi-turn prompt to rewrite code, the decoding engine simply pops the invalidated KV-cache entries back to token index $j$.
- The model regenerates from index $j$ conditioned on the new insight, saving massive memory and avoiding context bloat.
3. Diffusion / Non-Monotonic Fine-Tuning
- Train the model on human coding sessions (e.g., git commits, LSP undo/redo logs, terminal keystroke logs) where code development naturally includes deletion, cursor navigation, and refactoring.
- Formulate this as an interleaved Write $\rightarrow$ Execute $\rightarrow$ Backspace/Patch $\rightarrow$ Continue policy using Reinforcement Learning with Verifiable Rewards (RLVR).
Why this fits Kimi-K2.7-Code
Kimi's architecture already demonstrates exceptional capabilities in handling long context and deep technical reasoning. Equipping a coding model with the ability to self-heal in-place rather than just generating linearly would be a huge leap toward true agentic software engineering (closer to how humans actually write code in an IDE).
Would love to hear the team and community’s thoughts on:
- Feasibility of integrating control tokens for KV-cache splicing during inference.
- Training strategies using diff/patch datasets versus explicit cursor tokens.