-
Notifications
You must be signed in to change notification settings - Fork 7.1k
replace tensor division with scalar division and tensor multiplication #6903
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
Conversation
Are we sure it also provides the same results as a division? |
We have pretty extensive tests that make sure that it does. The only thing I needed to adapt was to allow some tolerances on the TBH, the difference is really insignificant:
This failure is for |
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.
LGTM, thnks!
…iplication (#6903) Summary: * replace tensor division with scalar division and tensor multiplication * fix consistency test tolerances Reviewed By: NicolasHug Differential Revision: D41265200 fbshipit-source-id: bb438d768ebe1137f84df559589ad19eb2e0fc9e
As discussed in #6830 (comment), a tensor vision of a Python scalar is slower than inverting the Python scalar first and performing a tensor multiplication afterwards. The linked comment identified three places where we could use that optimization:
Performance improvement is significant for
posterize
andconvert_dtype
. Foradjust_hue
the change is within measuring tolerance. LMK if we still want this change there.Apart from the ops above there are a few more places that divide by a Python scalar, but they are always accompanied by a floor rounding like
vision/torchvision/prototype/transforms/functional/_color.py
Line 418 in cb4413a
Since
Tensor.mul
does not have that option we need an additional.floor_()
afterwards eliminating the gains.cc @vfdev-5 @datumbox @bjuncek