@@ -457,13 +457,18 @@ def load_experts_weight(
457457 """
458458 logical_expert_ids = [
459459 i
460+ % (
461+ self .fd_config .model_config .moe_num_experts [0 ]
462+ if isinstance (self .fd_config .model_config .moe_num_experts , list )
463+ else self .fd_config .model_config .moe_num_experts
464+ )
460465 for i in range (
461466 self .expert_id_offset ,
462467 self .expert_id_offset + self .num_local_experts ,
463468 )
464469 ]
465470 ep_rank_to_expert_id_list = [i for i in range (self .num_experts )]
466- if self .redundant_table_manger is not None and is_rearrange is True :
471+ if self .redundant_table_manger is not None :
467472 (
468473 ep_rank_to_expert_id_list ,
469474 expert_id_to_ep_rank_array ,
@@ -477,18 +482,15 @@ def load_experts_weight(
477482 down_proj_weights = []
478483 if isinstance (state_dict , list ):
479484 state_dict = dict (state_dict )
480- is_ffn_merged = (
481- up_gate_proj_expert_weight_key .format (logical_expert_ids [0 ] if is_rearrange else self .expert_id_offset )
482- in state_dict
483- )
485+ is_ffn_merged = up_gate_proj_expert_weight_key .format (logical_expert_ids [0 ]) in state_dict
484486 if is_ffn_merged :
485487 for expert_idx in logical_expert_ids :
486488 down_proj_expert_weight_key_name = down_proj_expert_weight_key .format (expert_idx )
487489 up_gate_proj_expert_weight_key_name = up_gate_proj_expert_weight_key .format (expert_idx )
488490 up_gate_proj_weights .append (
489491 get_tensor (
490492 (
491- state_dict . pop ( up_gate_proj_expert_weight_key_name )
493+ state_dict [ up_gate_proj_expert_weight_key_name ]
492494 if up_gate_proj_expert_weight_key_name in state_dict
493495 else up_gate_proj_expert_weight_key_name
494496 ),
@@ -498,7 +500,7 @@ def load_experts_weight(
498500 down_proj_weights .append (
499501 get_tensor (
500502 (
501- state_dict . pop ( down_proj_expert_weight_key_name )
503+ state_dict [ down_proj_expert_weight_key_name ]
502504 if down_proj_expert_weight_key_name in state_dict
503505 else down_proj_expert_weight_key_name
504506 ),
0 commit comments