Skip to content

[LLM] fix moe using on tensor parallelism #10875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: incubate/paddlenlp-fleety_20250421
Choose a base branch
from
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