Skip to content

Commit

Permalink
Drop inplace operation for loss computation with gradient accumulation (
Browse files Browse the repository at this point in the history
#35416)

Fix inplace loss computation
  • Loading branch information
qgallouedec authored Dec 26, 2024
1 parent 24c91f0 commit 4eb17b2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3700,7 +3700,7 @@ def training_step(
else:
# Finally we need to normalize the loss for reporting
if num_items_in_batch is None:
loss /= self.args.gradient_accumulation_steps
loss = loss / self.args.gradient_accumulation_steps

self.accelerator.backward(loss, **kwargs)

Expand Down

0 comments on commit 4eb17b2

Please sign in to comment.