Instructions to use moonshotai/Kimi-Linear-48B-A3B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use moonshotai/Kimi-Linear-48B-A3B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="moonshotai/Kimi-Linear-48B-A3B-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 AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("moonshotai/Kimi-Linear-48B-A3B-Instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("moonshotai/Kimi-Linear-48B-A3B-Instruct", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use moonshotai/Kimi-Linear-48B-A3B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "moonshotai/Kimi-Linear-48B-A3B-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-Linear-48B-A3B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/moonshotai/Kimi-Linear-48B-A3B-Instruct
- SGLang
How to use moonshotai/Kimi-Linear-48B-A3B-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-Linear-48B-A3B-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-Linear-48B-A3B-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-Linear-48B-A3B-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-Linear-48B-A3B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use moonshotai/Kimi-Linear-48B-A3B-Instruct with Docker Model Runner:
docker model run hf.co/moonshotai/Kimi-Linear-48B-A3B-Instruct
Non-existant API Call - Request for Help
When this is called: transformers.AutoModelForCausalLM.from_pretrained("tiny-random/kimi-linear") to load a smaller, randomly initialized version of kimi linear,
It comes up with this error: ImportError: cannot import name 'OutputRecorder' from 'transformers.utils.generic' (/opt/homebrew/lib/python3.14/site-packages/transformers/utils/generic.py) which originates from modeling_kimi.py from moonshotai/Kimi-Linear-48B-A3B-Instruct.
I am currently using transformers==5.2.0 and would like a workaround or a fix.
Thank you.
Full error message:
File /opt/homebrew/lib/python3.14/site-packages/transformers/models/auto/auto_factory.py:356, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
353 kwargs["adapter_kwargs"] = adapter_kwargs
355 if has_remote_code and trust_remote_code:
--> 356 model_class = get_class_from_dynamic_module(
357 class_ref, pretrained_model_name_or_path, code_revision=code_revision, **hub_kwargs, **kwargs
358 )
359 _ = hub_kwargs.pop("code_revision", None)
360 # This block handles the case where the user is loading a model with trust_remote_code=True
361 # but a library model exists with the same name. We don't want to override the autoclass
362 # mappings in this case, or all future loads of that model will be the remote code model.
File /opt/homebrew/lib/python3.14/site-packages/transformers/dynamic_module_utils.py:583, in get_class_from_dynamic_module(class_reference, pretrained_model_name_or_path, cache_dir, force_download, proxies, token, revision, local_files_only, repo_type, code_revision, **kwargs)
571 # And lastly we get the class inside our newly created module
572 final_module = get_cached_module_file(
573 repo_id,
574 module_file + ".py",
(...) 581 repo_type=repo_type,
582 )
--> 583 return get_class_in_module(class_name, final_module, force_reload=force_download)
...
---> 21 from transformers.utils.generic import OutputRecorder, check_model_inputs
23 try:
24 from fla.modules import FusedRMSNormGated, ShortConvolution
ImportError: cannot import name 'OutputRecorder' from 'transformers.utils.generic' (/opt/homebrew/lib/python3.14/site-packages/transformers/utils/generic.py)