@@ -230,8 +230,8 @@ def _add_layer_slice_config(prefix):
230230 _add_layer_slice_config (f"model.layers.{ layer_idx } " )
231231
232232 # MTP layers
233- if config . mtp_num_layers > 0 :
234- num_nextn_predict_layers = config . mtp_num_layers
233+ if getattr ( config , " mtp_num_layers" , 0 ) > 0 :
234+ num_nextn_predict_layers = getattr ( config , " mtp_num_layers" , 0 )
235235 else :
236236 num_nextn_predict_layers = config .num_nextn_predict_layers if config .num_nextn_predict_layers else 0
237237 for layer_idx in range (num_nextn_predict_layers ):
@@ -339,8 +339,8 @@ def _gen_aoa_config(cls, config: MiniMaxM2Config):
339339
340340 # NOTE: MiniMax-M2 has no dense layers (first_k_dense_replace=0)
341341
342- if config . mtp_num_layers > 0 :
343- num_nextn_predict_layers = config . mtp_num_layers
342+ if getattr ( config , " mtp_num_layers" , 0 ) > 0 :
343+ num_nextn_predict_layers = getattr ( config , " mtp_num_layers" , 0 )
344344 else :
345345 num_nextn_predict_layers = config .num_nextn_predict_layers if config .num_nextn_predict_layers else 0
346346
@@ -361,7 +361,7 @@ def _gen_aoa_config(cls, config: MiniMaxM2Config):
361361 ]
362362
363363 # transformer_layer.mlp.up_gate_proj.weight
364- if config . use_dense_mtp :
364+ if getattr ( config , " use_dense_mtp" , False ) :
365365 prefix_offset += ".transformer_layer"
366366 aoa_config ["aoa_statements" ] += [
367367 f"{ prefix } .mlp.gate_proj.weight^T, { prefix } .mlp.up_proj.weight^T -> { prefix_offset } .mlp.up_gate_proj.weight, fused_ffn" ,
@@ -382,7 +382,7 @@ def _gen_aoa_config(cls, config: MiniMaxM2Config):
382382 f"{ prefix } .self_attn.o_proj.weight^T -> { prefix_offset } .self_attn.o_proj.weight" ,
383383 ]
384384
385- if config . q_lora_rank :
385+ if getattr ( config , " q_lora_rank" , None ) :
386386 # MLA attention
387387 aoa_config ["aoa_statements" ] += [
388388 f"{ prefix } .self_attn.o_proj.weight^T -> { prefix_offset } .self_attn.o_proj.weight" ,
@@ -410,7 +410,7 @@ def _gen_aoa_config(cls, config: MiniMaxM2Config):
410410 ]
411411
412412 moe_layer_start = config .first_k_dense_replace
413- moe_layer_end = num_hidden_layers if config . use_dense_mtp else num_hidden_layers + num_nextn_predict_layers
413+ moe_layer_end = num_hidden_layers if getattr ( config , " use_dense_mtp" , False ) else num_hidden_layers + num_nextn_predict_layers
414414 # All layers are MoE (first_k_dense_replace=0)
415415 for layer_idx in reversed (range (moe_layer_start , moe_layer_end )):
416416 layer_idx_offset = layer_idx + num_head_empty_layers
@@ -506,8 +506,8 @@ def _gen_inv_aoa_config(cls, config: MiniMaxM2Config):
506506
507507 # NOTE: MiniMax-M2 has no dense layers (first_k_dense_replace=0)
508508
509- if config . mtp_num_layers > 0 :
510- num_nextn_predict_layers = config . mtp_num_layers
509+ if getattr ( config , " mtp_num_layers" , 0 ) > 0 :
510+ num_nextn_predict_layers = getattr ( config , " mtp_num_layers" , 0 )
511511 else :
512512 num_nextn_predict_layers = config .num_nextn_predict_layers if config .num_nextn_predict_layers else 0
513513
@@ -528,7 +528,7 @@ def _gen_inv_aoa_config(cls, config: MiniMaxM2Config):
528528 ]
529529
530530 # dense MTP: inverse mapping for dense MLP weights
531- if config . use_dense_mtp :
531+ if getattr ( config , " use_dense_mtp" , False ) :
532532 prefix_offset_tf = f"{ prefix_offset } .transformer_layer"
533533 aoa_statements += [
534534 f"{ prefix_offset_tf } .mlp.up_gate_proj.weight -> { prefix } .mlp.gate_proj.weight, { prefix } .mlp.up_proj.weight, fused_ffn" ,
@@ -552,7 +552,7 @@ def _gen_inv_aoa_config(cls, config: MiniMaxM2Config):
552552 f"{ prefix_offset } .self_attn.o_proj.weight^T -> { prefix } .self_attn.o_proj.weight" ,
553553 ]
554554
555- if config . q_lora_rank :
555+ if getattr ( config , " q_lora_rank" , None ) :
556556 # MLA attention
557557 aoa_statements += [
558558 f"{ prefix_offset } .self_attn.o_proj.weight^T -> { prefix } .self_attn.o_proj.weight" ,
@@ -583,7 +583,7 @@ def _gen_inv_aoa_config(cls, config: MiniMaxM2Config):
583583 ]
584584
585585 # All layers are MoE (first_k_dense_replace=0)
586- moe_layer_end = num_hidden_layers if config . use_dense_mtp else num_hidden_layers + num_nextn_predict_layers
586+ moe_layer_end = num_hidden_layers if getattr ( config , " use_dense_mtp" , False ) else num_hidden_layers + num_nextn_predict_layers
587587 for layer_idx in range (config .first_k_dense_replace , moe_layer_end ):
588588 layer_idx_offset = layer_idx + num_head_empty_layers
589589 prefix_offset = f"{ model_prefix } layers.{ layer_idx_offset } "
0 commit comments