Skip to content

💭 [Data] Fix DeepSeek-R1 case #3522

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

Merged
merged 12 commits into from
Jun 4, 2025
Merged

Conversation

kashif
Copy link
Collaborator

@kashif kashif commented Jun 2, 2025

What does this PR do?

fixes the issue that:

  1. When applying a chat template to just the prompt with add_generation_prompt=True, DeepSeek's tokenizer would add <think> tokens
  2. When applying the chat template to the full conversation (prompt + completion), no <think> tokens were added
  3. The function tried to extract the completion by using prompt_completion[len(prompt):], but since the strings didn't match at the beginning, it would fail the startswith check

We now add add_generation_prompt=False to all calls that apply chat templates to full conversations (prompt + completion/chosen/rejected) to ensure consistency.

Fixes #3490

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@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.

@kashif kashif requested a review from qgallouedec June 2, 2025 12:54
@qgallouedec
Copy link
Member

Nice, just a quick question, this issue occurs with DeepSeek-v3 but not with DeepSeek-v3-0528, right?

@kashif
Copy link
Collaborator Author

kashif commented Jun 2, 2025

@qgallouedec checking!

@kashif
Copy link
Collaborator Author

kashif commented Jun 3, 2025

@qgallouedec yes correct no issue with DeepSeek-v3-0528 on main

Comment on lines -141 to -154
# Ensure that the prompt is the initial part of the prompt-completion string
if "prompt" in example:
error_message = (
"The chat template applied to the prompt + completion does not start with the chat template applied to "
"the prompt alone. This can indicate that the chat template is not supported by TRL."
"\n**Prompt**:\n{}\n\n**Prompt + Completion**:\n{}"
)
if "chosen" in example and not prompt_chosen.startswith(prompt):
raise ValueError(error_message.format(prompt, prompt_chosen))
if "rejected" in example and not prompt_rejected.startswith(prompt):
raise ValueError(error_message.format(prompt, prompt_rejected))
if "completion" in example and not prompt_completion.startswith(prompt):
raise ValueError(error_message.format(prompt, prompt_completion))

Copy link
Member

Choose a reason for hiding this comment

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

This can't occur anymore

@qgallouedec qgallouedec changed the title [Data] Added add_generation_prompt=False to chat template [Data] Fix DeepSeek-R1 case Jun 4, 2025
@qgallouedec qgallouedec changed the title [Data] Fix DeepSeek-R1 case 💭 [Data] Fix DeepSeek-R1 case Jun 4, 2025
@qgallouedec qgallouedec merged commit 6ffde23 into huggingface:main Jun 4, 2025
10 checks passed
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.

Converting a conversational dataset into a standard dataset [not working]
4 participants