Skip to content

Commit

Permalink
Fix CPO
Browse files Browse the repository at this point in the history
  • Loading branch information
qgallouedec committed Jan 24, 2025
1 parent 5e4d7be commit 6567321
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions trl/trainer/cpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ def make_inputs_require_grad(module, input, output):
preprocess_logits_for_metrics=preprocess_logits_for_metrics,
)

# Gradient accumulation requires scaled loss. Normally, loss scaling in the parent class depends on whether the
# model accepts loss-related kwargs. Since we compute our own loss, this check is irrelevant. We set
# self.model_accepts_loss_kwargs to False to enable scaling.
self.model_accepts_loss_kwargs = False

# Add tags for models that have been loaded with the correct transformers version
if hasattr(self.model, "add_model_tags"):
self.model.add_model_tags(self._tag_names)
Expand Down

0 comments on commit 6567321

Please sign in to comment.