Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions paddlenlp/transformers/moe_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def __init__(

self.moe_num_experts = moe_num_experts
self.capacity = capacity
self.is_tp_moe = False
self.is_dp_moe = False

try:
dist.fleet.get_hybrid_communicate_group()
Expand All @@ -190,6 +192,7 @@ def __init__(
self.moe_num_experts, self.expert_parallel_degree
)
self.is_dummy_moe = False if self.expert_parallel_degree > 1 else True
self.is_dp_moe = True
elif (
is_fleet_init
and dist.fleet.get_hybrid_communicate_group().get_model_parallel_world_size() > 1
Expand All @@ -210,6 +213,7 @@ def __init__(
) # e.g. 单机2路tp, 那么 32 = 128/4

self.is_dummy_moe = False if self.expert_parallel_degree > 1 else True # False
self.is_tp_moe = True
else:
self.moe_group = None
self.moe_rank = 0
Expand Down Expand Up @@ -250,9 +254,11 @@ def _post_init(self):
for k in self.experts:
if k is not None:
for p in k.parameters():
p.expert = not self.is_dummy_moe
p.no_sync = not self.is_dummy_moe
# logger.info(f"expert param={p.name}, no-sync={p.no_sync}")
p.expert = not (self.is_tp_moe or self.is_dummy_moe) # type: ignore
p.no_sync = not (self.is_tp_moe or self.is_dummy_moe)
logger.info(f"expert param={p.name}, no-sync={p.no_sync}")
if self.is_mp_moe or self.is_dp_moe:
p.is_distributed = True

def forward(
self,
Expand Down
Loading