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

[Cherry-pick] update truncate #8375

Merged
merged 1 commit into from
May 7, 2024
Merged
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
10 changes: 7 additions & 3 deletions paddlenlp/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2721,11 +2721,15 @@ def evaluation_loop(
# Number of losses has been rounded to a multiple of batch_size and in a distributed training, the number of
# samplers has been rounded to a multiple of batch_size, so we truncate.
if all_losses is not None:
all_losses = all_losses[:num_samples]
all_losses = all_losses[: num_samples * int(self.args.world_size / self.args.dataset_world_size)]
if all_preds is not None:
all_preds = nested_truncate(all_preds, num_samples)
all_preds = nested_truncate(
all_preds, num_samples * int(self.args.world_size / self.args.dataset_world_size)
)
if all_labels is not None:
all_labels = nested_truncate(all_labels, num_samples)
all_labels = nested_truncate(
all_labels, num_samples * int(self.args.world_size / self.args.dataset_world_size)
)

model.train()

Expand Down
Loading