Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jintao-Huang committed Oct 31, 2024
1 parent 280edc3 commit d8c1d8d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions swift/trainers/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def compute_loss(self, model, inputs, return_outputs=None, **kwargs):

loss_kwargs['labels'] = labels
outputs = model(**inputs)
# fix transformers>=4.46
if outputs.loss is not None and 'num_items_in_batch' in kwargs:
outputs.loss = outputs.loss * (inputs['labels'] != -100).sum() / kwargs['num_items_in_batch']
if loss_name is not None:
loss_func = get_loss_func(loss_name)
outputs['loss'] = loss_func(outputs, **loss_kwargs)
Expand Down

0 comments on commit d8c1d8d

Please sign in to comment.