Skip to content

Conversation

@bbeckca
Copy link
Contributor

@bbeckca bbeckca commented Jul 31, 2025

Purpose

This PR migrates OvisImagePatchInputs 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

(venv) benjibeck@Benjis-MacBook-Pro vllm % python3 -m pytest tests/utils_/test_tensor_schema.py -v --log-cli-level=DEBUG          
========================================================================== test session starts ==========================================================================
platform darwin -- Python 3.9.6, pytest-8.4.1, pluggy-1.6.0 -- /Users/benjibeck/Projects/vllm/venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/benjibeck/Projects/vllm
configfile: pyproject.toml
plugins: anyio-4.9.0
collected 19 items                                                                                                                                                      

tests/utils_/test_tensor_schema.py::test_tensor_schema_valid_tensor PASSED                                                                                        [  5%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_optional_fields PASSED                                                                                     [ 10%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_constant_dim_failure PASSED                                                                                [ 15%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_invalid_types_in_list PASSED                                                                               [ 21%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_rank_mismatch PASSED                                                                                       [ 26%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_missing_required_field PASSED                                                                              [ 31%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_symbolic_dim_mismatch PASSED                                                                               [ 36%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_list_tensor_valid PASSED                                                                                   [ 42%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_variable_patch_counts_valid PASSED                                                                         [ 47%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_tuple_tensor_valid PASSED                                                                                  [ 52%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_inconsistent_shapes_in_list PASSED                                                                         [ 57%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_empty_list PASSED                                                                                          [ 63%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_validation_disabled_skips_shape_check PASSED                                                               [ 68%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_with_valid_resolve_binding_dims PASSED                                                                     [ 73%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_with_invalid_resolve_binding_dims PASSED                                                                   [ 78%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_with_list_of_symbolic_dim PASSED                                                                           [ 84%]
tests/utils_/test_tensor_schema.py::test_tensor_schema_with_list_of_symbolic_dim_mismatch_in_length PASSED                                                        [ 89%]
tests/utils_/test_tensor_schema.py::test_valid_tensor_schema_with_static_last_dim PASSED                                                                          [ 94%]
tests/utils_/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 pull request successfully migrates OvisImagePatchInputs from a TypedDict to a TensorSchema, which improves input validation and code clarity. However, a field rename introduces a breaking change because its usages elsewhere in the file were not updated. I've provided a critical comment with a suggestion to revert the rename to ensure the code remains functional.

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, LGTM now

@DarkLight1337 DarkLight1337 added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 21, 2025
@bbeckca
Copy link
Contributor Author

bbeckca commented Aug 22, 2025

Update: Working on failing MM test for:

[2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     image_input = self._parse_and_validate_image_input(**kwargs)
--
"/usr/local/lib/python3.12/dist-packages/vllm/model_executor/models/ovis.py", line 459, in _parse_and_validate_image_input
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     return OvisImagePatchInputs(
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]            ^^^^^^^^^^^^^^^^^^^^^
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]   File "/usr/local/lib/python3.12/dist-packages/vllm/utils/tensor_schema.py", line 67, in __init__
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     self.validate()
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]   File "/usr/local/lib/python3.12/dist-packages/vllm/utils/tensor_schema.py", line 222, in validate
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     self._validate_tensor_shape_expected(
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]   File "/usr/local/lib/python3.12/dist-packages/vllm/utils/tensor_schema.py", line 138, in _validate_tensor_shape_expected
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     raise ValueError(f"{field_name} has rank {len(actual_shape)} "
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708] ValueError: flat_data has rank 4 but expected 2
``

@bbeckca
Copy link
Contributor Author

bbeckca commented Aug 22, 2025

Update: Working on failing MM test for:

[2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     image_input = self._parse_and_validate_image_input(**kwargs)
--
"/usr/local/lib/python3.12/dist-packages/vllm/model_executor/models/ovis.py", line 459, in _parse_and_validate_image_input
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     return OvisImagePatchInputs(
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]            ^^^^^^^^^^^^^^^^^^^^^
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]   File "/usr/local/lib/python3.12/dist-packages/vllm/utils/tensor_schema.py", line 67, in __init__
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     self.validate()
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]   File "/usr/local/lib/python3.12/dist-packages/vllm/utils/tensor_schema.py", line 222, in validate
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     self._validate_tensor_shape_expected(
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]   File "/usr/local/lib/python3.12/dist-packages/vllm/utils/tensor_schema.py", line 138, in _validate_tensor_shape_expected
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708]     raise ValueError(f"{field_name} has rank {len(actual_shape)} "
  | [2025-08-22T04:45:50Z] (EngineCore_0 pid=8358) ERROR 08-21 21:45:50 [core.py:708] ValueError: flat_data has rank 4 but expected 2
``

@DarkLight1337 @Isotr0py Before trying to fix, I wanted to check whether expected format for OvisImagePatchInputs.flat_data should be 2D or 4D? Observed Fuyu using flat_data with 2 dims, but it's not clear to me whether Ovis should have the same. Trying to understand whether this issue is with the annotation or processor inputs.

class OvisImagePatchInputs(TypedDict):
    type: Literal["image_patches"]
    flat_data: torch.Tensor
    """
    Shape: 
    `(batch_size * num_patches, patch_size_x * patch_size_y * num_channels)`
    """

> /home/bbeckca/vllm/vllm/utils/tensor_schema.py(139)_validate_tensor_shape_expected()
-> raise ValueError(f"{field_name} has rank {len(actual_shape)} "
(Pdb) expected_shape
('batch_patches', 'patch_size')
(Pdb) actual_shape
torch.Size([30, 3, 448, 448])

@mergify
Copy link

mergify bot commented Sep 1, 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

@mergify mergify bot added the needs-rebase label Sep 1, 2025
Signed-off-by: Benji Beck <benjibeck@meta.com>
Signed-off-by: Benji Beck <benjibeck@meta.com>
Signed-off-by: Benji Beck <benjibeck@meta.com>
@DarkLight1337 DarkLight1337 merged commit 1fa1d6a into vllm-project:main Sep 2, 2025
41 checks passed
eicherseiji pushed a commit to eicherseiji/vllm that referenced this pull request Sep 9, 2025
Signed-off-by: Benji Beck <benjibeck@meta.com>
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
Signed-off-by: Benji Beck <benjibeck@meta.com>
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.

2 participants