Skip to content

Conversation

@yuekaizhang
Copy link
Contributor

@yuekaizhang yuekaizhang commented Aug 26, 2025

This PR fixed a bug when multimodal model and its embedding input is torch.bfloat16 tensor. Bfloat16 tensors can't be converted to numpy() directly.

Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
@github-actions
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 ask your reviewers to trigger select CI tests on top of fastcheck CI.

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.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

@mergify mergify bot added the multi-modality Related to multi-modality (#4194) label Aug 26, 2025
Copy link
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 addresses a bug where hashing torch.bfloat16 tensors would fail. The proposed fix is to convert these tensors to a different data type before converting to a NumPy array. However, the chosen torch.float16 data type has a more limited range than bfloat16, which can lead to overflow and result in hash collisions for large numerical values. I've provided a critical comment with a suggestion to convert to torch.float32 instead, which avoids this issue. It would also be beneficial to add a new test case to verify the hashing of bfloat16 tensors and prevent future regressions.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Copy link
Member

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

Thanks for fixing!

@Isotr0py Isotr0py added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 26, 2025
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.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.

Thanks for fixing

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) August 26, 2025 07:25
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.

Thanks for the fix!

@yuekaizhang
Copy link
Contributor Author

@DarkLight1337 Would you mind helping skip the failed pre-commit mypy CI tasks?

@DarkLight1337
Copy link
Member

You should fix the mypy error in this PR.

@yuekaizhang
Copy link
Contributor Author

You should fix the mypy error in this PR.

I think the CI CD error existed before the PR. I could help to fix it if you could guide me.

Running mypy on 
Error: vllm/multimodal/hasher.py:47: error: "object" has no attribute "dtype"  [attr-defined]
Error: vllm/multimodal/hasher.py:48: error: "object" has no attribute "to"  [attr-defined]
Error: vllm/multimodal/hasher.py:49: error: "object" has no attribute "numpy"  [attr-defined]

Co-authored-by: Roger Wang <hey@rogerw.io>
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
auto-merge was automatically disabled August 26, 2025 08:36

Head branch was pushed to by a user without write access

Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) August 26, 2025 09:53
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
auto-merge was automatically disabled August 26, 2025 10:17

Head branch was pushed to by a user without write access

Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
@DarkLight1337
Copy link
Member

Should be good to go now, thanks

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) August 26, 2025 10:39
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
auto-merge was automatically disabled August 26, 2025 11:18

Head branch was pushed to by a user without write access

Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.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 think this should work now

@DarkLight1337 DarkLight1337 merged commit 513298f into vllm-project:main Aug 26, 2025
36 checks passed
Comment on lines +54 to +55
"original_dtype": str(tensor_dtype),
"original_shape": tuple(tensor_obj.shape),
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for being late to the party. This is still the 1D shape of the uint8 tensor since tensor_obj is overwritten above. This should be obj.shape instead of tensor_obj.shape.

Could you extend the tests to verify the bfloat16 code path as well:

def test_hash_collision_array_shape():
# The hash should be different though the data is the same when flattened
arr1 = np.zeros((5, 10, 20, 3))
arr2 = np.zeros((10, 20, 5, 3))
hasher = MultiModalHasher
assert hasher.hash_kwargs(data=arr1) != hasher.hash_kwargs(data=arr2)

Otherwise it would cause another CVE similar to #17378

Copy link
Member

Choose a reason for hiding this comment

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

Oops, let me open another PR to fix

Copy link
Member

Choose a reason for hiding this comment

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

tc-mb pushed a commit to tc-mb/vllm that referenced this pull request Aug 27, 2025
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Roger Wang <hey@rogerw.io>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
Signed-off-by: tc-mb <caitianchi@modelbest.cn>
epwalsh pushed a commit to epwalsh/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Roger Wang <hey@rogerw.io>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Roger Wang <hey@rogerw.io>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
Signed-off-by: Xiao Yu <xiao.yu@amd.com>
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Roger Wang <hey@rogerw.io>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Sep 3, 2025
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Roger Wang <hey@rogerw.io>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Roger Wang <hey@rogerw.io>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

multi-modality Related to multi-modality (#4194) 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.

5 participants