Skip to content

Commit cdb75de

Browse files
authored
Fix Mistral Large 4 config (#50418)
fix
1 parent 7d5d6d6 commit cdb75de

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎src/transformers/models/mistral_large4/configuration_mistral_large4.py‎

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/transformers/models/mistral_large4/modular_mistral_large4.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import torch
1919
import torch.nn.functional as F
20+
from huggingface_hub.dataclasses import strict
2021
from torch import nn
2122

2223
from ... import initialization as init
@@ -51,6 +52,8 @@
5152
from ..qwen2_moe.modeling_qwen2_moe import Qwen2MoeMLP
5253

5354

55+
@auto_docstring(checkpoint="mistralai/Mistral-Large-4-1T-A52B")
56+
@strict
5457
class MistralLarge4TextConfig(GlmMoeDsaConfig):
5558
r"""
5659
n_group (`int`, *optional*, defaults to 1):
@@ -73,9 +76,6 @@ class MistralLarge4TextConfig(GlmMoeDsaConfig):
7376
List with at least the same length as the number of layers in the model.
7477
A `1` at an index position indicates that the corresponding layer will use RoPE,
7578
while a `0` indicates that it's a NoPE layer.
76-
no_rope_layer_interval (`int`, *optional*, defaults to 4):
77-
Every `no_rope_layer_interval`-th layer is a NoPE layer (no rotary embedding in the attention nor in the
78-
indexer). The other layers use RoPE.
7979
kv_source_layers (`list[int]`, *optional*):
8080
For each layer, the index of the layer whose latent KV cache it attends to. A layer whose entry is its own
8181
index computes and caches its own latent KV; a layer pointing at an earlier layer has no `kv_a_proj_with_mqa`
@@ -134,7 +134,6 @@ class MistralLarge4TextConfig(GlmMoeDsaConfig):
134134
index_n_heads: int = 32
135135
first_k_dense_replace: int = 1
136136
no_rope_layers: list[int] | None = None
137-
no_rope_layer_interval: int = 4
138137
kv_source_layers: list[int] | None = None
139138
final_logit_softcapping: float = 30.0
140139

@@ -156,8 +155,9 @@ def __post_init__(self, **kwargs):
156155
}
157156
# NoPE every `no_rope_layer_interval`-th layer (smollm3 convention: 1 == uses RoPE)
158157
if self.no_rope_layers is None:
158+
no_rope_layer_interval = kwargs.pop("no_rope_layer_interval", 4)
159159
self.no_rope_layers = [
160-
int((layer_idx + 1) % self.no_rope_layer_interval != 0) for layer_idx in range(self.num_hidden_layers)
160+
int((layer_idx + 1) % no_rope_layer_interval != 0) for layer_idx in range(self.num_hidden_layers)
161161
]
162162
# KV sharing: by default every layer owns its latent KV cache
163163
if self.kv_source_layers is None:
@@ -194,6 +194,8 @@ def kv_sharing_modes(self) -> list[str | None]:
194194
return kv_sharing_modes
195195

196196

197+
@auto_docstring(checkpoint="mistralai/Mistral-Large-4-1T-A52B")
198+
@strict
197199
class MistralLarge4Config(Mistral3Config):
198200
model_type = "mistral_large4"
199201
sub_configs_defaults = {

‎utils/check_config_attributes.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
],
235235
"DeepseekV32Config": ["head_dim", "layer_types", "mlp_bias", "first_k_dense_replace", "n_routed_experts"],
236236
"GlmMoeDsaConfig": ["head_dim", "layer_types", "mlp_bias", "first_k_dense_replace", "n_routed_experts"],
237-
"MistralLarge4TextConfig": ["layer_types", "first_k_dense_replace", "no_rope_layer_interval", "kv_source_layers"],
237+
"MistralLarge4TextConfig": ["layer_types", "first_k_dense_replace", "kv_source_layers"],
238238
"EsmFoldConfig": ["esm_ablate_pairwise", "esm_ablate_sequence", "esm_input_dropout", "esm_type"],
239239
"TrunkConfig": ["cpu_grad_checkpoint", "layer_drop"],
240240
"Zamba2Config": ["use_mamba_kernels", "use_mem_eff_path"],

0 commit comments

Comments
 (0)