[trainer] fix pt loss (#7748)

* fix pt loss

* robust

* fix

* test
This commit is contained in:
hoshi-hiyouga
2025-04-17 03:15:35 +08:00
committed by GitHub
parent 86ebb219d6
commit 39169986ef
10 changed files with 34 additions and 34 deletions

View File

@@ -40,6 +40,11 @@ class CustomTrainer(Trainer):
kwargs["processing_class"] = kwargs.pop("tokenizer")
super().__init__(**kwargs)
if processor is not None:
# avoid wrong loss under gradient accumulation
# https://github.com/huggingface/transformers/pull/36044#issuecomment-2746657112
self.model_accepts_loss_kwargs = False
self.finetuning_args = finetuning_args
if processor is not None:

View File

@@ -60,6 +60,8 @@ class CustomSeq2SeqTrainer(Seq2SeqTrainer):
super().__init__(**kwargs)
if processor is not None:
# avoid wrong loss under gradient accumulation
# https://github.com/huggingface/transformers/pull/36044#issuecomment-2746657112
self.model_accepts_loss_kwargs = False
self.finetuning_args = finetuning_args