Repository navigation
fix(vision): honour checkpoint pixel bounds in eager Qwen3-VL processor - #3316
Merged
Merged
Conversation
Eager Qwen3-VL resized images against the Qwen2-VL family defaults (min_pixels 3136) with Lanczos3, while HF and the XLA host preprocessor use the checkpoint's size.shortest_edge / longest_edge (65536 / 16777216) and its bicubic resample. A 224x224 image became 49 image tokens on eager and 64 on XLA and HF, one cause of the eager vs XLA divergence found in #3212. A new shared reader, QwenImageResizePolicy, resolves bounds and resampler from the nested processor_config.json image_processor block first and preprocessor_config.json second, with explicit min_pixels / max_pixels before size. qwen_vl_processor_with_norm applies it, so Qwen3-VL, Qwen3-VL MoE, Qwen3.5 / 3.6 / 3.8, Qwen3-Omni, Qwen4-Exp and Cohere Compass all resize as HF does; the XLA Qwen3-VL loader validates the same policy instead of parsing its own. Compass's private bound reader is folded in. Malformed or inverted bounds and unsupported resample codes now fail the load. Qwen2-VL, Qwen2.5-VL and GLM-4V keep their processor. Validated with the new policy unit tests (including a 224x224 -> grid [1,16,16], 64 token gate through the real loader helper), the qwen, compass, clef and mage lib test filters, and eager vs XLA real-model runs. Closes #3290
Member
Author
Implementation Review SummaryIntent
Findings AddressedNone needed fixing on the branch: no CRITICAL or HIGH findings. Remaining Items
Verification
|
…ze overflow-safe A crafted processor_config.json or preprocessor_config.json could state min_pixels or max_pixels in the trillions. smart_resize then upscaled every image to an allocation-exhausting size, and its u32 `h * w` products wrapped in release builds (panicked in debug), producing a wrong grid and image-token count. The policy reader now rejects either bound above 2^28 pixels (16384 x 16384; real checkpoints use 16777216 at most). smart_resize does its arithmetic in saturating u64 and clamps the result to u32 instead of multiplying u32 edges. Validated with the new oversized-bound and huge-input tests plus the existing qwen_image_policy and qwen2_vl suites. The xla-iree feature could not be built here (IREE_DIST is not provisioned on this host), so the XLA loader path was reviewed but not compiled. Refs #3290
Member
Author
|
Security and performance review of the sidecar reader, the eager and XLA Qwen3-VL loaders, and
Tests: new oversized-bound and huge-input tests pass along with the existing |
QwenImageResizePolicy merged the nested processor_config.json image_processor block and preprocessor_config.json key by key. HF transformers 5.x picks one whole source instead: the nested block when present, otherwise the standalone file, with missing keys taking the class defaults (3136 / 12845056 / bicubic). The policy now does the same, and a new test pins a nested block without bounds next to a standalone file that has them. Qwen3-VL-Embedding and the Qwen3-VL reranker re-applied preprocessor_config.json min/max on top of the loader through a private apply_pixel_bounds whose comment still said the loader used Qwen2-VL defaults. load_qwen3_vl already applies the shared policy, so the duplicate is removed. Validation: a scan of the 97 local checkpoints with processor sidecars resolves the same bounds, resampler and validation outcome under both rules. Refs #3290
…vl-pixel-bounds # Conflicts: # CHANGELOG.md
inureyes
marked this pull request as ready for review
November 23, 2026 09:10
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eager Qwen3-VL resized images against the Qwen2-VL family defaults (
min_pixels3136) with Lanczos3, while HF and the XLA host preprocessor resize against the checkpoint'ssize.shortest_edge/size.longest_edge(65536 / 16777216) with bicubic. Ontests/fixtures/test_image.png(224x224) eager saw 49 image tokens where XLA and HF see 64.QwenImageResizePolicy(src/loading/vlm_qwen_image_policy.rs) selects one whole sidecar as HF 5.x does: the nestedprocessor_config.jsonimage_processorblock when present, otherwisepreprocessor_config.json; keys the chosen source omits take the class defaults (3136 / 12845056 / bicubic). Within the source, explicitmin_pixels/max_pixelswin oversize. A checkpoint with no sidecar keeps the historical defaults. Over the 97 local checkpoints that ship a sidecar, whole-source selection and the earlier key-by-key merge resolve identically.smart_resize(src/vision/processors/qwen2_vl.rs) now uses saturating u64 arithmetic, so a crafted sidecar or a huge image cannot wrap the grid and image-token count.qwen_vl_processor_with_normapplies it, so every caller follows: Qwen3-VL, Qwen3-VL MoE, Qwen3.5 / 3.6 / 3.8, Qwen3-Omni MoE, Qwen4-Exp and Cohere Compass. Compass's private bound reader is folded into the shared one (it keeps 16384 / 3868706 and 49 tokens) and now resamples bicubic. Qwen3-Omni keeps 3136 / 12845056 and only changes resampler. Qwen3-VL-Embedding and the Qwen3-VL reranker drop their duplicateapply_pixel_boundsand take the same policy throughload_qwen3_vl, so they now resize bicubic (embedding values and rerank scores shift slightly; bounds unchanged).resample=3) instead of parsing its own.resamplecodes now fail the load rather than falling back.qwen_vl_processorand are untouched.Real-model results (GB10,
-n 64 --temp 0, "Describe this image.")Qwen2.5-VL XLA matches eager up to EOS (the missing stop is #3292). Smoke runs: Qwen3-VL 30B-A3B MoE 64 tokens, coherent; Qwen3.5-0.8B 49 to 64 tokens, same greedy ids; North-Micro-Vision 49 tokens, ids identical to main.
Test plan
cargo test --profile test-fast --features cuda,xla-iree --lib -- qwen_image_policy qwen3_vl_iree_processor_policy(12 passed, including the 224x224 to 64-token gate through the real loader helper)qwen(663 passed) andcompass clef mage(1010 passed),--test-threads=1qwen_image_policy qwen3_vl_iree_processor_policy qwen2_vl(30 passed),qwen3_vl_embedding qwen3_vl_generative cohere_compass(44 passed), real-model rerun (64 image tokens, index 8 = 4285)cargo check --features cuda,xla-iree --all-targets,cargo check --no-default-features --features xla-diagnostics --all-targets,cargo clippy -p mlxcel --features cuda,xla-iree --lib --tests -- -D warnings,cargo fmt --checkCloses #3290