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

[core / xxxTrainer] Automatic tagging #1329

Merged
merged 4 commits into from
Feb 15, 2024
Merged

[core / xxxTrainer] Automatic tagging #1329

merged 4 commits into from
Feb 15, 2024

Conversation

younesbelkada
Copy link
Contributor

What does this PR do?

This PR injects trl / dpo / sft etc tags on the model at the trainer's init. That way models that get pushed with model.push_to_hub() will also get the correct tags instead of users that call trainer.push_to_hub

cc @lvwerra @osanseviero for awareness

@younesbelkada
Copy link
Contributor Author

Verified that this PR do not create any conflict with the previous tagging logic already in place:

import datasets
import peft
import transformers
import trl


model_dir = "HuggingFaceM4/tiny-random-LlamaForCausalLM"

tokenizer = transformers.AutoTokenizer.from_pretrained(model_dir)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"

model = transformers.AutoModelForCausalLM.from_pretrained(model_dir)

ds_train = datasets.load_dataset("imdb", split="train[:10]")

trainer = trl.SFTTrainer(
    model=model,
    args=transformers.TrainingArguments(
        output_dir="test-automatic-tagging-from-trainer",
        max_steps=1,
        remove_unused_columns=True,
    ),
    peft_config=peft.LoraConfig(
        lora_alpha=16,
        lora_dropout=0.1,
        r=8,
        bias="none",
        task_type="Causal_LM",
    ),
    train_dataset=ds_train,
    tokenizer=tokenizer,
    dataset_text_field="text",
    max_seq_length=8,
)

model.push_to_hub("ybelkada/test-automatic-tagging")
trainer.push_to_hub()

https://huggingface.co/ybelkada/test-automatic-tagging-from-trainer

https://huggingface.co/ybelkada/test-automatic-tagging

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

@philschmid philschmid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Copy link
Contributor

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

cc @kashif to also add in KTO Trainer

@kashif
Copy link
Collaborator

kashif commented Feb 15, 2024

ah yes thanks! added to #1181

@younesbelkada younesbelkada merged commit 1e77d8a into main Feb 15, 2024
9 checks passed
@younesbelkada younesbelkada deleted the add-tags-loading branch February 15, 2024 13:47
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
* automatic tagging

* add comments

* fix tests

* fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants