Skip to content
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

fix --use-cpu-initialization error when expert is not tensor-parallel #413

Open
wants to merge 1 commit into
base: main
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
9 changes: 8 additions & 1 deletion megatron/core/tensor_parallel/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ def _initialize_affine_weight_cpu(weight, output_size, input_size,
my_weight_list = weight_list[rank::world_size]

with torch.no_grad():
torch.cat(my_weight_list, dim=partition_dim, out=weight)
if master_weight.shape[partition_dim] > per_partition_size:
torch.cat(my_weight_list, dim=partition_dim, out=weight)
else:
# when non-expert is tensor-parallel and expert is not tensor-parallel,
# per_partition_size is equal to master_weight.shape[partition_dim],
# so my_weight_list len is 0 except in 0 rank ,so we can not use torch.cat,
# we should use assign.
weight = master_weight
if return_master_weight:
return master_weight
return None
Expand Down