Skip to content

Commit

Permalink
[trainer] fix the GA model_accepts_loss_kwargs (huggingface#34915)
Browse files Browse the repository at this point in the history
* fix

* style

* values

* fix
  • Loading branch information
ArthurZucker authored Dec 5, 2024
1 parent e682c17 commit a928d9c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,7 @@ def __init__(
else unwrapped_model.get_base_model().forward
)
forward_params = inspect.signature(model_forward).parameters
self.model_accepts_loss_kwargs = (
"loss_kwargs" in forward_params and forward_params["loss_kwargs"].kind == inspect.Parameter.VAR_KEYWORD
)
self.model_accepts_loss_kwargs = any(k.kind == inspect.Parameter.VAR_KEYWORD for k in forward_params.values())

self.neftune_noise_alpha = args.neftune_noise_alpha

Expand Down Expand Up @@ -3651,7 +3649,10 @@ def training_step(
return loss_mb.reduce_mean().detach().to(self.args.device)

with self.compute_loss_context_manager():
loss = self.compute_loss(model, inputs, num_items_in_batch=num_items_in_batch)
if self.model_accepts_loss_kwargs:
loss = self.compute_loss(model, inputs)
else:
loss = self.compute_loss(model, inputs, num_items_in_batch=num_items_in_batch)

del inputs
if (
Expand Down

0 comments on commit a928d9c

Please sign in to comment.