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

🚨🚨 TextGenerationPipeline: rely on the tokenizer default kwargs #31747

Merged
merged 2 commits into from
Jul 2, 2024

Conversation

gante
Copy link
Member

@gante gante commented Jul 2, 2024

What does this PR do?

Issue

TextGenerationPipeline.preprocess, where tokenization happens, has defined a few optional kwargs whose default value does not match the tokenizer defaults. This was causing:

  1. A mismatch between the tokens resulting from tokenizer calls and the tokens pipeline was seeing, using default arguments on both
  2. The issue seen in this thread -- add_special_tokens had to be manually set to True in the pipeline, despite it already being the default in the tokenizer.

(2 is a consequence of 1 :) )

This PR

🚨🚨 This PR changes the code to rely on the tokenizer's defaults when these flags are unset. This means some models using TextGenerationPipeline previously did not add a <bos> by default, which (negatively) impacted their performance. In practice, this is a breaking change.

Example of a script changed as a result of this PR:

from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
import torch

tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
model = AutoModelForCausalLM.from_pretrained("google/gemma-2-9b-it", torch_dtype=torch.bfloat16, device_map="auto")
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
print(pipe("Foo bar"))

@gante gante requested a review from LysandreJik July 2, 2024 13:11
@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.

@gante gante changed the title Pipeline: rely on the tokenizer default kwargs 🚨🚨 TextGenerationPipeline: rely on the tokenizer default kwargs Jul 2, 2024
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Thanks a lot @gante ! Let's keep it a bit on main to ensure it doesn't break too much the users' setups before releasing it.

@LysandreJik LysandreJik merged commit 82486e5 into huggingface:main Jul 2, 2024
21 checks passed
@pcuenca
Copy link
Member

pcuenca commented Jul 2, 2024

Very nice, I agree it makes sense to make the behaviours consistent!

loadams added a commit to microsoft/DeepSpeed that referenced this pull request Jul 30, 2024
Corresponding PR to microsoft/DeepSpeed-MII#510
that is made due to changes from transformers introduced in
huggingface/transformers#31747
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.

4 participants