Skip to content

Conversation

qionghuang6
Copy link
Contributor

@qionghuang6 qionghuang6 commented May 6, 2025

When using the bad_words SamplingParam with Mistral models with V1, bad_words compiles incorrectly.
For example, when bad_words=["the"] _bad_words_token_ids is [[1, 3265]] when it should be [[3265]], so the word "the" is never matched.

We fix this by setting add_special_tokens=False for all tokenizers when we generate _bad_words_token_ids

It seems that for non-Mistral models too, we don't want to add the special tokens either, so it's a little unclear why this logic was included, as other models like Llama also include start of sequence tokens.
image

We can replicate this bug with any Mistral model using the original e2e testing code from #13376

@github-actions
Copy link

github-actions bot commented May 6, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

Copy link
Member

@ywang96 ywang96 left a comment

Choose a reason for hiding this comment

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

Thanks for the bugfix! LGTM but I think the following code needs to be updated as well?

if isinstance(tokenizer, MistralTokenizer):
# Mistral tokenizers should not add special tokens
prompt_token_ids = tokenizer.encode(text=prompt)
else:
prompt_token_ids = tokenizer.encode(text=prompt,
add_special_tokens=False)

Comment on lines -495 to -497
if isinstance(tokenizer, MistralTokenizer):
# Mistral tokenizers should not add special tokens
prompt_token_ids = tokenizer.encode(text=prompt)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the issue was caused by the BOS token so this makes sense

if add_special_tokens is not None:
return self.tokenizer.encode(text,
bos=add_special_tokens,
eos=add_special_tokens)
else:
return self.tokenizer.encode(text, bos=True, eos=False)

@qionghuang6
Copy link
Contributor Author

Thanks for the bugfix! LGTM but I think the following code needs to be updated as well?

if isinstance(tokenizer, MistralTokenizer):
# Mistral tokenizers should not add special tokens
prompt_token_ids = tokenizer.encode(text=prompt)
else:
prompt_token_ids = tokenizer.encode(text=prompt,
add_special_tokens=False)

Ah yes, I only updated it for V1. Just added it now

@qionghuang6 qionghuang6 requested a review from ywang96 May 7, 2025 16:22
Copy link
Member

@ywang96 ywang96 left a comment

Choose a reason for hiding this comment

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

LGTM!

@ywang96 ywang96 added the ready ONLY add when PR is ready to merge/full CI is needed label May 7, 2025
@ywang96 ywang96 enabled auto-merge (squash) May 7, 2025 17:46
@vllm-bot vllm-bot merged commit 39956ef into vllm-project:main May 8, 2025
67 checks passed
princepride pushed a commit to princepride/vllm that referenced this pull request May 10, 2025
RichardoMrMu pushed a commit to RichardoMrMu/vllm that referenced this pull request May 12, 2025
mawong-amd pushed a commit to ROCm/vllm that referenced this pull request May 14, 2025
zzzyq pushed a commit to zzzyq/vllm that referenced this pull request May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants