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

πŸ§‘β€πŸ€β€πŸ§‘ Proper metrics gathering across ranks before logging #2474

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion trl/trainer/dpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,11 @@ def log(self, logs: dict[str, float], start_time: Optional[float] = None) -> Non
train_eval = "train" if "loss" in logs else "eval"
# Add averaged stored metrics to logs
for key, metrics in self._stored_metrics[train_eval].items():
logs[key] = torch.tensor(metrics).mean().item()
if isinstance(metrics[0], torch.Tensor):
gathered = self._nested_gather([m.cuda() for m in metrics])
qgallouedec marked this conversation as resolved.
Show resolved Hide resolved
metrics = [g.mean() for g in gathered]
meaned = torch.tensor(metrics).mean()
logs[key] = meaned.item()
del self._stored_metrics[train_eval]

if version.parse(transformers.__version__) >= version.parse("4.47.0.dev0"):
Expand Down
Loading