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:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("XiaomiMiMo/MiMo-V2-Flash", dtype="auto") - Notebooks
- Google Colab
- Kaggle
[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 |
|