Skip to content

Commit

Permalink
fix tracking variance error (IBM#27)
Browse files Browse the repository at this point in the history
Signed-off-by: Mayank Mishra <[email protected]>
  • Loading branch information
mayank31398 authored Sep 28, 2024
1 parent f49d632 commit 1645214
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dolomite_engine/train_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ def train_step(

def all_reduce_metrics_tracker(metrics_tracker: MetricsTrackingDict) -> MetricsTrackingDict:
tensor = [metrics_tracker[key] for key in metrics_tracker]
tensor = torch.stack(tensor)
torch.distributed.all_reduce(tensor.cpu(), group=ProcessGroupManager.get_data_parallel_group())
tensor = torch.stack(tensor) / ProcessGroupManager.get_data_parallel_world_size()
tensor = tensor.cpu()
# gloo op doesn't support averaging so we do sum and divide by world size above
torch.distributed.all_reduce(tensor, group=ProcessGroupManager.get_data_parallel_group())
tensor = tensor.tolist()

for i, key in enumerate(metrics_tracker):
Expand Down
4 changes: 4 additions & 0 deletions dolomite_engine/utils/loss_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def __add__(self, x: MetricsTrackingDict | dict | float | int) -> MetricsTrackin
elif isinstance(x, (int, float)):
for key in self.data:
self.data[key] += x
else:
raise ValueError()

return self

Expand All @@ -28,6 +30,8 @@ def __truediv__(self, x: MetricsTrackingDict | dict | float | int) -> MetricsTra
elif isinstance(x, (int, float)):
for key in self.data:
self.data[key] /= x
else:
raise ValueError()

return self

Expand Down

0 comments on commit 1645214

Please sign in to comment.