@@ -93,17 +93,9 @@ def _ffn_gate_up(matrix, ortho_fn, intermediate_size=None):
9393 """Slice FFN gate_up, orthogonalise gate and up independently."""
9494 import paddle
9595
96- if matrix .ndim == 2 :
97- gate , up = paddle .split (matrix , [intermediate_size , intermediate_size ], axis = 1 )
98- return paddle .concat ([ortho_fn (gate ), ortho_fn (up )], axis = 1 )
99- elif matrix .ndim == 3 :
100- expert_updates = []
101- for ei in range (matrix .shape [0 ]):
102- gate , up = paddle .split (matrix [ei ], [intermediate_size , intermediate_size ], axis = 1 )
103- expert_updates .append (paddle .concat ([ortho_fn (gate ), ortho_fn (up )], axis = 1 ))
104- return paddle .stack (expert_updates , axis = 0 )
105- else :
106- raise ValueError (f"FFN gate_up split expects 2D or 3D tensor, got shape { matrix .shape } " )
96+ assert matrix .ndim == 2 or matrix .ndim == 3 , "FFN gate_up split expects 2D or 3D tensor"
97+ gate , up = paddle .split (matrix , [intermediate_size , intermediate_size ], axis = - 1 )
98+ return paddle .concat ([ortho_fn (gate ), ortho_fn (up )], axis = - 1 )
10799
108100 def _mla_per_head (matrix_2d_global , ortho_fn , head_num = None , axis = None , head_split_sizes = None ):
109101 """Slice MLA weights by heads."""
@@ -114,18 +106,6 @@ def _mla_per_head(matrix_2d_global, ortho_fn, head_num=None, axis=None, head_spl
114106 processed_groups = [ortho_fn (group ) for group in groups ]
115107 return paddle .concat (processed_groups , axis = axis )
116108
117- def _moe_experts (matrix_3d_global , ortho_fn ):
118- """Slice MoE weights by experts."""
119- import paddle
120-
121- if matrix_3d_global .ndim != 3 :
122- raise ValueError (f"MoE expert split expects 3D tensor, got shape { matrix_3d_global .shape } " )
123- n_experts = matrix_3d_global .shape [0 ]
124- return paddle .stack (
125- [ortho_fn (matrix_3d_global [ei ]) for ei in range (n_experts )],
126- axis = 0 ,
127- )
128-
129109 slice_config = {}
130110
131111 muon_configs = config .muon_configs
@@ -135,7 +115,6 @@ def _moe_experts(matrix_3d_global, ortho_fn):
135115 num_key_value_heads = config .num_key_value_heads
136116 num_key_value_groups = num_attention_head // num_key_value_heads
137117 use_mla = getattr (config , "q_lora_rank" , None ) and config .q_lora_rank > 0
138- moe_expert_fusion = getattr (config , "moe_expert_fusion" , False )
139118 use_gated_attn = getattr (config , "use_gated_attn" , False )
140119
141120 # Get Muon configuration from muon_configs
@@ -155,9 +134,6 @@ def _moe_experts(matrix_3d_global, ortho_fn):
155134 # Determine FFN slice strategy
156135 ffn_slice_fn = _ffn_gate_up if muon_ffn_split else None
157136
158- # Determine Fused MoE slice strategy
159- fused_moe_fn = _moe_experts if moe_expert_fusion else None
160-
161137 # Determine MLA slice strategy
162138 mla_slice_fn = None
163139 if use_mla and muon_qkv_update_mode == "split_head" :
@@ -198,11 +174,6 @@ def _add_layer_slice_config(prefix):
198174 {"intermediate_size" : moe_intermediate_size },
199175 )
200176
201- # Fused MoE weights (grouped_gemm)
202- if moe_expert_fusion and fused_moe_fn is not None :
203- slice_config [f"{ prefix } .mlp.experts.down_proj.weight" ] = (fused_moe_fn , {})
204- slice_config [f"{ prefix } .mlp.grouped_gemm_experts.weight2" ] = (fused_moe_fn , {})
205-
206177 # MLA weights
207178 if use_mla and mla_slice_fn is not None :
208179 assert (
0 commit comments