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

tokenizers.apply_chat_template with continue_final_message=True with trailing spaces in input #35433

Open
1 of 4 tasks
chuyishang opened this issue Dec 27, 2024 · 0 comments
Open
1 of 4 tasks
Labels

Comments

@chuyishang
Copy link

chuyishang commented Dec 27, 2024

System Info

As title says, tokenizers.apply_chat_template fails with trailing spaces in input for Llama-3.1-Instruct.

If the last assistant message has a trailing space, such as
{'role': 'assistant', 'content': 'some text "}

and continue_final_message is True, it throws a "ValueError: substring not found"

This is because in the apply_chat_template function, there is a line
rendered_chat = rendered_chat[: rendered_chat.rindex(final_message) + len(final_message)].rstrip()

but rendered_chat ends with "some text<|eot_id|>" while the final_message still has the trailing space: "some text "

Who can help?

@ArthurZucker @itazap

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

See above

Expected behavior

I expect it to be able to continue after the trailing space

@chuyishang chuyishang added the bug label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant