fix SFT trainer

This commit is contained in:
hiyouga 2023-10-31 21:52:52 +08:00
parent f4e4a04529
commit d8cf8cfdeb
1 changed files with 1 additions and 1 deletions

View File

@ -33,10 +33,10 @@ class CustomSeq2SeqTrainer(Seq2SeqTrainer):
Subclass and override to inject custom behavior.
"""
labels = inputs["labels"].clone() if "labels" in inputs else None # backup labels
if self.args.predict_with_generate:
assert self.tokenizer.padding_side == "left", "This method only accepts left-padded tensor."
prompt_len, label_len = inputs["input_ids"].size(-1), inputs["labels"].size(-1)
labels = inputs["labels"].clone()
if prompt_len > label_len:
inputs["labels"] = self._pad_tensors_to_target_len(inputs["labels"], inputs["input_ids"])
if label_len > prompt_len: