Image-Text-to-Text
Transformers
Safetensors
kimi_k3
feature-extraction
compressed-tensors
conversational
custom_code
Eval Results
8-bit precision
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
Fix A_log loading via checkpoint-side slice instead of resizing the model parameter (alternative to #144)
#150
by sakshamio - opened
- modeling_kimi_linear.py +23 -0
modeling_kimi_linear.py
CHANGED
|
@@ -540,6 +540,29 @@ class KimiDeltaAttention(nn.Module):
|
|
| 540 |
self.head_dim, eps=config.rms_norm_eps, activation='sigmoid')
|
| 541 |
self.o_proj = nn.Linear(projection_size, self.hidden_size, bias=False)
|
| 542 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
def forward(
|
| 544 |
self,
|
| 545 |
hidden_states: torch.Tensor,
|
|
|
|
| 540 |
self.head_dim, eps=config.rms_norm_eps, activation='sigmoid')
|
| 541 |
self.o_proj = nn.Linear(projection_size, self.hidden_size, bias=False)
|
| 542 |
|
| 543 |
+
def _load_from_state_dict(self, state_dict, prefix, *args, **kwargs):
|
| 544 |
+
# The released checkpoint stores A_log as [head_dim] rather than
|
| 545 |
+
# [num_heads], which raises a size mismatch on a plain load. Inspecting
|
| 546 |
+
# the checkpoint shows elements [num_heads:head_dim] are exactly zero in
|
| 547 |
+
# every KDA layer -- i.e. num_heads trained per-head decays, zero-padded
|
| 548 |
+
# to head_dim by the export pipeline. The KDA kernel indexes A_log per
|
| 549 |
+
# head (the head count used for indexing comes from the shape of v at
|
| 550 |
+
# call time, not from A_log's own shape), so the model's [num_heads]
|
| 551 |
+
# parameter is correct; only the checkpoint tensor needs slicing down to
|
| 552 |
+
# match it.
|
| 553 |
+
key = prefix + "A_log"
|
| 554 |
+
if key in state_dict:
|
| 555 |
+
ckpt_val = state_dict[key]
|
| 556 |
+
want = self.A_log.shape[0]
|
| 557 |
+
if ckpt_val.shape[0] > want:
|
| 558 |
+
tail = ckpt_val[want:]
|
| 559 |
+
if not torch.all(tail == 0):
|
| 560 |
+
raise ValueError(
|
| 561 |
+
f"{key}: checkpoint tail beyond index {want} is non-zero; "
|
| 562 |
+
"refusing to truncate real values")
|
| 563 |
+
state_dict[key] = ckpt_val[:want]
|
| 564 |
+
super()._load_from_state_dict(state_dict, prefix, *args, **kwargs)
|
| 565 |
+
|
| 566 |
def forward(
|
| 567 |
self,
|
| 568 |
hidden_states: torch.Tensor,
|