8000 Allow qwen/emu3 to process low res images by qubvel · Pull Request #38150 · huggingface/transformers · GitHub
[go: up one dir, main page]

Skip to content

Allow qwen/emu3 to process low res images #38150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

qubvel
Copy link
Member
@qubvel qubvel commented May 15, 2025

What does this PR do?

Allow to process images with low resolution, found this limitation while evaluating model on the MMMU-pro benchmark

Reroduction:

from PIL import Image
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor

model = Qwen2_5_VLForConditionalGeneration.from_pretrained("Qwen/Qwen2.5-VL-3B-Instruct", torch_dtype="auto", device_map="auto")
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-3B-Instruct")

image = Image.new("RGB", (25, 100), color="red")
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": image,
            },
            {"type": "text", "text": "Describe this image."},
        ],
    }
]

text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=[text], images=image, return_tensors="pt").to("cuda")

generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
    out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
    generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)

Gives the following error on main:

...
 line 432, in preprocess
    patches, image_grid_thw = self._preprocess(
  File "/home/ubuntu/projects/transformers/src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py", line 251, in _preprocess
    resized_height, resized_width = smart_resize(
  File "/home/ubuntu/projects/transformers/src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py", line 68, in smart_resize
    raise ValueError(f"height:{height} and width:{width} must be larger than factor:{factor}")
ValueError: height:100 and width:25 must be larger than factor:28

@qubvel qubvel marked this pull request as ready for review May 15, 2025 11:57
@qubvel qubvel requested a review from zucchini-nlp May 15, 2025 12:00
@qubvel
Copy link
Member Author
qubvel commented May 15, 2025

cc @zucchini-nlp

@HuggingFaceDocBuilderDev

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.

Copy link
Member
@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

Thanks! Maybe we can add a small test in common image test mixin, to make sure all our image processors can work with tiny images?

@rdonggroq rdonggroq mentioned this pull request Jun 9, 2025
5 tasks
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
0