Skip to content

No label_names provided for model class PeftModelForCausalLM. Since PeftModel hides base models input arguments, if label_names is not given, label_names can't be set automatically within Trainer. #1788

Closed

Description

@Ahmed-Hassany

I am trying to fine-tune unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit with the help of the notebook: [](https://colab.research.google.com/drive/1WZDi7APtQ9VsvOrQSSC5DDtxq159j8iZ
And I get the error whenever I run the following code:)

from trl import SFTTrainer
from transformers import TrainingArguments
from unsloth import is_bfloat16_supported

trainer = SFTTrainer(
    model = model,
    tokenizer = tokenizer,
    train_dataset = train_df,
    # eval_dataset = val_df,
    dataset_text_field = "text",
    # formatting_func=formatting_func,
    max_seq_length = max_seq_length,
    dataset_num_proc = 1,
    packing = False, # Can make training 5x faster for short sequences.
    args = TrainingArguments(
        per_device_train_batch_size = 2,
        gradient_accumulation_steps = 4,
        warmup_steps = 5,
        # max_steps = 60,
        num_train_epochs = 5, # For longer training runs!
        learning_rate = 2e-4,
        fp16 = not is_bfloat16_supported(),
        bf16 = is_bfloat16_supported(),
        logging_steps = 1,
        optim = "adamw_8bit",
        weight_decay = 0.01,
        lr_scheduler_type = "linear",
        seed = 3407,
        output_dir = "outputs",
        report_to = "wandb", # Use this for WandB etc
    ),
)

The Error message:
No label_names provided for model class PeftModelForCausalLM. Since PeftModelhides base models input arguments, if label_names is not given, label_names can't be set automatically withinTrainer. Note that empty label_names list will be used instead.

Activity

  1. wwwzwbz commented on Feb 22, 2025

    @wwwzwbz

    Same, have you figured out why?

  2. danielhanchen commented on Feb 22, 2025

    @danielhanchen
    Member

    Oh I thought I hid this by now! Try updating Unsloth pip install --upgrade --no-cache-dir --no-deps unsloth

  3. Ahmed-Hassany commented on Feb 22, 2025

    @Ahmed-Hassany
    Author

    Oh I thought I hid this by now! Try updating Unsloth pip install --upgrade --no-cache-dir --no-deps unsloth

    Yes, now it works after updating from 2025.2.14 to 2025.2.15 thanks.

  4. Septemberlemon commented on Mar 23, 2025

    @Septemberlemon

    Oh I thought I hid this by now! Try updating Unsloth pip install --upgrade --no-cache-dir --no-deps unsloth

    I didn't use Unsloth but got the warning, too

    from transformers import BitsAndBytesConfig, AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer
    from peft import get_peft_model, LoraConfig
    from datasets import load_dataset
    import torch
    
    
    model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
    quant_config = BitsAndBytesConfig(load_in_4bit=True,
                                      bnb_4bit_compute_dtype=torch.float16,
                                      )
    model = AutoModelForCausalLM.from_pretrained(model_name,
                                                 quantization_config=quant_config,
                                                 device_map="auto",
                                                 attn_implementation="flash_attention_2",
                                                 )
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    tokenizer.pad_token = tokenizer.eos_token
    
    # 配置 LoRA 参数
    lora_config = LoraConfig(r=8,
                             lora_alpha=32,
                             target_modules=["q_proj", "v_proj"],
                             lora_dropout=0.1,
                             bias="none",
                             )
    model = get_peft_model(model, lora_config)
    
    # 加载数据集
    dataset = load_dataset("json",
                           data_files={
                               "train": "train_data.jsonl",
                               "validation": "val_data.jsonl"},
                           )
    
    
    def preprocess_function(examples):
        # 根据任务将指令、输入、输出拼接为一个完整的文本
        texts = [f"Instruction: {inst}\nInput: {inp}"
                 for inst, inp in zip(examples["instruction"], examples["input"])]
        return tokenizer(texts,
                         text_target=examples["output"],
                         truncation=True, padding="max_length",
                         max_length=512,
                         )
    
    
    # 应用预处理
    tokenized_dataset = dataset.map(preprocess_function,
                                    batched=True,
                                    remove_columns=dataset["train"].column_names,  # 自动移除原始列
                                    )
    
    # 调整训练参数
    training_args = TrainingArguments(output_dir="./qlora_finetuned",
                                      per_device_train_batch_size=2,
                                      per_device_eval_batch_size=2,
                                      num_train_epochs=3,
                                      eval_strategy="steps",  # 替换过时的evaluation_strategy
                                      logging_steps=10,
                                      save_steps=50,
                                      fp16=True,
                                      remove_unused_columns=False,  # 重要:防止自动删除必要列
                                      )
    
    # 初始化Trainer
    trainer = Trainer(model=model,
                      args=training_args,
                      train_dataset=tokenized_dataset["train"],
                      eval_dataset=tokenized_dataset["validation"],
                      )
    
    # 开始训练
    trainer.train()

    Can someone tell me what's the problem?

  5. El-Bahnasawi commented on Apr 2, 2025

    @El-Bahnasawi

    add this line in TrainingArguments: label_names=["labels"]. PeftModel hides the base model so you need to re-specify the labels.

  6. GuoXian0729 commented on Apr 20, 2025

    @GuoXian0729

    I had the same error, but my task was a text generation class and there were no label names. And when I explicitly provided an empty list as the labelnames argument, I got the error: TypeError: Qwen2_5_VLForConditionalGeneration.init() got an unexpected keyword argument 'label_names'

  7. ge85tow commented on May 1, 2025

    @ge85tow

    add this line in TrainingArguments: label_names=["labels"]. PeftModel hides the base model so you need to re-specify the labels.

    I also face the error of '''got an unexpected keyword argument 'label_names''''

  8. rajydv commented on Jun 8, 2025

    @rajydv

    add this line in TrainingArguments: label_names=["labels"]. PeftModel hides the base model so you need to re-specify the labels.

    Thanks @El-Bahnasawi

    • Does this argument has any effect on model training?
    • I'm fine-tuning text generation tasks, in case I have to provide this label_names=["labels"] what does it mean if training dataset is in chat format like this
    <|im_start|>system
    You are a spelling corrector for an e-commerce marketplace.
    After review, OUTPUT ONLY the full corrected query, with no extra text or explanation.<|im_end|>
    <|im_start|>user
    Query: nike shos<|im_end|>
    <|im_start|>assistant
    <think>
    
    </think>
    
    nike shoes<|im_end|>
    
    

    I'm not using unsloth, using LoraConfig and SFTConfig from peft and trl library respectively.

  9. steveepreston commented on Sep 30, 2025

    @steveepreston

    @Septemberlemon @GuoXian0729 @rajydv Did you find any answer?
    I faced this in non-unsloth env

  10. danielhanchen commented on Jun 17, 2026

    @danielhanchen
    Member

    This issue should be fixed now - sorry on the delay - please update with uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir - if the issue is still there, please open another issue - appreciate it again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions