-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add basic torch.hash_tensor op #154149
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
Add basic torch.hash_tensor op #154149
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/154149
Note: Links to docs will display an error until the docs builds have been completed. ⏳ 1 Pending, 1 Unrelated FailureAs of commit 5c8132c with merge base f168cf4 ( UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Attention! native_functions.yaml was changedIf you are adding a new function or defaulted argument to native_functions.yaml, you cannot use it from pre-existing Python frontend code until our FC window passes (two weeks). Split your PR into two PRs, one which adds the new C++ functionality, and one that makes use of it from Python, and land them two weeks apart. See https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy#forwards-compatibility-fc for more info. Caused by: |
cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 jerryzh168 albanD [ghstack-poisoned]
cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 jerryzh168 albanD voznesenskym penguinwu EikanWang Guobing-Chen zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov [ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to multiply/shift via range then reduction with xor. The tensor is always viewed as int64 (applying padding as necessary) before the reduction so the result is always int64. I chose int64 rather than uint64 because e.g. a * x + b is not implemented for uint64 in torch on cuda. [ghstack-poisoned]
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to multiply/shift via range then reduction with xor. The tensor is always viewed as int64 (applying padding as necessary) before the reduction so the result is always int64. I chose int64 rather than uint64 because e.g. a * x + b is not implemented for uint64 in torch on cuda. [ghstack-poisoned]
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to multiply/shift via range then reduction with xor. The tensor is always viewed as int64 (applying padding as necessary) before the reduction so the result is always int64. I chose int64 rather than uint64 because e.g. a * x + b is not implemented for uint64 in torch on cuda. [ghstack-poisoned]
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to multiply/shift via range then reduction with xor. The tensor is always viewed as int64 (applying padding as necessary) before the reduction so the result is always int64. I chose int64 rather than uint64 because e.g. a * x + b is not implemented for uint64 in torch on cuda. [ghstack-poisoned]
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to reduction with xor. - The hash is always uint64. - Integers will be casted to uint64 before performing the xor_sum reduction - Floats will be upcasted to double and then bitcasted to uint64 before performing the xor_sum reduction [ghstack-poisoned]
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to reduction with xor. - The hash is always uint64. - Integers will be casted to uint64 before performing the xor_sum reduction - Floats will be upcasted to double and then bitcasted to uint64 before performing the xor_sum reduction [ghstack-poisoned]
// return a double, otherwise uint64_t will be cast to double | ||
// when accumulating and the result will be wrong |
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.
Ho why?
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.
Let's say we have inputs
a: 3.14159, a_bits: 4614256650576692846
b: 1.61803, b_bits: 4609965778477721196
a ^ b: 9219082337818812418
If we return the result as int64_t, the next time it is used as an input, it will be cast to 9219082337818812418.0, which becomes 4890905006165143848 in bits, which would mess up the xor reduction here
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to reduction with xor. - The hash is always uint64. - Integers will be casted to uint64 before performing the xor_sum reduction - Floats will be upcasted to double and then bitcasted to uint64 before performing the xor_sum reduction [ghstack-poisoned]
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to reduction with xor. - The hash is always uint64. - Integers will be casted to uint64 before performing the xor_sum reduction - Floats will be upcasted to double and then bitcasted to uint64 before performing the xor_sum reduction [ghstack-poisoned]
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to reduction with xor. - The hash is always uint64. - Integers will be casted to uint64 before performing the xor_sum reduction - Floats will be upcasted to double and then bitcasted to uint64 before performing the xor_sum reduction [ghstack-poisoned]
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.
Sounds good to me!
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Added `torch.hash_tensor` reduction function with a `mode` argument that defaults to reduction with xor. - The hash is always uint64. - Integers will be casted to uint64 before performing the xor_sum reduction - Floats will be upcasted to double and then bitcasted to uint64 before performing the xor_sum reduction Pull Request resolved: #154149 Approved by: https://github.com/albanD
Added
torch.hash_tensor
reduction function with amode
argument that defaults to reduction with xor.We don't provide an ordering aware hash function yet because we don't have an easy way to provide a fast cuda kernel for it
Stack from ghstack (oldest at bottom):
cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @jerryzh168 @voznesenskym @penguinwu @EikanWang @Guobing-Chen @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @Lucaskabela