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

[Frontend] Chat-based Embeddings API #9759

Merged
merged 46 commits into from
Nov 1, 2024
Merged

Conversation

DarkLight1337
Copy link
Member

@DarkLight1337 DarkLight1337 commented Oct 28, 2024

This PR extends the existing Embeddings API to accept chat conversations similar to Chat Completions API. This enables multi-modal conversations to be passed to the embedding model.

To reduce code duplication, I've also factored out the common code for handling completion and chat-based inputs into the base OpenAIServing class.

FIX #8967
FIX #9303 (comment)

Copy link

👋 Hi! Thank you for contributing to the vLLM project.
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 do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

@DarkLight1337 DarkLight1337 changed the title Chat embeddings api [Frontend] Chat-based Embeddings API Oct 28, 2024
@mergify mergify bot added documentation Improvements or additions to documentation frontend labels Oct 28, 2024
Copy link

mergify bot commented Oct 29, 2024

This pull request has merge conflicts that must be resolved before it can be
merged. @DarkLight1337 please rebase it. 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 Oct 29, 2024
@mergify mergify bot removed the needs-rebase label Oct 29, 2024
@DarkLight1337
Copy link
Member Author

Sorry for the commit spam, I'm done refining the docs now.

@DarkLight1337
Copy link
Member Author

Entrypoints tests pass now.

Copy link
Collaborator

@Isotr0py Isotr0py left a comment

Choose a reason for hiding this comment

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

Overall LGTM since entrypoint tests all passed. See if @ywang96 is OK with the frontend refactor as well.

@DarkLight1337
Copy link
Member Author

DarkLight1337 commented Oct 31, 2024

@simon-mo @njhill do you have time to take a look at this? @ywang96 is busy today.

Copy link
Contributor

@maxdebayser maxdebayser left a comment

Choose a reason for hiding this comment

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

I left a few comments but overall this looks good to me.

Since VLM2Vec has the same model architecture as Phi-3.5-Vision, we have to explicitly pass ``--task embedding``
to run this model in embedding mode instead of text generation mode.

Since this schema is not defined by OpenAI client, we post a request to the server using the lower-level ``requests`` library:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just leaving this as a thought here: should we perhaps have a fork of the openai client that support our extensions explicitly?

Copy link
Member Author

Choose a reason for hiding this comment

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

This sounds good, but not sure whether we have bandwidth to maintain it 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I suggest opening an issue for this.

tests/entrypoints/openai/test_embedding.py Show resolved Hide resolved
@@ -7,7 +7,7 @@ class PoolingParams(
msgspec.Struct,
omit_defaults=True, # type: ignore[call-arg]
array_like=True): # type: ignore[call-arg]
"""Pooling parameters for pooling.
"""Pooling parameters for embeddings API.
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be missing something, but the additional_data attribute doesn't seem to be used anywhere. Which is good, because it can by anything and is passed without validation from the request to the Pooler.forward() method as part of the PoolingMetadata object. If there is no use case for this, can we remove it in this PR?

Copy link
Member Author

@DarkLight1337 DarkLight1337 Nov 1, 2024

Choose a reason for hiding this comment

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

@robertgshaw2-neuralmagic originally added this (#4800 (comment)). I am not sure whether this is still relevant since we can now set the pooling strategy via CLI (#9697).

Copy link
Member Author

Choose a reason for hiding this comment

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

@robertgshaw2-neuralmagic can you comment on this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Meanwhile let's merge this PR first.

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.

Left a few comments - PTAL!

docs/source/models/vlm.rst Outdated Show resolved Hide resolved
tests/entrypoints/openai/test_embedding.py Show resolved Hide resolved
vllm/entrypoints/openai/protocol.py Show resolved Hide resolved
vllm/entrypoints/openai/serving_embedding.py Outdated Show resolved Hide resolved
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!

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) November 1, 2024 05:58
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Nov 1, 2024
@DarkLight1337 DarkLight1337 merged commit 06386a6 into main Nov 1, 2024
69 checks passed
@DarkLight1337 DarkLight1337 deleted the chat-embeddings-api branch November 1, 2024 08:13
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 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.

[RFC]: Reward Modelling in OpenAI Compatible Server
4 participants