-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[Frontend] OpenAI API server: Do not add bos token by default when encoding #4688
[Frontend] OpenAI API server: Do not add bos token by default when encoding #4688
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment in the code for this?
Have you checked whether this would affect the usage of the example templates in vLLM? I don't think that the examples include BOS tokens. |
Hi @DarkLight1337, You mean this one? I think it's the same llama-3-8b-instruct reuploaded by NousResearch? So they have the same chat template. Also got repeated 128000 for this model:
Here are a few examples from other models: https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1/blob/main/tokenizer_config.json#L42 https://huggingface.co/microsoft/Phi-3-mini-128k-instruct/blob/main/tokenizer_config.json#L119 https://huggingface.co/CohereForAI/c4ai-command-r-plus/blob/main/tokenizer_config.json#L304 |
I am referring to the ones that are in vLLM repo, not those on HuggingFace. |
Certainly, done @simon-mo |
@DarkLight1337 I got your point. I'm not familiar with all these models, but falcon-instruct doesn't use the BOS token, so this PR won't affect it. Here is a test with falcon-7b-instruct. # server
python -m vllm.entrypoints.openai.api_server \
--model tiiuae/falcon-7b-instruct \
--chat-template examples/template_falcon.jinja \
--dtype float16
# client
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "tiiuae/falcon-7b-instruct",
"messages": [
{"role": "user", "content": "Hi!"}
],
"temperature": 0
}' Before this commit:
After this commit:
They have the same prompt token IDs, where 7932 represents "User". I believe the idea of the chat template is to include all special tokens, as explained in the doc. So we should just update these templates if necessary.
|
It would be great if you could add some test cases to avoid regression issues. |
@DarkLight1337 can you help take another look and let me know whether this is mergable? |
The CI tests fail so those have to be addressed first. |
Thanks for pointing that out. I tried to fix it but still encountered issues. I don't quite understand the error since "Any" has been imported. It passed on my end, though. |
Try merging the current main branch into your branch. |
aa91ba0
to
57e5f09
Compare
Oh, you are right. It was deleted in this PR. Just added it back. |
Seems that the existing tests assume the addition of bos token. Can you update them accordingly? |
Please also check whether this is consistent with the behaviour of the official OpenAI API. |
Hey, could you point me to the relevant tests?
Which behavior would you like to check? |
You can check the logs of the failing tests in CI.
Whether |
Just realized that the modified However, we only need to disable |
Not sure I fully understand. Why should we compare input ( |
Originally I wasn't sure whether you should modify the existing tests or update the tests to comply with the new behaviour. If it's the latter than I wanted to make sure that it doesn't violate any invariants in OpenAI's API. Now that the tests pass I guess it can be merged now. @simon-mo |
@DarkLight1337 thanks for the discussion! |
Hi,
I noticed that the BOS token is always duplicated when running with the OpenAI API server. As shown in the console output below when launching Meta-Llama-3-8B-Instruct, there are two repeated 128000 (
bos_token_id
) at the beginning ofprompt_token_ids
.After investigating, I found that this happens because the chat template already includes the BOS token (AFAIK as is common practice in most cases). However, the encoding step adds it again due to
add_special_tokens
being enabled by default.vllm/vllm/entrypoints/openai/serving_engine.py
Line 206 in 0f9a6e3
https://github.com/huggingface/transformers/blob/5962d62bac850cd01ee830ffba880469338c96fd/src/transformers/tokenization_utils_base.py#L2808
A simple fix is to disable the
add_special_tokens
, as is done in theapply_chat_template
function of Transformers (whentokenize=True
).https://github.com/huggingface/transformers/blob/5962d62bac850cd01ee830ffba880469338c96fd/src/transformers/tokenization_utils_base.py#L1820-L1829
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Model]
for adding a new model or improving an existing model. Model name should appear in the title.[Frontend]
For changes on the vLLM frontend (e.g., OpenAI API server,LLM
class, etc.)[Kernel]
for changes affecting CUDA kernels or other compute kernels.[Core]
for changes in the core vLLM logic (e.g.,LLMEngine
,AsyncLLMEngine
,Scheduler
, etc.)[Hardware][Vendor]
for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]
).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
format.sh
to format your code.docs/source/
if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-required
and might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-required
label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!