Skip to content
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

[proto] Small optimization for gaussian_blur functional op #6762

Merged
merged 7 commits into from
Oct 17, 2022

Conversation

vfdev-5
Copy link
Collaborator

@vfdev-5 vfdev-5 commented Oct 13, 2022

Description:

  • use softmax and multiplication to speed-up gaussian blur op
[-------------- Gaussian Blur cpu torch.uint8 --------------]
                     |  gaussian_blur v1  |  gaussian_blur v2
1 threads: --------------------------------------------------
      (3, 400, 400)  |        2.78        |        2.65
6 threads: --------------------------------------------------
      (3, 400, 400)  |        1.08        |        1.01

Times are in milliseconds (ms).

[-------------- Gaussian Blur cuda torch.uint8 -------------]
                     |  gaussian_blur v1  |  gaussian_blur v2
1 threads: --------------------------------------------------
      (3, 400, 400)  |        342         |        227
6 threads: --------------------------------------------------
      (3, 400, 400)  |        259         |        227

Times are in microseconds (us).

[------------- Gaussian Blur cpu torch.float32 -------------]
                     |  gaussian_blur v1  |  gaussian_blur v2
1 threads: --------------------------------------------------
      (3, 400, 400)  |        2160        |        2080
6 threads: --------------------------------------------------
      (3, 400, 400)  |         917        |         840

Times are in microseconds (us).

[------------- Gaussian Blur cuda torch.float32 ------------]
                     |  gaussian_blur v1  |  gaussian_blur v2
1 threads: --------------------------------------------------
      (3, 400, 400)  |        232         |        200
6 threads: --------------------------------------------------
      (3, 400, 400)  |        231         |        200

Times are in microseconds (us).

Code source


This PR may also help with flaky gaussian blur tests.

Context:

Gaussian blur eager vs jit tests are flaky for uint8 input. This may be due to the fact that we cast to float32, perform the opertation in float32 and cast back to uint8. We generate conv kernels (created using exp op) in float32 and maybe accumulating precision errors.

Refs: #6755

@vfdev-5 vfdev-5 changed the title [WIP] Use softmax in _get_gaussian_kernel1d [proto] Optimize gaussian_blur functional op Oct 17, 2022
@vfdev-5 vfdev-5 force-pushed the update-gaussian-blur branch from b8e4e60 to c26baa9 Compare October 17, 2022 09:17
@vfdev-5 vfdev-5 changed the title [proto] Optimize gaussian_blur functional op [proto] Small optimization for gaussian_blur functional op Oct 17, 2022
@vfdev-5 vfdev-5 marked this pull request as ready for review October 17, 2022 11:23
Copy link
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if CI is green!

@vfdev-5 vfdev-5 merged commit decb191 into pytorch:main Oct 17, 2022
@vfdev-5 vfdev-5 deleted the update-gaussian-blur branch October 17, 2022 14:45
@github-actions
Copy link

Hey @vfdev-5!

You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

@vfdev-5 vfdev-5 added module: transforms Perf For performance improvements prototype labels Oct 17, 2022
facebook-github-bot pushed a commit that referenced this pull request Oct 21, 2022
…6762)

Summary:
* Use softmax in _get_gaussian_kernel1d

* Revert "Use softmax in _get_gaussian_kernel1d"

This reverts commit eb8fba3.

* Code update

* Relaxed tolerance in consistency tests for GaussianBlur and ElasticTransform

* Code review updates

* Update test_prototype_transforms_consistency.py

Reviewed By: YosuaMichael

Differential Revision: D40588166

fbshipit-source-id: 51e0f651843efbc9487543ad889d6f6d390a19db
@pmeier pmeier mentioned this pull request May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants