Skip to content

Commit

Permalink
fix pp no drop last (PaddlePaddle#9439)
Browse files Browse the repository at this point in the history
  • Loading branch information
lugimzzz authored Nov 19, 2024
1 parent 801dd74 commit f21329c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions paddlenlp/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3284,6 +3284,14 @@ def prediction_pipeline_step(
else:
labels = None
inputs = inputs.pop("input_ids")
# consider no drop_last case
model_config_backup = model.micro_batch_size, model.accumulate_steps
if isinstance(inputs, tuple):
actual_batch_size = inputs[0].shape[0]
else:
actual_batch_size = inputs.shape[0]
model.micro_batch_size = 1
model.accumulate_steps = actual_batch_size

with paddle.no_grad():
if has_labels:
Expand All @@ -3293,6 +3301,7 @@ def prediction_pipeline_step(
loss = loss.mean().detach()
else:
raise ValueError("pipeline mode eval need label!")
model.micro_batch_size, model.accumulate_steps = model_config_backup

return (loss, None, labels)

Expand Down

0 comments on commit f21329c

Please sign in to comment.