Drop inplace operation for loss computation with gradient accumulation (#35416)

Fix inplace loss computation
This commit is contained in:
Quentin Gallouédec 2024-12-26 14:58:53 +01:00 committed by GitHub
parent 24c91f095f
commit 4eb17b26e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3700,7 +3700,7 @@ class Trainer:
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)