Instructions to use XiaomiMiMo/MiMo-V2-Flash with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use XiaomiMiMo/MiMo-V2-Flash with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="XiaomiMiMo/MiMo-V2-Flash", 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-V2-Flash", trust_remote_code=True, dtype="auto") - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use XiaomiMiMo/MiMo-V2-Flash with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "XiaomiMiMo/MiMo-V2-Flash" # 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-V2-Flash", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/XiaomiMiMo/MiMo-V2-Flash
- SGLang
How to use XiaomiMiMo/MiMo-V2-Flash 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-V2-Flash" \ --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-V2-Flash", "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-V2-Flash" \ --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-V2-Flash", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use XiaomiMiMo/MiMo-V2-Flash with Docker Model Runner:
docker model run hf.co/XiaomiMiMo/MiMo-V2-Flash
[Fix.] apply attention_value_scale.
#39
by Jumbo0715 - opened
modeling_mimo_v2_flash.py
CHANGED
|
@@ -330,6 +330,8 @@ class MiMoV2Attention(nn.Module):
|
|
| 330 |
self.v_proj = nn.Linear(config.hidden_size, v_hidden_size, bias=self.attention_bias)
|
| 331 |
self.o_proj = nn.Linear(o_hidden_size, config.hidden_size, bias=False)
|
| 332 |
|
|
|
|
|
|
|
| 333 |
self.attention_sink_bias = (
|
| 334 |
torch.nn.Parameter(torch.empty(config.num_attention_heads), requires_grad=False)
|
| 335 |
if (config.add_full_attention_sink_bias and not is_swa) or (config.add_swa_attention_sink_bias and is_swa)
|
|
@@ -353,6 +355,9 @@ class MiMoV2Attention(nn.Module):
|
|
| 353 |
query_states = self.q_proj(hidden_states).view(qk_hidden_shape).transpose(1, 2)
|
| 354 |
key_states = self.k_proj(hidden_states).view(qk_hidden_shape).transpose(1, 2)
|
| 355 |
value_states = self.v_proj(hidden_states).view(v_hidden_shape).transpose(1, 2)
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
cos, sin = position_embeddings
|
| 358 |
|
|
|
|
| 330 |
self.v_proj = nn.Linear(config.hidden_size, v_hidden_size, bias=self.attention_bias)
|
| 331 |
self.o_proj = nn.Linear(o_hidden_size, config.hidden_size, bias=False)
|
| 332 |
|
| 333 |
+
self.v_scale = getattr(config, "attention_value_scale", None)
|
| 334 |
+
|
| 335 |
self.attention_sink_bias = (
|
| 336 |
torch.nn.Parameter(torch.empty(config.num_attention_heads), requires_grad=False)
|
| 337 |
if (config.add_full_attention_sink_bias and not is_swa) or (config.add_swa_attention_sink_bias and is_swa)
|
|
|
|
| 355 |
query_states = self.q_proj(hidden_states).view(qk_hidden_shape).transpose(1, 2)
|
| 356 |
key_states = self.k_proj(hidden_states).view(qk_hidden_shape).transpose(1, 2)
|
| 357 |
value_states = self.v_proj(hidden_states).view(v_hidden_shape).transpose(1, 2)
|
| 358 |
+
|
| 359 |
+
if self.v_scale is not None:
|
| 360 |
+
value_states = value_states * self.v_scale
|
| 361 |
|
| 362 |
cos, sin = position_embeddings
|
| 363 |
|