-
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
[prototype] Speed up adjust_sharpness_image_tensor
#6930
Conversation
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.
One question otherwise LGTM if CI is green.
@@ -119,7 +122,29 @@ def adjust_sharpness_image_tensor(image: torch.Tensor, sharpness_factor: float) | |||
else: | |||
needs_unsquash = False | |||
|
|||
output = _blend(image, _FT._blurred_degenerate_image(image), sharpness_factor) | |||
kernel_dtype = image.dtype if fp else torch.float32 |
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.
To ease review, here is the old implementation:
def _blurred_degenerate_image(img: Tensor) -> Tensor: |
# We speed up blending by minimizing flops and doing in-place. The 2 blend options are mathematically equivalent: | ||
# x+(1-r)*(y-x) = x + (1-r)*y - (1-r)*x = x*r + y*(1-r) | ||
view.add_(blurred_degenerate.sub_(view), alpha=(1.0 - sharpness_factor)) |
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.
Can push a change like this to _blend
or is this a special case here?
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.
It's a special case :( We can do this only because we are allowed to subtract image1
from image2
in place. In all other cases where _blend()
is used, we rely on broadcasting do that's not possible.
adjust_sharpness_image_tensor
adjust_sharpness_image_tensor
Summary: * Speed up `adjust_sharpness_image_tensor` * Add a comment Reviewed By: NicolasHug Differential Revision: D41265190 fbshipit-source-id: 4ebbd1d7a4d763a77f4af84b2da710f7a981a843
Related to #6818
Performance optimization for the adjust sharpness kernel:
cc @vfdev-5 @bjuncek @pmeier