4040# 52-layer pattern, which keeps a representative mamba (M), MoE-MLP (E) and
4141# attention (*) layer mix.
4242_LLM_LAYER_TYPES = ["mamba" , "moe" , "mamba" , "moe" , "mamba" , "attention" ]
43- # Transformers 5.15 serializes the same hybrid blocks under their canonical names.
44- _SERIALIZED_LLM_LAYER_TYPES = [
45- "linear_attention" ,
46- "moe" ,
47- "linear_attention" ,
48- "moe" ,
49- "linear_attention" ,
50- "full_attention" ,
51- ]
43+ _LLM_LAYER_TYPE_ALIASES = {
44+ "linear_attention" : "mamba" ,
45+ "full_attention" : "attention" ,
46+ }
5247_LLM_OVERRIDES = {
5348 "hybrid_override_pattern" : "MEMEM*" ,
5449 "layer_types" : _LLM_LAYER_TYPES ,
@@ -72,6 +67,11 @@ def _apply_overrides(sub_config, overrides: dict) -> None:
7267 setattr (sub_config , key , value )
7368
7469
70+ def _normalize_llm_layer_types (layer_types : list [str ]) -> list [str ]:
71+ """Normalize equivalent remote-config names to the toy model's layer vocabulary."""
72+ return [_LLM_LAYER_TYPE_ALIASES .get (layer_type , layer_type ) for layer_type in layer_types ]
73+
74+
7575def _fix_tied_weights_keys (model : nn .Module ) -> None :
7676 """Convert _tied_weights_keys from list to dict for transformers 5.x compatibility."""
7777 for module in model .modules ():
@@ -223,11 +223,23 @@ def test_nemotron_omni_conversion_roundtrip(self, nemotron_omni_toy_model_path,
223223 with open (config_file ) as f :
224224 saved_config = json .load (f )
225225
226+ source_config_file = Path (hf_model_id ) / "config.json"
227+ if source_config_file .exists ():
228+ with open (source_config_file ) as f :
229+ source_config = json .load (f )
230+ else :
231+ source_config = AutoConfig .from_pretrained (hf_model_id , trust_remote_code = True ).to_dict ()
232+ source_llm_config = source_config ["llm_config" ]
233+
226234 assert saved_config ["architectures" ][0 ] == "NemotronH_Nano_Omni_Reasoning_V3"
227235 assert saved_config ["model_type" ] == "NemotronH_Nano_Omni_Reasoning_V3"
228236 assert "llm_config" in saved_config
229237 assert "vision_config" in saved_config
230238 assert "sound_config" in saved_config
231239 assert saved_config ["llm_config" ]["num_hidden_layers" ] == 6
232- assert saved_config ["llm_config" ]["layer_types" ] == _SERIALIZED_LLM_LAYER_TYPES
233- assert saved_config ["llm_config" ]["layers_block_type" ] == _SERIALIZED_LLM_LAYER_TYPES
240+ expected_layer_types = _normalize_llm_layer_types (source_llm_config ["layer_types" ])
241+ expected_block_types = _normalize_llm_layer_types (source_llm_config ["layers_block_type" ])
242+ assert expected_layer_types == _LLM_LAYER_TYPES
243+ assert expected_block_types == _LLM_LAYER_TYPES
244+ assert _normalize_llm_layer_types (saved_config ["llm_config" ]["layer_types" ]) == expected_layer_types
245+ assert _normalize_llm_layer_types (saved_config ["llm_config" ]["layers_block_type" ]) == expected_block_types
0 commit comments