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

add_generation_prompt=False in Tokenizer.apply_chat_template has no effect #30893

Closed
3 of 4 tasks
AndreiMuresanu opened this issue May 18, 2024 · 6 comments
Closed
3 of 4 tasks

Comments

@AndreiMuresanu
Copy link

AndreiMuresanu commented May 18, 2024

System Info

Hi, I am trying to apply a chat template to an input without the generation prompt. However, setting add_generation_prompt=False appears to have no effect.

Who can help?

@ArthurZucker @Rocketknight1

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

Minimal reproducible example:

from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")

chat = [
		{"role": "assistant", "content": "Hello, how are you?"},
	]
formatted_chat = tokenizer.apply_chat_template(chats, add_generation_prompt=False, tokenize=False)
print(formatted_chat)

transformers==4.41.0

Expected behavior

Observed Output:

<|begin_of_text|><|start_header_id|>assistant<|end_header_id|>

Hello, how are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>


Expected Output:

<|begin_of_text|><|start_header_id|>assistant<|end_header_id|>

Hello, how are you?<|eot_id|>
@Rocketknight1
Copy link
Member

Hi @AndreiMuresanu, I just tried to reproduce this and add_generation_prompt=False worked correctly for me. Can you retry your code, and make sure you're updated to the latest version of transformers?

@Taeyoung-Jang
Copy link

I have also encountered this issue.

model : Llama-3-8B-Instruct
package: transformers==4.41.1, tokenizer==0.19.1

@Rocketknight1
Copy link
Member

Can you try installing transformers from main with pip install git+https://github.com/huggingface/transformers.git? I can't reproduce this issue at all, and I'm curious if it's caused by an old cached version of the model, or some recent change, or something.

@iseesaw
Copy link

iseesaw commented May 27, 2024

same problem

@iseesaw
Copy link

iseesaw commented May 27, 2024

same problem

Solved. Because I used the initial chat template, which was later updated.

See Fix chat template to add generation prompt only if the option is selected (#9)

@Rocketknight1
Copy link
Member

Rocketknight1 commented May 27, 2024

@iseesaw thanks for pointing that one out! It seems like this was an issue with the model's chat template, which has since been resolved, and the issue will be fixed if people redownload the tokenizer. Going to close this issue now, since it's not a bug in transformers itself.

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

No branches or pull requests

5 participants