pythondeep-learningneural-networkhuggingface-transformershuggingface

SFTTrainer: The specified `eos_token` ('<EOS_TOKEN>') is not found in the vocabulary of the given `processing_class` (Qwen2TokenizerFast)


I upgraded my Python trl package to version 0.18.1. I use the SFTTrainer of the package to finetune a Qwen2.5 LLM neural net. Previously, I used the TrainingArgument class to set additional params. I migrated them to SFTConfig. My trainer now looks like this:

trainer = SFTTrainer(
        model=model,
        processing_class=tokenizer,
        train_dataset=train_dataset,
        eval_dataset=eval_dataset,
        data_collator=DataCollatorForSeq2Seq(tokenizer=tokenizer),
        callbacks=[train_log_callback],
        args=SFTConfig(
            per_device_train_batch_size=per_device_train_batch_size,
            gradient_accumulation_steps=gradient_accumulation_steps,
            warmup_steps=warmup_steps,
            num_train_epochs=max_epochs,
            max_steps=max_steps,
            max_seq_length=block_size,
            learning_rate=learning_rate,
            fp16=not is_bfloat16_supported(),
            bf16=is_bfloat16_supported(),
            logging_steps=logging_steps,
            optim="paged_adamw_8bit",
            weight_decay=0.01,
            lr_scheduler_type="linear",
            seed=random_seed,
            eval_strategy="epoch" if eval_dataset is not None else "no",
            save_strategy="no",
            output_dir="models",
            save_steps=50,
            report_to="none",
            packing=False,
            dataset_text_field="text",
            eos_token="<|im_end|>", # eos token is set!
        ),
)

I set my tokenizer to processing_class and manually set the eos token as well to match the eos token in the Qwen2TokenizerFast class (class of my tokenizer).

It seems like that during the creation of the trainer, the eos_token param is exchanged by <EOS_TOKEN> as shown in the error message (title).

Having a look at the SFTTrainer class, during the creation, it is checked if the eos string is available in the vocab:\

eos_token = args.eos_token # should be "<|im_end|>"
eos_token_id = processing_class.convert_tokens_to_ids(eos_token)
if eos_token_id is None:
    raise ValueError(...)

My args.eos_token value seems to be magically changed to <EOS_TOKEN> which is the wrong eos value leading to this "token not found error".

Where is the mistake I'm doing that leads to the error?

Lastly, it may be an interesting information that I use unsloth as well. Maybe it changes something in the background?


Solution

  • I got the same issue, it looks like unsloth is changing something under the hood. I fix the issue by making sure unsloth is imported BEFORE trl.

    
    from unsloth import FastLanguageModel
    from trl import SFTTrainer, SFTConfig
    

    my package version:

    trl==0.18.2

    unsloth==2025.6.2