@@ -374,17 +374,10 @@ def test_moe_layers_fuse_to_qmoe_when_quantized(self):
374374class TestPreprocessWeights :
375375 def _state_dict (self , config : ArchitectureConfig ) -> dict [str , torch .Tensor ]:
376376 model = GlmMoeDsaCausalLMModel (config )
377- state = {
377+ return {
378378 name : torch .zeros (tuple (int (d ) for d in p .shape ))
379379 for name , p in model .named_parameters ()
380380 }
381- # Convert Mobius's own attribute-path names into the HF-style
382- # ``model.layers.N.*`` names preprocess_weights expects on input.
383- renamed = {
384- f"model.{ name } " if not name .startswith ("lm_head" ) else name : v
385- for name , v in state .items ()
386- }
387- return renamed
388381
389382 def test_drops_mtp_layer_weights_with_warning (self , caplog ):
390383 config = _glm_config (num_hidden_layers = 4 )
@@ -420,6 +413,43 @@ def test_dsa_path_keeps_indexer_weights(self):
420413 out = model .preprocess_weights (state )
421414 assert any (".self_attn.indexer." in k for k in out )
422415
416+ @pytest .mark .parametrize ("use_dsa" , [True , False ], ids = ["dsa" , "dense" ])
417+ def test_preprocessed_weights_cover_every_graph_parameter (self , use_dsa : bool ):
418+ config = _glm_config (
419+ num_hidden_layers = 1 ,
420+ indexer_types = ["full" ],
421+ use_dsa = use_dsa ,
422+ )
423+ model = GlmMoeDsaCausalLMModel (config )
424+ graph = build_from_module (model , config , task = "glm-moe-dsa" )["model" ].graph
425+ state = {
426+ name : torch .zeros (tuple (int (d ) for d in initializer .shape ))
427+ for name , initializer in graph .initializers .items ()
428+ if initializer .const_value is None
429+ }
430+ expected = set (state )
431+
432+ if use_dsa :
433+ prefix = "model.layers.0.self_attn."
434+ key_rows = state .pop (f"{ prefix } k_b_proj.weight" ).reshape (
435+ config .num_attention_heads ,
436+ config .qk_nope_head_dim ,
437+ config .kv_lora_rank ,
438+ )
439+ value_rows = state .pop (f"{ prefix } v_b_proj.weight" ).reshape (
440+ config .num_attention_heads ,
441+ config .v_head_dim ,
442+ config .kv_lora_rank ,
443+ )
444+ state [f"{ prefix } kv_b_proj.weight" ] = torch .cat (
445+ (key_rows , value_rows ), dim = 1
446+ ).reshape (- 1 , config .kv_lora_rank )
447+
448+ out = model .preprocess_weights (state )
449+
450+ assert expected
451+ assert set (out ) == expected
452+
423453 def test_splits_hf_fused_kv_b_projection (self ):
424454 config = _glm_config (num_hidden_layers = 1 , indexer_types = ["full" ])
425455 model = GlmMoeDsaCausalLMModel (config )
0 commit comments