# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # This file was automatically generated from src/transformers/models/olmicro/modular_olmicro.py. # Do NOT edit this file manually as any edits will be overwritten by the generation of # the file from the modular. If any change should be done, please apply the change to the # modular_olmicro.py file directly. One of our CI enforces this. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # Copyright 2026 the HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import math from huggingface_hub.dataclasses import strict from transformers.configuration_utils import PreTrainedConfig from transformers.modeling_rope_utils import RopeParameters from transformers.utils import auto_docstring from transformers.utils.type_validators import interval @auto_docstring(checkpoint="allenai/olmicro-275m-base") @strict class OlmicroConfig(PreTrainedConfig): r""" embed_scale (`float`, *optional*): Scaling factor applied to embeddings. Defaults to `sqrt(hidden_size)` if not set. embedding_norm_eps (`float`, *optional*, defaults to 1e-6): Epsilon for the RMSNorm applied after embedding scaling. use_attention_gate (`bool`, *optional*, defaults to `True`): Whether to apply an elementwise sigmoid gate on the full attention output (before o_proj). use_head_qk_norm (`bool`, *optional*, defaults to `True`): Whether to use per-head QK normalization (norm of size head_dim per head) instead of full-dim norm (norm of size num_heads * head_dim). linear_num_key_heads (`int`, *optional*): Number of key heads for the linear attention layers. Defaults to `num_attention_heads`. linear_num_value_heads (`int`, *optional*): Number of value heads for the linear attention layers. Defaults to `num_attention_heads`. linear_key_head_dim (`int`, *optional*): Dimension of each key head in linear attention layers. Defaults to `head_dim`. linear_value_head_dim (`int`, *optional*): Dimension of each value head in linear attention layers. Defaults to `2 * linear_key_head_dim`. linear_a_log_min (`float`, *optional*, defaults to 0.0): Minimum value for uniform initialization of A_log in GatedDeltaNet layers. linear_a_log_max (`float`, *optional*, defaults to 16.0): Maximum value for uniform initialization of A_log in GatedDeltaNet layers. linear_dt_min (`float`, *optional*, defaults to 0.001): Minimum value for dt initialization in GatedDeltaNet layers. linear_dt_max (`float`, *optional*, defaults to 0.1): Maximum value for dt initialization in GatedDeltaNet layers. linear_dt_init_floor (`float`, *optional*, defaults to 0.0001): Floor value for clamping dt during initialization in GatedDeltaNet layers. linear_conv_kernel_dim (`int`, *optional*, defaults to 4): Kernel size for the short convolution applied to queries, keys, and values in linear attention layers. linear_allow_neg_eigval (`bool`, *optional*, defaults to `True`): Whether to allow negative eigenvalues in the GatedDeltaNet recurrence. Example: ```python >>> from transformers import OlmicroModel, OlmicroConfig >>> # Initializing an Olmicro style configuration >>> configuration = OlmicroConfig() >>> # Initializing a model from the Olmicro style configuration >>> model = OlmicroModel(configuration) >>> # Accessing the model configuration >>> configuration = model.config ``` """ model_type = "olmicro" keys_to_ignore_at_inference = ["past_key_values"] base_model_tp_plan = { "layers.*.self_attn.q_proj": "colwise_gather_output", # we need to replicate here due to the added norm on q and k "layers.*.self_attn.k_proj": "colwise_gather_output", # we need to replicate here due to the added norm on q and k "layers.*.self_attn.v_proj": "colwise_gather_output", # we need to replicate here due to the added norm on q and k "layers.*.self_attn.o_proj": "rowwise_split_input", # input is replicated due to the added norm on q and k "layers.*.mlp.gate_proj": "colwise", "layers.*.mlp.up_proj": "colwise", "layers.*.mlp.down_proj": "rowwise", } base_model_pp_plan = { "embed_tokens": (["input_ids"], ["inputs_embeds"]), "layers": (["hidden_states", "attention_mask"], ["hidden_states"]), "norm": (["hidden_states"], ["hidden_states"]), } vocab_size: int = 100352 # Override defaults from parent hidden_size: int = 640 intermediate_size: int = 5120 num_hidden_layers: int = 10 num_attention_heads: int = 8 num_key_value_heads: int = 8 hidden_act: str = "silu" max_position_embeddings: int = 8192 initializer_range: float = interval(min=0.0, max=1.0)(default=0.02) rms_norm_eps: float = 1e-6 use_cache: bool = True pad_token_id: int | None = 100277 bos_token_id: int | None = None eos_token_id: int | list[int] | None = 100257 tie_word_embeddings: bool = False rope_parameters: RopeParameters | dict | None = None attention_bias: bool = False attention_dropout: int | float | None = 0.0 layer_types: list[str] | None = None linear_num_key_heads: int | None = None linear_num_value_heads: int | None = None linear_key_head_dim: int | None = None linear_value_head_dim: int | None = None linear_a_log_min: float = 0.0 linear_a_log_max: float = 16.0 linear_dt_min: float = 0.001 linear_dt_max: float = 0.1 linear_dt_init_floor: float = 1e-4 linear_conv_kernel_dim: int = 4 linear_allow_neg_eigval: bool = True # New attributes embed_scale: float | None = None embedding_norm_eps: float = 1e-6 use_attention_gate: bool = True use_head_qk_norm: bool = True head_dim: int = 128 def __post_init__(self, **kwargs): if self.layer_types is None: # Default: 4 GDN layers + 1 full attention, repeating (4:1 ratio) self.layer_types = ["linear_attention"] * int(self.num_hidden_layers) for i in range(int(self.num_hidden_layers)): if i % 5 == 4: self.layer_types[i] = "full_attention" # Ensure at least one full attention layer if "full_attention" not in self.layer_types: self.layer_types[-1] = "full_attention" if self.embed_scale is None: self.embed_scale = math.sqrt(self.hidden_size) if self.linear_num_key_heads is None: self.linear_num_key_heads = self.num_attention_heads if self.linear_num_value_heads is None: self.linear_num_value_heads = self.num_attention_heads if self.linear_key_head_dim is None: self.linear_key_head_dim = self.head_dim if self.linear_value_head_dim is None: self.linear_value_head_dim = 2 * self.linear_key_head_dim super().__post_init__(**kwargs) def validate_architecture(self): """Part of `@strict`-powered validation. Validates the architecture of the config.""" if "linear_attention" not in self.layer_types: raise ValueError("Olmicro expects at least one 'linear_attention' layer.") if all(t == "linear_attention" for t in self.layer_types): raise ValueError("Olmicro expects at least one attention layer.") def convert_rope_params_to_dict(self, **kwargs): # NoPE model: skip RoPE parameter standardization entirely to prevent # Transformers from filling in default rope_theta/rope_type values. return kwargs __all__ = ["OlmicroConfig"]