Skip to content

Support embedding models in V1 #16188

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 98 commits into from
Jun 19, 2025
Merged

Conversation

maxdebayser
Copy link
Contributor

@maxdebayser maxdebayser commented Apr 7, 2025

This PR proposes an implementation path to support embedding models in V1. The basic idea is to take a different path than in V0 where there were completely different code bases for decoder models and encoder only models. Since the difference between decoder and encoder only models boils down to the attention mask and what is done to the hidden states at the end, in this PR I'm trying to add the minimum amount of changes required to the engine, the scheduler and the model runner to get embeddings working end-to-end.

In the current shape if this PR, Bert models are already running. The next steps are to enable the other embedding models in our unit tests.

The goal of this PR is to get V1 in a shape from where we can refactor the code base towards the a generic hidden states processor implementation: #12249

cc: @DarkLight1337

maxdebayser and others added 7 commits March 24, 2025 15:59
Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
Encoder-only models can also benefit from the prefix caching that is
enabled by the kv cache

Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
This is only passing mypy, it hasn't been tested
yet

Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
... and disable cuda graphs for these models.

Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
Copy link

github-actions bot commented Apr 7, 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.

🚀

@mergify mergify bot added v1 tpu Related to Google TPUs labels Apr 7, 2025
Copy link

mergify bot commented Apr 7, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @maxdebayser.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Apr 7, 2025
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

I'm done with my initial review. Will test later. Can @njhill @robertgshaw2-redhat also take a look at this?

Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
@mergify mergify bot added the frontend label Apr 8, 2025
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
@mergify mergify bot removed the needs-rebase label Apr 8, 2025
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
@mergify mergify bot removed the needs-rebase label Jun 13, 2025
Comment on lines +406 to +412
# chunked prefill has to be enabled explicitly to allow
# pooling requests to be chunked
if not self.scheduler_config.chunked_prefill_enabled and \
num_new_tokens > token_budget:
self.waiting.popleft()
skipped_waiting_requests.appendleft(request)
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this could potentially cause a starvation problem, but it seems to be ok at least for the pooling/embedding models

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, because the requests that skip ahead of the one that doesn't fit in the budget are processed and leave the waiting queue, right? So in theory, in the next call to schedule the skipped request will be in front of the queue and should be processed unless it was to big to fit max_model_len or max_batch_tokens to begin with. And if chunked prefill is disabled, there will never be running requests so the token budget should still be 100% when schedule reaches the processing of the waiting queue.

Copy link

mergify bot commented Jun 16, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @maxdebayser.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Jun 16, 2025
Copy link
Collaborator

@WoosukKwon WoosukKwon left a comment

Choose a reason for hiding this comment

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

@maxdebayser @22quinn LGTM overall. Thanks again for all the efforts in this PR!

Left some minor comments. Please take a look.

Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
@mergify mergify bot removed the needs-rebase label Jun 16, 2025
@maxdebayser
Copy link
Contributor Author

@WoosukKwon , one of the failing tests depends on this fix: #19686 .
The second test is failing due to an error introduced in this PR: #19446 . The third one is failing with AttributeError: module 'triton.language' has no attribute 'bfloat16', but I haven't figured out yet where that error is coming from.

@russellb
Copy link
Member

@WoosukKwon , one of the failing tests depends on this fix: #19686 . The second test is failing due to an error introduced in this PR: #19446 . The third one is failing with AttributeError: module 'triton.language' has no attribute 'bfloat16', but I haven't figured out yet where that error is coming from.

regarding the error from #19446, here's the follow-up: #19715

that should address cases that weren't caught in the CI run on #19446 ...

@maxdebayser
Copy link
Contributor Author

Thanks, @russellb!

@maxdebayser
Copy link
Contributor Author

There is already a fix for the third problem as well: #19734. Thanks @mgoin

@mergify mergify bot added the qwen Related to Qwen models label Jun 18, 2025
Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
@WoosukKwon WoosukKwon merged commit 799397e into vllm-project:main Jun 19, 2025
63 of 67 checks passed
@DarkLight1337
Copy link
Member

Thanks for your hard work! Can you update the V1 guide with the latest status?

@maxdebayser
Copy link
Contributor Author

Thanks @DarkLight1337 and @22quinn for all your help. Is the doc update by @22quinn ok for now?

Comment on lines -1352 to -1356
# No Embedding Models so far.
if model_config.task not in ["generate"]:
_raise_or_fallback(feature_name=f"--task {model_config.task}",
recommend_to_remove=False)
return False
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to enable all tasks here?

TaskOption = Literal["auto", "generate", "embedding", "embed", "classify",
                     "score", "reward", "transcription"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll double check the "transcription" task, but the others yes. Is this causing a problem?

Copy link
Member

Choose a reason for hiding this comment

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

Nope, it just caused a conflcit in my branch where I had enabled "transcription" and thought maybe it had enabled more than you intended. It's fine if you mean to!

I'm not sure about transcription, either. I know it wouldn't work with whisper, but that'll still get blocked because the model is marked as v0-only. Since all models should have the V0-only marker where needed, this check probably isn't necessary.

@DarkLight1337
Copy link
Member

Thanks @DarkLight1337 and @22quinn for all your help. Is the doc update by @22quinn ok for now?

Yeah it looks good!

yeqcharlotte pushed a commit to yeqcharlotte/vllm that referenced this pull request Jun 22, 2025
Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Co-authored-by: 22quinn <33176974+22quinn@users.noreply.github.com>
minpeter pushed a commit to minpeter/vllm that referenced this pull request Jun 24, 2025
Signed-off-by: Max de Bayser <mbayser@br.ibm.com>
Signed-off-by: Max de Bayser <maxdebayser@gmail.com>
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Co-authored-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: minpeter <kali2005611@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation frontend qwen Related to Qwen models ready ONLY add when PR is ready to merge/full CI is needed structured-output tpu Related to Google TPUs v1
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

9 participants