Create kernel on-device for transforms.functional.gaussian_blur#8426
Merged
NicolasHug merged 4 commits intopytorch:mainfrom May 29, 2024
Merged
Create kernel on-device for transforms.functional.gaussian_blur#8426NicolasHug merged 4 commits intopytorch:mainfrom
transforms.functional.gaussian_blur#8426NicolasHug merged 4 commits intopytorch:mainfrom
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. |
NicolasHug
approved these changes
May 29, 2024
Member
NicolasHug
left a comment
There was a problem hiding this comment.
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.
This was referenced May 29, 2024
transforms.functional.gaussian_blur
facebook-github-bot
pushed a commit
that referenced
this pull request
Jun 7, 2024
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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