unslothai / unsloth

Finetune Llama 3.2, Mistral, Phi, Qwen 2.5 & Gemma LLMs 2-5x faster with 80% less memory
https://unsloth.ai
Apache License 2.0
18.42k stars 1.29k forks source link

An error while NOT using the train_on_response only #1102

Closed Yashar78 closed 1 month ago

Yashar78 commented 1 month ago

I am trying to finetune LLama3.2 model and I did it successfully if I add the lines below: trainer = train_on_responses_only( trainer, instruction_part = "<|start_header_id|>user<|end_header_id|>\n\n", response_part = "<|start_header_id|>assistant<|end_header_id|>\n\n", )

But if I remove those lines I get the error: File "/workspace/ft.py", line 80, in trainer_stats = trainer.train() File "", line 142, in train File "", line 363, in _fast_inner_training_loop File "/usr/local/lib/python3.10/dist-packages/transformers/trainer.py", line 3318, in training_step loss = self.compute_loss(model, inputs) File "/usr/local/lib/python3.10/dist-packages/transformers/trainer.py", line 3381, in compute_loss raise ValueError( ValueError: The model did not return a loss from the inputs, only the following keys: logits. For reference, the inputs it received are input_ids,attention_mask.

Any clue what is wrong?

danielhanchen commented 1 month ago

@Yashar78 Oh yes so the issue is you need to comment out the line data_collator = DataCollatorForSeq2Seq(tokenizer = tokenizer),

Yashar78 commented 1 month ago

@danielhanchen That worked :)