[Fix] Wrong type hint in get_number_of_image_patches - #47788
Conversation
|
[For maintainers] Suggested jobs to run (before merge) run-slow: aria, cohere2_vision, cosmos3_edge, deepseek_ocr2, ernie4_5_vl_moe, glm46v, glm4v, glm_image, glmga, got_ocr2, hunyuan_vl, idefics3, kimi_k25, minimax_m3_vl, paddleocr_vl, qwen2_vl |
CI recapDashboard: View test results in Grafana |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
zucchini-nlp
left a comment
There was a problem hiding this comment.
hm, i think we don't have cases when kwargs are explicitly None if we assume the helper is used only by vllm 馃
In most cases None would have thrown an error when we try to get a value from it
Re different return types: agreed on that, Anton raises similar question recently on making get_num_patches a "required/uniform" method for image processors. Will be a bit breaking but imo worth it in long term
I will also use the helper in CB I think!
yes definitely. Hence my PS about the fact we can go the other way, but I think the default is a good solution as well |
ah, nice, didn't know about that. We can make it optional, no big deal in any case. If you wish to work on uniform return format, imo the I'll review this one in a sec |
| min_patches = images_kwargs.get("min_patches", self.min_patches) if images_kwargs else self.min_patches | ||
| max_patches = images_kwargs.get("max_patches", self.max_patches) if images_kwargs else self.max_patches | ||
| patch_size = images_kwargs.get("patch_size", self.size) if images_kwargs else self.size | ||
| crop_to_patches = ( | ||
| images_kwargs.get("crop_to_patches", self.crop_to_patches) if images_kwargs else self.crop_to_patches | ||
| ) | ||
| images_kwargs = images_kwargs or {} | ||
| min_patches = images_kwargs.get("min_patches", self.min_patches) |
There was a problem hiding this comment.
oke, i see where the confusion comes from 馃珷
Actually I liked the 3 ints tuple, with product, width, height (or the other order, idk). But we can leave that for a downstream PR |
molbap
left a comment
There was a problem hiding this comment.
LGTM! type balance is restored, thanks. For the return uniformization, the three-element tuple is nice but I'm always a fan of dataclasses for typing outputs as well, slightly more future-proof.
To note, the name of the util is also misleading as we don't just return the number of image patches, but rich image patches metadata in many cases, though we can't really change that (just to keep in mind when we uniformize everything)
ah right, this will be easier for future extremely weird processors indeed |
This PR fixes a wrong type hint + default value in
get_number_of_image_patches: currently, theimage_kwargsis annotated as an optionnal dictionary with default valueNonebut passingNonewould crash the function.To correect this, we use
image_kwargs = image_kwargs or {}to go from the default dict to an empty one and then usegetwith appropriate defaults.Also,
glm4vused to hardcode a default value (call itV) forsizethat was different from a potential user-suppliedself.size: now, we default toself.size, which if not user supplied, defaults itself toV. So in absence of user intervention, behavior is identical.One thing to consider: depending on the model,
get_number_of_image_patchesreturns either anint(number of patches,n_patches = n_width_patches * n_height_patches) a tuple of 2 ints (n_width_patches, n_height_patches) or a tuple of 3 ints (n_patches, n_width_patches, n_height_patches) -> maybe it would be worth uniformising this. WDYT? cc. @molbap @zucchini-nlpPS: we can go the other route and force image_kwargs to be passed, but it seems even more breaking, plus I think VLLM uses this function.