transformers
d8904a23 - fix(aria): use math.ceil in get_number_of_image_patches to match actual patch count (#46732)

Commit
26 days ago
fix(aria): use math.ceil in get_number_of_image_patches to match actual patch count (#46732) * fix(aria): use math.ceil in get_number_of_image_patches to match actual patch count `get_number_of_image_patches` used floor division (`//`) to compute the number of patches, but `get_image_patches` calls `divide_to_patches` which iterates `range(0, height, patch_size)` — equivalent to ceiling division. When `max_image_size=980` the default `split_resolutions` include odd multiples of 490 (490, 1470, 2450, ...) that are not divisible by 980. The mismatch caused `get_number_of_image_patches` to undercount — returning 0 instead of 1 for resolutions like [490, 980] or [980, 490], and 1 instead of 2 for [980, 1470] or [1470, 980]. The wrong count propagates to `num_image_tokens` in `get_multimodal_data`, misaligning visual embeddings with text token positions at inference time. Fix: replace `resized_height // max_image_size * resized_width // max_image_size` with `math.ceil(resized_height / max_image_size) * math.ceil(resized_width / max_image_size)`. The same change is applied to all three files (modular source + two auto-generated variants). Also updates the existing test whose expected value was based on the old formula, and adds regression cases for the `max_image_size=980` scenarios that were previously returning 0. Fixes #46728 * fix: avoid import math to prevent modular converter from touching modeling_aria.py Use -(-a // b) integer ceiling division instead of math.ceil(a / b) so that the top-level import does not propagate to modeling_aria.py via the modular converter, and run ruff format on the test file. * fix: use ruff-stable parenthesized form to match modular converter output The converter generates compact single-line ternary inside parens; ruff also produces this form when the expression fits as one inner line within the 119-char limit. Aligning both avoids the check_repository_consistency mismatch from the previous commit. * fix: correct wide-image test case for get_number_of_image_patches (400, 900) selects best_resolution=(490, 980) which gives 1 patch, not 2. Use (300, 1470) which selects (490, 1470) → 1*2 = 2 patches. * fix(aria): use math.ceil and respect split_resolutions kwarg in get_number_of_image_patches * improt top-lvl * Apply repo consistency fixes --------- Co-authored-by: Arnav Kewalram <arnav@Arnavs-MacBook-Pro.local> Co-authored-by: raushan <raushan@huggingface.co> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Author
Parents
Loading