-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Create kernel on-device for transforms.functional.gaussian_blur
#8426
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/8426
Note: Links to docs will display an error until the docs builds have been completed. ❌ 8 New Failures, 14 Unrelated FailuresAs of commit ad00447 with merge base a5f531a (): NEW FAILURES - The following jobs have failed:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
Thank you for the PR @drhead , I'll merge after the CI passes.
Note that the V2 version in torchvision.transforms.v2.functional.gaussian_blur
would already create the kernel on-device, so perhaps you can migrate to the V2 version already.
transforms.functional.gaussian_blur
…blur` (#8426) Reviewed By: vmoens Differential Revision: D58283858 fbshipit-source-id: a4df173fcafe9bce4b35478a7eab5f66f2579180 Co-authored-by: Nicolas Hug <nh.nicolas.hug@gmail.com> Co-authored-by: Nicolas Hug <nicolashug@fb.com>
The current implementation of gaussian blur creates the kernels on CPU and then moves them to the device and dtype of the image. This goes against best practices for pytorch optimization, since it induces a forced device sync.
To fix it, I have passed the device and dtype parameters over to the linspace operation that creates the initial tensor. This should remove the forced device sync. It is worth noting that this may result in it being calculated in a lower precision than normal. This would of course involve an extra call for the cast to get it to the correct precision.
There's probably room for more optimization in this, especially when GaussianBlur is used as a module -- really, I think it would be more appropriate to create the kernels one time and reuse them instead of constructing new ones. This PR solves the more critical issue as is, though.
Closes #8401
cc @vfdev-5