-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Haocheng lu2 #37350
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
base: main
Are you sure you want to change the base?
Haocheng lu2 #37350
Conversation
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Can you also update the test here, so it checks that video processing works for any input shape?
Existing test:
transformers/tests/models/qwen2_vl/test_image_processing_qwen2_vl.py
Lines 277 to 288 in e2b0224
def test_video_inputs(self): | |
for image_processing_class in self.image_processor_list: | |
image_processing = image_processing_class(**self.image_processor_dict) | |
expected_dims_by_frames = {1: 34300, 2: 34300, 3: 68600, 4: 68600, 5: 102900, 6: 102900} | |
for num_frames, expected_dims in expected_dims_by_frames.items(): | |
image_processor_tester = Qwen2VLImageProcessingTester(self, num_frames=num_frames) | |
video_inputs = image_processor_tester.prepare_video_inputs(equal_resolution=True) | |
prcocess_out = image_processing(None, videos=video_inputs, return_tensors="pt") | |
encoded_video = prcocess_out.pixel_values_videos | |
expected_output_video_shape = (expected_dims, 1176) | |
self.assertEqual(tuple(encoded_video.shape), expected_output_video_shape) |
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. |
What does this PR do?
This PR fixes an issue in the _preprocess function of the Qwen2VLImageProcessor class, located in:
transformers/src/transformers/models/qwen2_vl/image_processing_qwen2_vl.py
Previously, when the number of patches was not divisible by temporal_patch_size, the code mistakenly repeated the last patch temporal_patch_size - 1 times, which could cause overshooting. This PR corrects the padding logic by computing the exact number of repeats needed:
pad_len = temporal_patch_size - (patches.shape[0] % temporal_patch_size)
repeats = np.repeat(patches[-1][np.newaxis], pad_len, axis=0)
Motivation and context
This change ensures that the total number of temporal patches is always divisible by temporal_patch_size, without introducing unnecessary extra patches. It avoids shape mismatch or over-padding problems in the later reshape steps.
Local Testing
✅ I have tested this change locally and confirmed that all tests pass.
Fixes # (issue)
#37064
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.