Skip to content

Commit d368965

Browse files
committed
改动预览
1 parent c04ba85 commit d368965

4 files changed

Lines changed: 17 additions & 14 deletions

File tree

paddleformers/transformers/fused_a2a.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import paddle.distributed.communication.deep_ep as deep_ep
17+
# import paddle.distributed.communication.deep_ep as deep_ep
1818

19-
HAVE_DEEP_EP = True
19+
HAVE_DEEP_EP = False
2020

2121
import paddle
2222
from paddle.autograd import PyLayer

paddleformers/transformers/minimax_m2/configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def __init__(
137137
use_mtp=True,
138138
num_mtp_modules=3,
139139
mtp_transformer_layers=1,
140+
use_dense_mtp=False,
140141
use_routing_bias=True,
141142
moe_layer_freq=1,
142143
attn_type_list=None,
@@ -188,6 +189,7 @@ def __init__(
188189
self.use_mtp = use_mtp
189190
self.num_mtp_modules = num_mtp_modules
190191
self.mtp_transformer_layers = mtp_transformer_layers
192+
self.use_dense_mtp = use_dense_mtp
191193
self.use_routing_bias = use_routing_bias
192194
self.moe_layer_freq = moe_layer_freq
193195
self.attn_type_list = attn_type_list

paddleformers/transformers/minimax_m2/modeling.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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}"

paddleformers/utils/moe_hybrid_parallel_optimizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def __getattr__(self, item):
334334
return getattr(self._clip, item)
335335

336336
def __call__(self, params_grads):
337+
return params_grads
337338
return self._dygraph_clip(params_grads)
338339

339340

0 commit comments

Comments
 (0)