Skip to content

fix: close remaining vision resize and frame-sampling parity gaps - #3490

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-3478-vision-resize-parity
Nov 27, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-3478-vision-resize-parity

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Closes the four resize and frame-sampling parity gaps left after #3464 and #3466. Each fix lands in the existing preprocessing function, so only the inputs named below change.

  • Frame sampling: uniform_indices, evenly_spaced_indices and Gemma 4 uniform_sample_frames now round half to even, as np.linspace(...).round() does (uniform_indices(6, 3) is [0, 2, 5]). Inkling pair_adjacent_frame_indices switched too: its reference formula (issue feat(vision): Inkling native video ingestion through adjacent-frame temporal pairs #1323) uses Python round, so 12 frames in 5 pairs anchor at [0, 2, 5, 8, 10].
  • Qwen2-VL family, dots.ocr and Hunyuan-VL: the first rounding step no longer floors an edge at one factor, so a thin edge rounding to 0 takes the reference's min_pixels branch (10x1000 at factor 28 is now 28x560, as transformers gives, not 28x1008). The final result is floored at one factor only for the min_pixels == 0 case, where the reference returns a zero edge (commented). In qwen2_vl the >200:1 cap trim now also runs after the min_pixels branch, because a thin edge can now reach that branch with a long side over a small cap.
  • ERNIE 4.5 VL: every ERNIE checkpoint (baidu/ERNIE-4.5-VL-28B-A3B-PT, -Thinking, and the validated mlx-community/ERNIE-4.5-VL-28B-A3B-Thinking-4bit) ships processing_ernie4_5_vl.py (Ernie4_5_VLImageProcessor through auto_map). That file is now the reference. It matches neither transformers nor mlx-vlm exactly. It keeps the first-step one-factor floor, which mlx-vlm also has and transformers lacks, so item 2 does not apply to ERNIE and 10x1000 stays 28x1008. It does not truncate before ceil, which matches transformers and the current code: 4x15 gives 56x112 here and 28x112 in mlx-vlm. Past 200:1 it clamps the ratio instead of raising, so that clamp is now ported: 10x3000 goes from 28x2996 to 28x5600. The arithmetic now uses u64 so h * w cannot overflow.
  • Hunyuan-VL zero edge: a zero edge is rescaled as one pixel, and the math is saturating u64, so smart_resize(0, 10) returns 192x1632 instead of overflowing.
  • MiniMax-M3 was checked and left unchanged: its mlx-vlm reference also has max(factor, round_by_factor(..)).

Changed expectations

No existing expectation changed. Each old test input gives the same result under the transformers or checkpoint reference: the zero-edge tests still give (28, 196) and (56, 56), and the ERNIE tie and out-of-bounds tests match the checkpoint code. The only edit to an existing test is in the load_video decode test (video_tests.rs), where the expected-index helper now rounds half to even. Index 12 becomes 24, which is still inside the color tolerance.

Every new expected value was computed with the Python reference: transformers 5.16.1 smart_resize for qwen2_vl, dots (qwen2_vl bounds) and hunyuan_vl, the checkpoint's processing_ernie4_5_vl.py for ERNIE, and numpy for the frame indices. Each test's doc comment shows the arithmetic. The ERNIE thin-image and 4x15 tests pass on main by design, because the checkpoint code agrees with the current arithmetic there. The ratio-clamp test fails on main.

Test plan

Remote CI was cancelled by maintainer decision. Local validation only:

  • cargo fmt --all -- --check
  • cargo clippy -p mlxcel --lib --tests --features metal,accelerate -- -D warnings
  • cargo test -p mlxcel --lib --profile test-fast --features metal,accelerate filtered to vision::processors::{qwen2_vl,dots_ocr,ernie4_5_vl,hunyuan_vl,gemma4} and multimodal::video: qwen2_vl 14, dots_ocr 6, ernie4_5_vl 8, hunyuan_vl 4, gemma4 21 (1 ignored), multimodal::video 57 (11 ignored, ffmpeg-fixture gated) passed, 0 failed

Closes #3478

Frame indices in uniform_indices, evenly_spaced_indices, Gemma 4 uniform_sample_frames and Inkling pair anchors now round half to even, as numpy and Python round do, so a tie samples the same frame as the reference.

The Qwen2-VL family, dots.ocr and Hunyuan-VL smart_resize drop the one-factor floor from the first rounding step, so a thin edge that rounds to 0 takes the min_pixels branch like transformers (10x1000 at factor 28 is 28x560). The result is floored at one factor only when min_pixels is 0. The qwen2_vl 200:1 cap trim now also runs after the min_pixels branch.

ERNIE 4.5 VL follows the processing_ernie4_5_vl.py its checkpoints ship: it keeps the first-step floor and now clamps ratios past 200:1 as that file does, in u64 arithmetic. Hunyuan-VL rescales a zero edge as one pixel in saturating u64 instead of overflowing.

Validated with the focused processor and multimodal::video tests, clippy and fmt.

Closes #3478
@inureyes inureyes added status:done Completed type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority area:models Model architectures, weights, loading, metadata labels Nov 27, 2026
@inureyes
inureyes marked this pull request as ready for review November 27, 2026 05:21
@inureyes
inureyes merged commit e705ac8 into main Nov 27, 2026
1 of 33 checks passed
@inureyes

Copy link
Copy Markdown
Member Author

Merge-time validation by the orchestrator, on top of the focused tests in the PR body.

  • The fixture-gated video tests were not exercised in the PR run (they are #[ignore] and need ffmpeg). I ran the make verify-test-video selection on this branch: MLXCEL_TEST_VIDEO=1 cargo test --profile test-fast --features metal,accelerate -p mlxcel --lib -- --include-ignored --skip bench_single_pass_768_frames multimodal::video --test-threads=1 gave 68 passed, 0 failed (ffmpeg 9.0.2), and vision::processors::gemma4::tests::process_videos_pixel_values_match_input_color with --include-ignored passed. This covers the load_video decode test whose expected indices changed with the half-to-even rounding.
  • cargo fmt --all -- --check, scripts/ci/check_used_by.py and scripts/ci/check_env_var_docs.py passed.
  • Remote CI was cancelled by maintainer decision; the merge relies on the local runs above.

@inureyes
inureyes deleted the fix/issue-3478-vision-resize-parity branch November 27, 2026 05:21
inureyes added a commit that referenced this pull request Nov 28, 2026
## Summary

Adds the bilingual technical reports that were skipped when these three PRs merged on 2026-11-27:

- `TECHNICAL_REPORTS/3489-jiff-1x-strftime-now-20261127.{en,ko}.md` (#3489, jiff 1.0.3 and the `strftime_now` format and zone)
- `TECHNICAL_REPORTS/3490-vision-resize-frame-parity-20261127.{en,ko}.md` (#3490, resize and frame-sampling parity)
- `TECHNICAL_REPORTS/3491-qwen35-mtp-drafter-yarn-20261127.{en,ko}.md` (#3491, YaRN in the Qwen 3.5 MTP drafter)

Each report records the decisions the PR encodes (for example why ERNIE follows the checkpoint's `processing_ernie4_5_vl.py` rather than transformers or mlx-vlm, and why the drafter YaRN table is installed by the binary crate's loader) and what remains unverified.

## Test plan

Docs only. Remote CI was cancelled by maintainer decision.

- [x] Facts cross-checked against the merged diffs, PR bodies and the local validation output
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Close remaining vision resize and frame-sampling parity gaps

1 participant