-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Image processor compile fix #38540
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
Image processor compile fix #38540
Changes from all commits
c147b4b
907b63d
cb36ed8
18d48cb
7a7aff2
7769cc0
e4bae98
54135b3
14775c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ | |
| is_vision_available, | ||
| logging, | ||
| ) | ||
| from .utils.import_utils import is_rocm_platform | ||
|
|
||
|
|
||
| if is_vision_available(): | ||
|
|
@@ -279,8 +280,34 @@ def resize( | |
| "Size must contain 'height' and 'width' keys, or 'max_height' and 'max_width', or 'shortest_edge' key. Got" | ||
| f" {size}." | ||
| ) | ||
| # This is a workaround to avoid a bug in torch.compile when dealing with uint8 on AMD MI3XX GPUs | ||
| # Tracked in PyTorch issue: https://github.com/pytorch/pytorch/issues/155209 | ||
| # TODO: remove this once the bug is fixed (detected with torch==2.7.0+git1fee196, torchvision==0.22.0+9eb57cd) | ||
| if torch.compiler.is_compiling() and is_rocm_platform(): | ||
| return self.compile_friendly_resize(image, new_size, interpolation, antialias) | ||
| return F.resize(image, new_size, interpolation=interpolation, antialias=antialias) | ||
|
|
||
| @staticmethod | ||
| def compile_friendly_resize( | ||
| image: "torch.Tensor", | ||
| new_size: tuple[int, int], | ||
| interpolation: Optional["F.InterpolationMode"] = None, | ||
| antialias: bool = True, | ||
| ) -> "torch.Tensor": | ||
| """ | ||
| A wrapper around `F.resize` so that it is compatible with torch.compile when the image is a uint8 tensor. | ||
| """ | ||
| if image.dtype == torch.uint8: | ||
| image = image.float() / 256 | ||
| image = F.resize(image, new_size, interpolation=interpolation, antialias=antialias) | ||
| image = image * 256 | ||
|
Comment on lines
+301
to
+303
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why divide by 256 and not 255?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried with 255 and got a numerical difference, that I did not get with 256: |
||
| image = image.masked_fill(image > 255, 255) | ||
| image = image.masked_fill(image < 0, 0) | ||
| image = image.round().to(torch.uint8) | ||
| else: | ||
| image = F.resize(image, new_size, interpolation=interpolation, antialias=antialias) | ||
| return image | ||
|
|
||
| def rescale( | ||
| self, | ||
| image: "torch.Tensor", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,8 +143,10 @@ def _preprocess( | |
| min_pixels=min_pixels, | ||
| max_pixels=max_pixels, | ||
| ) | ||
| stacked_videos = F.resize( | ||
| stacked_videos, size=(resized_height, resized_width), interpolation=interpolation | ||
| stacked_videos = self.resize( | ||
| image=stacked_videos, | ||
| size=SizeDict(height=resized_height, width=resized_width), | ||
| interpolation=interpolation, | ||
|
Comment on lines
+146
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing that
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! It will be fixed in a side branch though, not yet in main
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh didn't catch that thanks
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, we can fix qwen2-vl image processor as well, it has the same issue |
||
| ) | ||
| resized_videos_grouped[shape] = stacked_videos | ||
| resized_videos = reorder_videos(resized_videos_grouped, grouped_videos_index) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.