Skip to content

Conversation

@bbeckca
Copy link
Contributor

@bbeckca bbeckca commented Jul 30, 2025

Purpose

This PR migrates MiniCPMVImageInputs from a TypedDict-based definition to a structured TensorSchema model with runtime shape validation. This brings it in line with recent changes to Phi3VImagePixelInputs, and is part of a broader effort to improve input contract enforcement and debug-ability across multi-modal models.

Test Plan

Confirm validation works via standalone tests in tests/standalone_test/test_tensor_schema.py and rely on CI to check integration.

Test Result

tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_valid_tensor PASSED                                                                                                                                      [  6%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_optional_fields PASSED                                                                                                                                   [ 12%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_constant_dim_failure PASSED                                                                                                                              [ 18%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_symbolic_dim_mismatch PASSED                                                                                                                             [ 25%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_list_tensor_valid PASSED                                                                                                                                 [ 31%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_variable_patch_counts_valid PASSED                                                                                                                       [ 37%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_tuple_tensor_valid PASSED                                                                                                                                [ 43%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_inconsistent_shapes_in_list PASSED                                                                                                                       [ 50%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_empty_list PASSED                                                                                                                                        [ 56%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_validation_disabled_skips_shape_check PASSED                                                                                                             [ 62%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_with_valid_resolve_binding_dims PASSED                                                                                                                   [ 68%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_with_invalid_resolve_binding_dims PASSED                                                                                                                 [ 75%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_with_list_of_symbolic_dim PASSED                                                                                                                         [ 81%]
tests/standalone_tests/test_tensor_schema.py::test_tensor_schema_with_list_of_symbolic_dim_mismatch_in_length PASSED                                                                                                      [ 87%]
tests/standalone_tests/test_tensor_schema.py::test_valid_tensor_schema_with_static_last_dim PASSED                                                                                                                        [ 93%]
tests/standalone_tests/test_tensor_schema.py::test_invalid_tensor_schema_with_static_last_dim PASSED                                                                                                                      [100%]

@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 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
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 PR migrates MiniCPMVImageInputs to TensorSchema. I've provided comments on the TensorShape definitions and a missing check that could cause regressions for variable-sized inputs.

Comment on lines 90 to 95
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The TensorShape for pixel_values does not correctly handle variable image sizes, which could lead to validation failures for valid inputs. The height (h) and width (w) dimensions can differ between tensors in the pixel_values list. Without marking h and w as dynamic, TensorSchema validation will require all tensors in the list to have the same shape. This is a regression from the previous TypedDict-based implementation and would cause validation to fail for valid inputs with varying image sizes.

pixel_values: Annotated[
    list[torch.Tensor],
    TensorShape("bns", 3, "h", "w", dynamic_dims={"h", "w"}),
]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we're fine to leave as is since this wasn't enforced and values aren't used in any symbolic cross field checks.

Comment on lines +113 to +118
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The TensorShape for image_embeds does not account for a variable number of slices, which could lead to validation failures. The TensorShape does not seem to account for a variable number of slices (ns) when image_embeds is a list of tensors. Each tensor in the list corresponds to an image and has a shape of (num_slices, hidden_size). If num_slices can vary per image, this will cause validation to fail. To support this, ns should be marked as a dynamic dimension.

image_embeds: Annotated[
    Union[torch.Tensor, list[torch.Tensor]],
    TensorShape("bn", "ns", "hs", dynamic_dims={"ns"}),
]

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 wasn't enforced previously, so I haven't added any validations. Feel free to let me know if we should make ns dynamic dim.

@bbeckca bbeckca force-pushed the minicpmv branch 2 times, most recently from 4fe5136 to a6adcd8 Compare August 7, 2025 14:32
@mergify
Copy link

mergify bot commented Aug 10, 2025

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

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@Isotr0py Isotr0py added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 11, 2025
@vllm-bot vllm-bot merged commit 4678503 into vllm-project:main Aug 12, 2025
38 of 43 checks passed
paulpak58 pushed a commit to paulpak58/vllm that referenced this pull request Aug 13, 2025
diegocastanibm pushed a commit to diegocastanibm/vllm that referenced this pull request Aug 15, 2025
yiliu30 pushed a commit to yiliu30/vllm-fork that referenced this pull request Aug 19, 2025
epwalsh pushed a commit to epwalsh/vllm that referenced this pull request Aug 28, 2025
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 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.

3 participants