Instructions to use XiaomiMiMo/MiMo-7B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use XiaomiMiMo/MiMo-7B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="XiaomiMiMo/MiMo-7B-Base", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("XiaomiMiMo/MiMo-7B-Base", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use XiaomiMiMo/MiMo-7B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "XiaomiMiMo/MiMo-7B-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "XiaomiMiMo/MiMo-7B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/XiaomiMiMo/MiMo-7B-Base
- SGLang
How to use XiaomiMiMo/MiMo-7B-Base 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 "XiaomiMiMo/MiMo-7B-Base" \ --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": "XiaomiMiMo/MiMo-7B-Base", "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 "XiaomiMiMo/MiMo-7B-Base" \ --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": "XiaomiMiMo/MiMo-7B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use XiaomiMiMo/MiMo-7B-Base with Docker Model Runner:
docker model run hf.co/XiaomiMiMo/MiMo-7B-Base
Update modeling_mimo.py
Browse filesFix:
1. Some parameter names are not aligned with Qwen2.
2. The return value of Qwen2Attention is three in some transformer versions.
- modeling_mimo.py +6 -6
modeling_mimo.py
CHANGED
|
@@ -27,10 +27,10 @@ class MiMoMTPLayers(nn.Module):
|
|
| 27 |
hidden_states,
|
| 28 |
attention_mask,
|
| 29 |
position_ids,
|
| 30 |
-
|
| 31 |
output_attentions: Optional[bool]=False,
|
| 32 |
use_cache: Optional[bool]=False,
|
| 33 |
-
|
| 34 |
cache_position=None,
|
| 35 |
**kwargs):
|
| 36 |
input_embeds = self.token_layernorm(input_embeds)
|
|
@@ -38,15 +38,15 @@ class MiMoMTPLayers(nn.Module):
|
|
| 38 |
hidden_states = self.input_proj(torch.cat([previous_hidden_states, input_embeds], dim=-1))
|
| 39 |
residual = hidden_states
|
| 40 |
hidden_states = self.input_layernorm(hidden_states)
|
| 41 |
-
hidden_states
|
| 42 |
attention_mask=attention_mask,
|
| 43 |
position_ids=position_ids,
|
| 44 |
-
|
| 45 |
output_attentions=output_attentions,
|
| 46 |
use_cache=use_cache,
|
| 47 |
cache_position=cache_position,
|
| 48 |
-
|
| 49 |
-
**kwargs)
|
| 50 |
hidden_states = residual + hidden_states
|
| 51 |
residual = hidden_states
|
| 52 |
hidden_states = self.post_attention_layernorm(hidden_states)
|
|
|
|
| 27 |
hidden_states,
|
| 28 |
attention_mask,
|
| 29 |
position_ids,
|
| 30 |
+
past_key_value: Optional[Cache]=None,
|
| 31 |
output_attentions: Optional[bool]=False,
|
| 32 |
use_cache: Optional[bool]=False,
|
| 33 |
+
position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
|
| 34 |
cache_position=None,
|
| 35 |
**kwargs):
|
| 36 |
input_embeds = self.token_layernorm(input_embeds)
|
|
|
|
| 38 |
hidden_states = self.input_proj(torch.cat([previous_hidden_states, input_embeds], dim=-1))
|
| 39 |
residual = hidden_states
|
| 40 |
hidden_states = self.input_layernorm(hidden_states)
|
| 41 |
+
hidden_states = self.self_attn(hidden_states,
|
| 42 |
attention_mask=attention_mask,
|
| 43 |
position_ids=position_ids,
|
| 44 |
+
past_key_value=past_key_value,
|
| 45 |
output_attentions=output_attentions,
|
| 46 |
use_cache=use_cache,
|
| 47 |
cache_position=cache_position,
|
| 48 |
+
position_embeddings=position_embeddings,
|
| 49 |
+
**kwargs)[0]
|
| 50 |
hidden_states = residual + hidden_states
|
| 51 |
residual = hidden_states
|
| 52 |
hidden_states = self.post_attention_layernorm(hidden_states)
|