Skip to content

[BugFix][Multi Modal] Fix TensorSchema shape mismatch in Molmo#24559

Merged
vllm-bot merged 2 commits intovllm-project:mainfrom
wwl2755:fix-molmo
Sep 10, 2025
Merged

[BugFix][Multi Modal] Fix TensorSchema shape mismatch in Molmo#24559
vllm-bot merged 2 commits intovllm-project:mainfrom
wwl2755:fix-molmo

Conversation

@wwl2755
Copy link
Contributor

@wwl2755 wwl2755 commented Sep 10, 2025

Number of crops would be dynamic in different images, so need to make it dynamic.

Fix: #24544

Related: #22022

cc: @bbeckca @DarkLight1337

Test

python -m vllm.entrypoints.openai.api_server --model allenai/Molmo-7B-D-0924 --trust-remote-code

vllm bench serve   --backend openai-chat   --endpoint-type openai-chat   --model allenai/Molmo-7B-D-0924   --endpoint /v1/chat/completions   --dataset-name hf   --dataset-path lmarena-ai/VisionArena-Chat   --hf-split train   --hf-output-len 1   --num-prompts 10   --seed 40

Result

============ Serving Benchmark Result ============
Successful requests:                     10        
Benchmark duration (s):                  1.15      
Total input tokens:                      816       
Total generated tokens:                  10        
Request throughput (req/s):              8.70      
Output token throughput (tok/s):         8.70      
Total Token throughput (tok/s):          719.00    
---------------Time to First Token----------------
Mean TTFT (ms):                          695.62    
Median TTFT (ms):                        549.66    
P99 TTFT (ms):                           1132.05   
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          0.00      
Median TPOT (ms):                        0.00      
P99 TPOT (ms):                           0.00      
---------------Inter-token Latency----------------
Mean ITL (ms):                           0.02      
Median ITL (ms):                         0.02      
P99 ITL (ms):                            0.02      
==================================================

Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
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 shape mismatch issue in the Molmo model by correctly marking the 'number of crops' (nc) dimension as dynamic. This is a crucial fix for handling batches of images that produce a variable number of crops. My review identifies a related issue where the 'token sequence positions' (tp) dimension, which can also vary between images, was not marked as dynamic. I've suggested a fix to prevent potential validation errors.

Comment on lines +91 to +93
feat_is_patch: Annotated[
Union[torch.Tensor, list[torch.Tensor]],
TensorShape("bn", "nc", "tp", dynamic_dims={"nc"})]
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The number of token sequence positions (tp) can also be dynamic for different images, similar to the number of crops (nc). The number of tokens depends on the image's height and width. To prevent potential ValueError during tensor shape validation when processing a batch of images with varying sizes, tp should also be marked as a dynamic dimension.

Suggested change
feat_is_patch: Annotated[
Union[torch.Tensor, list[torch.Tensor]],
TensorShape("bn", "nc", "tp", dynamic_dims={"nc"})]
feat_is_patch: Annotated[
Union[torch.Tensor, list[torch.Tensor]],
TensorShape("bn", "nc", "tp", dynamic_dims={"nc", "tp"})]

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! This model wasn't covered by CI because of its requirement conflicts 😅

@Isotr0py Isotr0py added the ready ONLY add when PR is ready to merge/full CI is needed label Sep 10, 2025
@DarkLight1337
Copy link
Member

DarkLight1337 commented Sep 10, 2025

Thanks, cc @Isotr0py we should make the test more robust to catch this case

@Isotr0py Isotr0py enabled auto-merge (squash) September 10, 2025 05:35
@vllm-bot vllm-bot merged commit 4c04eef into vllm-project:main Sep 10, 2025
51 of 53 checks passed
@wwl2755 wwl2755 deleted the fix-molmo branch September 11, 2025 00:06
@bbeckca
Copy link
Contributor

bbeckca commented Sep 11, 2025

Thanks @wwl2755 for the fix!

skyloevil pushed a commit to skyloevil/vllm that referenced this pull request Sep 13, 2025
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
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.

[Bug]: TensorSchema validation fails for allenai/Molmo-7B-D-0924

6 participants