Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 10 additions & 8 deletions src/megatron/bridge/training/utils/train_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ def calc_params_l2_norm(
False, # no per-parameter norm.
)
sharded_norm_2 = sharded_norm * sharded_norm
# Sum over all DP groups, including CP since distributed optimizer state is
# sharded jointly over DP+CP.
torch.distributed.all_reduce(
sharded_norm_2,
op=torch.distributed.ReduceOp.SUM,
group=parallel_state.get_data_parallel_group(with_context_parallel=True),
)
norm_2 += sharded_norm_2
else:
sharded_norm_2 = torch.zeros((1,), dtype=torch.float32, device="cuda")
# Sum over all DP groups, including CP since distributed optimizer state is
# sharded jointly over DP+CP.
torch.distributed.all_reduce(
sharded_norm_2,
op=torch.distributed.ReduceOp.SUM,
group=parallel_state.get_data_parallel_group(with_context_parallel=True),
)
norm_2 += sharded_norm_2

# Add norm contribution from expert layers in MoEs.
if len(moe_params_data) > 0:
Expand Down
Loading
Loading