Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTTrainer using quantized model + peft does not work #1055

Closed
osanseviero opened this issue Dec 3, 2023 · 3 comments · Fixed by #1064
Closed

SFTTrainer using quantized model + peft does not work #1055

osanseviero opened this issue Dec 3, 2023 · 3 comments · Fixed by #1064
Labels
⚡ PEFT Related to PEFT 🏋 SFT Related to SFT

Comments

@osanseviero
Copy link
Contributor

osanseviero commented Dec 3, 2023

Example code from the official docs fails due to this

from datasets import load_dataset
from transformers import AutoModelForCausalLM
from trl import SFTTrainer

dataset = load_dataset("timdettmers/openassistant-guanaco", split="train")

peft_config = LoraConfig(
    r=16,
    lora_alpha=32,
    lora_dropout=0.05,
    bias="none",
    task_type="CAUSAL_LM",
)

model = AutoModelForCausalLM.from_pretrained(
    "EleutherAI/gpt-neo-125m",
    load_in_8bit=True,
    device_map="auto",
)

trainer = SFTTrainer(
    model,
    train_dataset=dataset,
    dataset_text_field="text",
    peft_config=peft_config,
)

Error logs

AttributeError                            Traceback (most recent call last)
[<ipython-input-3-ffcd404fb112>](https://localhost:8080/#) in <cell line: 18>()
     16 )
     17 
---> 18 trainer = SFTTrainer(
     19     model,
     20     train_dataset=dataset,

[/usr/local/lib/python3.10/dist-packages/trl/trainer/sft_trainer.py](https://localhost:8080/#) in __init__(self, model, args, data_collator, train_dataset, eval_dataset, tokenizer, model_init, compute_metrics, callbacks, optimizers, preprocess_logits_for_metrics, peft_config, dataset_text_field, packing, formatting_func, max_seq_length, infinite, num_of_sequences, chars_per_token, dataset_num_proc, dataset_batch_size, neftune_noise_alpha, model_init_kwargs)
    169                     )
    170 
--> 171                     preprare_model_kwargs = {"use_gradient_checkpointing": args.gradient_checkpointing}
    172 
    173                     if _support_gc_kwargs:

AttributeError: 'NoneType' object has no attribute 'gradient_checkpointing'

Versions

transformers==4.35.2
trl==0.7.5.dev0 (install from source; I also tried from last release with same error).

Additional Info

If I pass my own TrainingArguments with gradient_checkpointing=True then all is fine.
Specifically, this line https://github.com/huggingface/trl/blob/main/trl/trainer/sft_trainer.py#L171 won't work if args is None.

@elliotttruestate
Copy link

What is the specific source of that example code?

The example script here https://github.com/huggingface/trl/blob/main/examples/scripts/sft.py provides an expected input and code structure.

@osanseviero
Copy link
Contributor Author

@lvwerra
Copy link
Member

lvwerra commented Dec 5, 2023

cc @younesbelkada

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ PEFT Related to PEFT 🏋 SFT Related to SFT
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants