Skip to content

Validate Qwen vision embedding output - #2511

Merged
Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
msrc/qwen-vl-embedding-bounds
Sep 10, 2026
Merged

Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
msrc/qwen-vl-embedding-bounds

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request improves the robustness of vision embedding injection in the Qwen2.5-VL model by centralizing and expanding validation of tensor shapes and element types, and by adding targeted unit tests. The main changes ensure that runtime errors due to shape mismatches or invalid data types are caught early and handled with clear error messages.

Validation improvements:

  • Added a new function ValidateVisionEmbeddingShapes in qwen_vl_model.h to check that embeddings and vision feature tensors have the correct rank, matching dimensions, and sufficient size for all input tokens.
  • Updated InjectVisionEmbeddings in qwen_vl_model.cpp to call ValidateVisionEmbeddingShapes and to explicitly check that the embeddings tensor contains float elements, throwing descriptive exceptions otherwise. [1] [2]

Testing:

  • Added a new unit test QwenVisionEmbeddingShapeValidation in model_tests.cpp to verify that valid shapes pass and invalid shapes throw the expected runtime errors.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens Qwen2.5-VL vision embedding injection by centralizing validation of embedding/vision tensor shapes and adding a focused unit test to ensure invalid shapes fail fast with clear runtime errors.

Changes:

  • Added Generators::ValidateVisionEmbeddingShapes to validate embedding/vision tensor ranks, dims, and token capacity.
  • Updated Qwen2_5_VL_PipelineState::InjectVisionEmbeddings to reuse the centralized shape validation and to reject non-float embedding outputs early.
  • Added a C++ unit test covering valid/invalid vision embedding shape scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
test/cpp/model_tests.cpp Adds a unit test for the new shape validation helper.
src/models/qwen_vl_model.h Introduces centralized vision embedding shape validation helper.
src/models/qwen_vl_model.cpp Uses centralized validation and adds explicit float element-type check before embedding injection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/models/qwen_vl_model.h Outdated
Comment thread src/models/qwen_vl_model.h
Comment thread test/cpp/model_tests.cpp
Comment thread src/models/qwen_vl_model.cpp
@apsonawane
Akshay Sonawane (apsonawane) merged commit 0be47e3 into main Sep 10, 2026
65 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the msrc/qwen-vl-embedding-bounds branch September 10, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants