@@ -65,7 +65,7 @@ def _resolve_hidden_act(config, model_type: str) -> str | None:
6565 or getattr (config , "afn" , None )
6666 # LLaDA/OLMo expose the activation as ``activation_type`` (e.g. "silu").
6767 or getattr (config , "activation_type" , None )
68- or ("silu" if model_type in ("qwen" , "chatglm" ) else None )
68+ or ("silu" if model_type in ("qwen" , "chatglm" , "lfm2" ) else None )
6969 # gelu_activation is a boolean (XLM) — must be after all string
7070 # attrs so it cannot override an explicit hidden_act.
7171 or ("gelu" if getattr (config , "gelu_activation" , False ) else None )
@@ -411,6 +411,10 @@ class ArchitectureConfig(BaseModelConfig):
411411 linear_num_key_heads : int | None = None
412412 linear_num_value_heads : int | None = None
413413
414+ # Double-gated short-convolution config (LFM2-style hybrid layers).
415+ short_conv_kernel : int = 3
416+ short_conv_bias : bool = False
417+
414418 rms_norm_eps : float = 1e-6
415419
416420 # Rotary embedding config.
@@ -707,6 +711,8 @@ def from_transformers(cls, config, parent_config=None) -> ArchitectureConfig:
707711 linear_value_head_dim = (getattr (config , "linear_value_head_dim" , None )),
708712 linear_num_key_heads = (getattr (config , "linear_num_key_heads" , None )),
709713 linear_num_value_heads = (getattr (config , "linear_num_value_heads" , None )),
714+ short_conv_kernel = getattr (config , "conv_L_cache" , 3 ),
715+ short_conv_bias = getattr (config , "conv_bias" , False ),
710716 pad_token_id = (getattr (config , "pad_token_id" , 0 )),
711717 model_type = model_type ,
712718 bos_token_id = getattr (config , "bos_token_id" , None ),
@@ -794,6 +800,7 @@ def from_transformers(cls, config, parent_config=None) -> ArchitectureConfig:
794800 "gemma3_text" ,
795801 "gemma3n" ,
796802 "gemma3n_text" ,
803+ "lfm2" ,
797804 "flex_olmo" ,
798805 "olmoe" ,
799806 "olmo2" ,
@@ -1313,6 +1320,38 @@ def from_transformers(cls, config, parent_config=None) -> MuseGlimmerConfig:
13131320 )
13141321
13151322
1323+ @dataclasses .dataclass
1324+ class Lfm2Config (CausalLMConfig ):
1325+ """Configuration for LFM2's automatically adjusted feed-forward width."""
1326+
1327+ block_multiple_of : int = 256
1328+ block_ffn_dim_multiplier : float | int | None = 1.0
1329+ block_auto_adjust_ff_dim : bool = True
1330+
1331+ @property
1332+ def effective_intermediate_size (self ) -> int :
1333+ """The MLP width constructed by HuggingFace's ``Lfm2MLP``."""
1334+ intermediate_size = self .intermediate_size
1335+ if self .block_auto_adjust_ff_dim :
1336+ intermediate_size = int (2 * intermediate_size / 3 )
1337+ if self .block_ffn_dim_multiplier is not None :
1338+ intermediate_size = int (self .block_ffn_dim_multiplier * intermediate_size )
1339+ intermediate_size = self .block_multiple_of * (
1340+ (intermediate_size + self .block_multiple_of - 1 ) // self .block_multiple_of
1341+ )
1342+ return intermediate_size
1343+
1344+ @classmethod
1345+ def from_transformers (cls , config , parent_config = None ) -> Lfm2Config :
1346+ base = ArchitectureConfig .from_transformers (config , parent_config )
1347+ return cls (
1348+ ** _shallow_fields (base ),
1349+ block_multiple_of = getattr (config , "block_multiple_of" , 256 ),
1350+ block_ffn_dim_multiplier = getattr (config , "block_ffn_dim_multiplier" , 1.0 ),
1351+ block_auto_adjust_ff_dim = getattr (config , "block_auto_adjust_ff_dim" , True ),
1352+ )
1353+
1354+
13161355@dataclasses .dataclass
13171356class DFlashConfig (CausalLMConfig ):
13181357 """Configuration for the DFlash speculative-decoding draft model.
0 commit comments