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

[V1] Refactor model executable interface for multimodal models #10570

Merged
merged 33 commits into from
Nov 26, 2024

Conversation

ywang96
Copy link
Member

@ywang96 ywang96 commented Nov 22, 2024

This PR refactors the interface of all multimodal language models for V1 VLM re-arch and torch.compile support. In particular, all multimodal model implementations on vLLM will need to meet the following requirements:

  • get_multimodal_embeddings(**kwargs) implemented in XYZModel or XYZForConditionalGeneration
  • get_input_embeddings(input_ids, multimodal_embeddings) implemented in XYZModel or XYZForConditionalGeneration to output input embeddings to be passed to the language backbone.
  • Backward compatibility added for V0 in XYZModel or XYZForConditionalGeneration until V0 is fully deprecated.

List of LMMs to be worked on

  • BLIP2
  • Chameleon
  • GLM
  • Fuyu
  • Intern-VL
  • Llava-next
  • Llava-next-video
  • Llava-one-vision
  • Molmo
  • Paligemma
  • Pixtral
  • Qwen2VL
  • Qwen2Audio
  • Ultravox

This PR is a prerequisite of applying #9871 to all multimodal models on vLLM.

Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
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.

🚀

Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
@DarkLight1337 DarkLight1337 self-assigned this Nov 23, 2024
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
@ywang96
Copy link
Member Author

ywang96 commented Nov 25, 2024

This PR is mostly done but with a few caveats:

  1. For MiniCPMV, the multimodal embedding generation relies on input ids. It's not so clear how it can be separated from input text embedding generation. We need to tag model author to see how to separate them.
  2. For Molmo, the original implementation requires the final multimodal embedding length to match input embedding length becasue of the (+) operation. I'll leave optimizing this to a later PR.
  3. This PR does not consider mllama.

All the other models included in this PR have been tested with example scripts to ensure v0 compatibility. Full v1 compatibility will be worked in the next PR.

@ywang96 ywang96 marked this pull request as ready for review November 25, 2024 03:01
@ywang96 ywang96 requested a review from WoosukKwon as a code owner November 25, 2024 03:01
@DarkLight1337
Copy link
Member

DarkLight1337 commented Nov 25, 2024

I'm getting this error for internvl tests (tests/models/decoder_only/vision_language/test_models.py::test_single_image_models[intern_vl-test_case52]):

self = InternVLChatModel(
  (vision_model): InternVisionPatchModel(
    (embeddings): InternVisionEmbeddings(
      (patch_em...048, bias=True)
    (2): GELU(approximate='none')
    (3): Linear(in_features=2048, out_features=2048, bias=True)
  )
)
input_ids = tensor([92546, 92546, 92546,  ..., 92546, 92546, 92546], device='cuda:0')

    def _get_visual_token_mask(self, input_ids: torch.Tensor) -> torch.Tensor:
        if self.is_mono:
>           visual_token_mask = (
                input_ids == self.img_context_token_id).reshape(-1, 1)
E           AttributeError: 'bool' object has no attribute 'reshape'

vllm/model_executor/models/internvl.py:639: AttributeError

I think it's because self.img_context_token_id hasn't been set yet, so it resolves to None in the comparison expression.

Copy link

mergify bot commented Nov 26, 2024

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

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 Nov 26, 2024
@mergify mergify bot removed the needs-rebase label Nov 26, 2024
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
@ywang96
Copy link
Member Author

ywang96 commented Nov 26, 2024

I'm getting this error for internvl tests (tests/models/decoder_only/vision_language/test_models.py::test_single_image_models[intern_vl-test_case52]):

self = InternVLChatModel(
  (vision_model): InternVisionPatchModel(
    (embeddings): InternVisionEmbeddings(
      (patch_em...048, bias=True)
    (2): GELU(approximate='none')
    (3): Linear(in_features=2048, out_features=2048, bias=True)
  )
)
input_ids = tensor([92546, 92546, 92546,  ..., 92546, 92546, 92546], device='cuda:0')

    def _get_visual_token_mask(self, input_ids: torch.Tensor) -> torch.Tensor:
        if self.is_mono:
>           visual_token_mask = (
                input_ids == self.img_context_token_id).reshape(-1, 1)
E           AttributeError: 'bool' object has no attribute 'reshape'

vllm/model_executor/models/internvl.py:639: AttributeError

I think it's because self.img_context_token_id hasn't been set yet, so it resolves to None in the comparison expression.

I pushed a change which I think should be a clean fix for this. Let me know what you think!

Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
DarkLight1337 and others added 4 commits November 27, 2024 00:51
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Roger Wang <[email protected]>
@ywang96 ywang96 added the ready ONLY add when PR is ready to merge/full CI is needed label Nov 26, 2024
@ywang96 ywang96 enabled auto-merge (squash) November 26, 2024 17:42
@ywang96 ywang96 merged commit 2f0a0a1 into vllm-project:main Nov 26, 2024
60 of 63 checks passed
afeldman-nm pushed a commit to neuralmagic/vllm that referenced this pull request Dec 2, 2024
sleepwalker2017 pushed a commit to sleepwalker2017/vllm that referenced this pull request Dec 13, 2024
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