Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bugfix] Fix Positive Feature Layers in Llava Models #13514

Merged

Conversation

alex-jw-brooks
Copy link
Contributor

@alex-jw-brooks alex-jw-brooks commented Feb 19, 2025

This PR fixes two small issues with positive feature layers in llava models.

  • There is an off by one indexing inconsistency compared to transformers when there are multiple feature layers used (e.g., IBM's granite vision models). E.g., if you consider a model with 24 visual encoder blocks:

    • In vLLM, we use only the output of the visual encoder blocks, i.e., [hs0, hs1, ..., hs23]
    • In transformers, the input to the visual encoder is also part of the hidden_states, i.e., [input_embed, hs0, hs1, ..., hs23] - Example in the Clip visual encoder can be found here
  • One extra layer is loaded - When the vision feature layer is positive, the layer count is one higher than the corresponding negative index, e.g., given a model with 24 visual encoder blocks, feature layer -1 produces the same output as 23, but this should be 24 since 0 should correspond to the input embedding. This also breaks if you request 24 since it tries to load one more layer than it should

Note that most llava models use one feature layer that's typically negative, so generally don't hit these cases

Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
Copy link

👋 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
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.

LGTM, thanks for fixing!

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) February 19, 2025 06:46
@@ -438,7 +438,7 @@ def _get_layer_index(feature_layer_index: int, num_hidden_layers: int) -> int:
"""
if feature_layer_index < 0:
return num_hidden_layers + feature_layer_index + 1
return feature_layer_index + 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the cause for the extra block being loaded, e.g., given num_hidden_layers=24, feature_layer_index=-1 produces 24, but feature_layer_index=24 produces 25

@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Feb 19, 2025
@alex-jw-brooks
Copy link
Contributor Author

Awesome, thanks for the quick review Cyrus! 😄

@DarkLight1337 DarkLight1337 merged commit 983a40a into vllm-project:main Feb 19, 2025
61 checks passed
xjpang pushed a commit to xjpang/vllm that referenced this pull request Feb 20, 2025
)

Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
kerthcet pushed a commit to kerthcet/vllm that referenced this pull request Feb 21, 2025
)

Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
Akshat-Tripathi pushed a commit to krai/vllm that referenced this pull request Mar 3, 2025
)

Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
lk-chen pushed a commit to lk-chen/vllm that referenced this pull request Mar 5, 2025
)

Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
Signed-off-by: Linkun Chen <github@lkchen.net>
Said-Akbar pushed a commit to Said-Akbar/vllm-rocm that referenced this pull request Mar 7, 2025
)

Signed-off-by: Alex-Brooks <Alex.brooks@ibm.com>
Signed-off-by: saeediy <saidakbarp@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # 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.

2 participants