Dear all,
I was training an LLM using ORPO based on the guides by Maxime Labonne .
Unfortunately, I encountered the following error on the code below:
Trainer.tokenizer is now deprecated. You should use Trainer.processing_class instead.
Trying to resolve it by using the processing_class in the way suggested by Gemini/ChatGPT did not resolve the problem. Does anyone have an idea how to resolve this?
Kind regards,
Ben
orpo_args = ORPOConfig(
learning_rate=8e-6,
beta=0.1,
lr_scheduler_type="linear",
max_length=1024,
max_prompt_length=512,
per_device_train_batch_size=2,
per_device_eval_batch_size=2,
gradient_accumulation_steps=4,
optim="paged_adamw_8bit",
#Ideally train 3-5 epochs
num_train_epochs=1,
evaluation_strategy="steps",
eval_steps=0.2,
logging_steps=1,
warmup_steps=10,
report_to="wandb",
output_dir="./results/",
)
trainer = ORPOTrainer(
model=model,
args=orpo_args,
train_dataset=dataset["train"],
eval_dataset=dataset["test"],
peft_config=peft_config,
tokenizer=tokenizer,
)
trainer.train()
trainer.save_model(new_model)
1 Like
It appears that an issue has been issued on github and fixed. The date is yesterday, so I’m not sure if it has been reflected yet.
opened 09:30AM - 20 Oct 24 UTC
fixed - pending confirmation
I can use orpo without issues with transformers 4.45.2 and orpo_trainer.train(),… the old way of starting the training loop.
When I use the new unsloth_train(orpo_trainer) for gradient_accumulation fix the following error shows up:
```
{
"name": "KeyError",
"message": "'labels'",
"stack": "---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[13], line 3
1 from unsloth import unsloth_train
----> 3 trainer_stats = unsloth_train(orpo_trainer)
5 # orpo_trainer.train()
7 model.save_pretrained(\"lora_model_final\") # Local saving
File c:\\work\\ModelTraining\\LocalUnsloth\\venv_LocalUnsloth\\lib\\site-packages\\unsloth\\trainer.py:41, in unsloth_train(trainer)
35 def unsloth_train(trainer):
36 print(
37 \"Unsloth: Using our custom gradient accumulation fixed trainer, which is not feature complete.\
\"\\
38 \"If you want to use our fix inside of HF, please update `transformers` to the latest version via:\
\"\\
39 '`pip uninstall transformers -y && pip install --upgrade --no-cache-dir \"git+https://github.com/huggingface/transformers.git\"`'
40 )
---> 41 return _unsloth_train(trainer)
File c:\\work\\ModelTraining\\LocalUnsloth\\venv_LocalUnsloth\\lib\\site-packages\\unsloth_zoo\\training_utils.py:258, in unsloth_train(trainer)
255 batches = [next(train_dataloader_iterator) for j in range(n_batches)]
257 # Count non zeros before loss calc
--> 258 n_items = torch.stack([
259 torch.count_nonzero(x[\"labels\"][..., 1:] != -100) for x in batches
260 ]).sum()
262 # Gradient accumulation
263 for batch in batches:
File c:\\work\\ModelTraining\\LocalUnsloth\\venv_LocalUnsloth\\lib\\site-packages\\unsloth_zoo\\training_utils.py:259, in <listcomp>(.0)
255 batches = [next(train_dataloader_iterator) for j in range(n_batches)]
257 # Count non zeros before loss calc
258 n_items = torch.stack([
--> 259 torch.count_nonzero(x[\"labels\"][..., 1:] != -100) for x in batches
260 ]).sum()
262 # Gradient accumulation
263 for batch in batches:
KeyError: 'labels'"
}
```
When I upgrade transformers to the newest version as recommended 4.46.0.dev0
I get these errors on both ways of starting the training:
```
{
"name": "AttributeError",
"message": "'generator' object has no attribute 'generate'",
"stack": "---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[10], line 3
1 from unsloth import unsloth_train
----> 3 trainer_stats = unsloth_train(orpo_trainer)
5 # orpo_trainer.train()
7 model.save_pretrained(\"lora_model_final\") # Local saving
File c:\\work\\ModelTraining\\LocalUnsloth\\venv_LocalUnsloth\\lib\\site-packages\\unsloth\\trainer.py:32, in unsloth_train(trainer)
31 def unsloth_train(trainer):
---> 32 return trainer.train()
File c:\\work\\ModelTraining\\LocalUnsloth\\venv_LocalUnsloth\\lib\\site-packages\\transformers\\trainer.py:2112, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
2110 hf_hub_utils.enable_progress_bars()
2111 else:
-> 2112 return inner_training_loop(
2113 args=args,
2114 resume_from_checkpoint=resume_from_checkpoint,
2115 trial=trial,
2116 ignore_keys_for_eval=ignore_keys_for_eval,
2117 )
File <string>:326, in _fast_inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)
File c:\\work\\ModelTraining\\LocalUnsloth\\venv_LocalUnsloth\\lib\\site-packages\\trl\\trainer\\orpo_trainer.py:852, in ORPOTrainer.get_batch_samples(self, model, batch)
849 generate_context_manager = amp.autocast(\"cuda\") if self._peft_has_been_casted_to_bf16 else nullcontext()
851 with generate_context_manager:
--> 852 policy_output = model.generate(
853 input_ids=batch[\"prompt_input_ids\"],
854 attention_mask=batch[\"prompt_attention_mask\"],
855 max_length=self.max_length,
856 do_sample=True,
857 pad_token_id=self.tokenizer.pad_token_id,
858 )
860 policy_output = pad_to_length(policy_output, self.max_length, self.tokenizer.pad_token_id)
861 policy_output_decoded = self.tokenizer.batch_decode(policy_output, skip_special_tokens=True)
AttributeError: 'generator' object has no attribute 'generate'"
}
```
My local env is:
🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
==((====))== Unsloth 2024.10.3: Fast Qwen2 patching. Transformers = 4.46.0.dev0.
\\ /| GPU: NVIDIA GeForce RTX 3090. Max memory: 23.999 GB. Platform = Windows.
O^O/ \_/ \ Pytorch: 2.4.0+cu121. CUDA = 8.6. CUDA Toolkit = 12.1.
\ / Bfloat16 = TRUE. FA [Xformers = 0.0.27.post2. FA2 = False]
"-____-" Free Apache license: http://github.com/unslothai/unsloth
But I also tried it with a linux cloud station running cuda 9 and 12.4 + torch 2.4.0
The errors are the same.
Tried to use qwen 14B and llama 3.2 3B.
Errors are the same.
And on a second note when trying to prepare the dataset the Orpo-Trainer throws this warning:
`Trainer.tokenizer is now deprecated. You should use Trainer.processing_class instead.`
While it still works the massiv wall of prints is eating up cpu power and slowing down the data-prep.
You can surpress this with this code:
```
import warnings
from transformers import logging as transformers_logging
warnings.filterwarnings("ignore")
transformers_logging.set_verbosity_error()
```
But a clear updated code how to setup the trainer might be the cleaner solution.
Thanks for looking into this ^^
1 Like
Hi John,
thanks for highlighting this - apparently it hasn’t been reflected yet. Will probably keep trying in the following days.
In a local environment, this change alone would be a workaround, but it would be best to wait until it is fixed for the latest version.
pip uninstall transformers
pip install transformers==4.45.2
2 Likes
Dear John,
thanks for helping a newbie – that literally fixed all my problems and stupid me didn’t think of just using the previous transformers version.
1 Like
It’s not a solution, it’s a workaround, but, well, better to have it work than not to have it work!
system
Closed
October 25, 2024, 10:26pm
7
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.