Skip to content

[V1] Change return type on get_multimodal_embeddings()#19446

Merged
russellb merged 1 commit intovllm-project:mainfrom
russellb:mm-api-return-type
Jun 16, 2025
Merged

[V1] Change return type on get_multimodal_embeddings()#19446
russellb merged 1 commit intovllm-project:mainfrom
russellb:mm-api-return-type

Conversation

@russellb
Copy link
Copy Markdown
Member

The return type implied that None was a valid return value, but the
code does not treat it that way. sanity_check_mm_encoder_outputs() in
vllm.v1.worker.utils is called on the output and does not allow None.

While we're at it, also change the input parameter type to the sanity
check function. Previously, it was specified as object, but it should
be MultiModalEmbeddings.

Implementations of the method can still return an empty list if
necessary.

Signed-off-by: Russell Bryant rbryant@redhat.com

@github-actions
Copy link
Copy Markdown

👋 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
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @russellb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses type hint inaccuracies related to multimodal embeddings. The get_multimodal_embeddings method was incorrectly marked as potentially returning None, while downstream code expected a MultiModalEmbeddings object. This change updates the type hints to accurately reflect the code's behavior and improves type safety.

Highlights

  • Type Hint Correction: Corrected the return type hint for the get_multimodal_embeddings method across various model implementations and the SupportsMultiModal interface from Optional[MultiModalEmbeddings] to MultiModalEmbeddings.
  • Sanity Check Type Update: Updated the type hint for the mm_embeddings parameter in the sanity_check_mm_encoder_outputs function to MultiModalEmbeddings, aligning it with the expected input type.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mergify mergify bot added llama Related to Llama models v1 labels Jun 10, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly identifies and addresses an inconsistency in the return type of get_multimodal_embeddings. By removing Optional from the return type and updating the sanity_check_mm_encoder_outputs function to expect MultiModalEmbeddings, the type hints become more precise and align better with the actual usage.

The primary feedback is to ensure that all implementations of get_multimodal_embeddings that previously returned None are updated to return an empty list ([]) to conform to the new non-optional type hint, as implied by the PR description. This will prevent potential type errors and ensure consistency across all multimodal models.

Copy link
Copy Markdown
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 fixing! The code change makes sense to me. cc @DarkLight1337 if you want to take a look too.

@ywang96 ywang96 added the ready ONLY add when PR is ready to merge/full CI is needed label Jun 11, 2025
@russellb
Copy link
Copy Markdown
Member Author

It looks like this broke some multi-modal tests. I'll take a look.

The return type implied that `None` was a valid return value, but the
code does not treat it that way. `sanity_check_mm_encoder_outputs()` in
`vllm.v1.worker.utils` is called on the output and does not allow None.

While we're at it, also change the input parameter type to the sanity
check function. Previously, it was specified as `object`, but it should
be `MultiModalEmbeddings`.

Implementations of the method can still return an empty list if
necessary.

Signed-off-by: Russell Bryant <rbryant@redhat.com>
@russellb russellb force-pushed the mm-api-return-type branch from 36c2c10 to f13bf8f Compare June 14, 2025 16:36
@russellb russellb merged commit 90f9c2e into vllm-project:main Jun 16, 2025
71 checks passed
@maxdebayser
Copy link
Copy Markdown
Contributor

@russellb, this commit is breaking tests like samplers/test_beam_search.py::test_beam_search_passes_multimodal_data because in a lot of places like

if multimodal_embeddings is not None:
because they still compare the multimodal inputs with None.

@russellb
Copy link
Copy Markdown
Member Author

@russellb, this commit is breaking tests like samplers/test_beam_search.py::test_beam_search_passes_multimodal_data because in a lot of places like

if multimodal_embeddings is not None:

because they still compare the multimodal inputs with None.

I guess these tests aren't running in CI always since CI was green here? Sorry for the trouble.

@russellb
Copy link
Copy Markdown
Member Author

I'm working on fixes.

russellb added a commit to russellb/vllm that referenced this pull request Jun 16, 2025
This is a follow up to PR vllm-project#19446.

In that PR, get_multimodal_embeddings() was changed to return
`MultiModalEmbeddings` instead of `Optional[MultiModalEmbeddings]`
because code in the model runner was requiring that the result was not
`None`.

Several models needed tweaks to account for this. Many were missed
because they were not tested in CI. This should fix the rest of the
common changes needed that weren't caught by CI.

Signed-off-by: Russell Bryant <rbryant@redhat.com>
@russellb
Copy link
Copy Markdown
Member Author

follow up here: #19715

russellb added a commit to russellb/vllm that referenced this pull request Jun 18, 2025
This is a follow up to PR vllm-project#19446.

In that PR, get_multimodal_embeddings() was changed to return
`MultiModalEmbeddings` instead of `Optional[MultiModalEmbeddings]`
because code in the model runner was requiring that the result was not
`None`.

Several models needed tweaks to account for this. Many were missed
because they were not tested in CI. This should fix the rest of the
common changes needed that weren't caught by CI.

Signed-off-by: Russell Bryant <rbryant@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llama Related to Llama models ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants