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

Misleading warning message about pad_token_id when passing tokenizer instance to pipeline #29378

Closed
4 tasks
tilmanbeck opened this issue Feb 29, 2024 · 3 comments · Fixed by #29614
Closed
4 tasks

Comments

@tilmanbeck
Copy link

tilmanbeck commented Feb 29, 2024

System Info

Python=3.11.5
Transformers= '4.37.2'

In my setup I am initializing a tokenizer and want to pass it to the pipeline. My expectation is that if I set the pad_token_id directly on tokenizer instance, the pipeline should not print the warning Setting pad_token_id to eos_token_id:50256 for open-end generation. If I pass the pad_token_id directly to the pipeline's __call__, the warning is not printed. However, I would rather like to set the pad_token_id directly rather than having to think about everytime I use the __call__ method of the pipeline.

Alternatively, I would like to add it as a parameter to the pipeline instantiation, but I think passing tokenizer parameters in the pipeline generator is currently not envisioned, as discussed in #12039 #24707 #22995

@Narsil

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

Here is a minimal code example to demonstrate the difference:

from transformers import AutoTokenizer, pipeline, AutoModelForCausalLM, Conversation

msg = 'The capital of France '
modelname = 'microsoft/DialoGPT-small'

# hand over model & tokenizer instantiations to pipeline
model = AutoModelForCausalLM.from_pretrained(modelname)
tokenizer = AutoTokenizer.from_pretrained(modelname)
tokenizer.pad_token_id = tokenizer.eos_token_id

chatbot = pipeline(task='conversational', model=model, tokenizer=tokenizer, framework='pt')
messages = ([{"role": "system", "content": 'You are a helpful assistant'}, {"role": "user", "content": msg}])
response = chatbot(Conversation(messages=messages))

This prints the warning message
Setting 'pad_token_id' to 'eos_token_id':50256 for open-end generation.

The following code does not:

from transformers import AutoTokenizer, pipeline, AutoModelForCausalLM, Conversation

msg = 'The capital of France '
modelname = 'microsoft/DialoGPT-small'

chatbot = pipeline(task='conversational', model=modelname, framework='pt')
messages = ([{"role": "system", "content": 'You are a helpful assistant'}, {"role": "user", "content": msg}])
response = chatbot(Conversation(messages=messages), pad_token_id=chatbot.tokenizer.eos_token_id)

Expected behavior

I would expect the first code snippet not to print the warning as the pad_token_id is directly set on the tokenizer instance

@ArthurZucker
Copy link
Collaborator

cc @Rocketknight1

@Rocketknight1
Copy link
Member

This issue and #29379 feel a bit like generation issues to me - @gante do you see any obvious solutions? If not, don't worry, I'll investigate.

@gante
Copy link
Member

gante commented Mar 12, 2024

Hi @tilmanbeck 👋

The root issue is that the tokenizer and the model are two separate objects, so pad_token_id needs to be set in both. In pipeline, IMO model should inherit pad_token_id from tokenizer when it is not set there. Opening a PR to fix that :)

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