-
Notifications
You must be signed in to change notification settings - Fork 24.4k
TensorIteratorBase::is_scalar
return false
for empty numpy tensors, but true for empty Torch ones
#113037
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
Comments
As @tringwald already commented is is due to a slightly odd definition of pytorch/aten/src/ATen/TensorIterator.cpp Lines 797 to 805 in e396687
|
@jiayisunx could you please take a look at this one ?
might be |
>>> a = torch.from_numpy(np.ones((0, 0, 0)))
>>> a.stride()
(0, 0, 0)
>>> a.shape
torch.Size([0, 0, 0])
>>> a.ndim
3
>>> b = torch.ones(0, 0, 0)
>>> b.stride()
(1, 1, 1) Due to this behavior, the |
Very easy fix is to add diff --git a/aten/src/ATen/TensorIterator.cpp b/aten/src/ATen/TensorIterator.cpp
index b42188858f6..fb7edeb5cfd 100644
--- a/aten/src/ATen/TensorIterator.cpp
+++ b/aten/src/ATen/TensorIterator.cpp
@@ -801,7 +801,7 @@ bool TensorIteratorBase::is_scalar(int arg) const {
return false;
}
}
- return true;
+ return data_ptr(arg) != nullptr;
}
bool TensorIteratorBase::is_cpu_scalar(int arg) const { |
closing this task since included in 2.1.2 and validated |
I want to have a proper fix, when we don't even dispatch to the implementation if number of elements is 0 |
Targeted fix for pytorch#113037 A more fundamental one, where those functions are not even called for empty tensors are coming later Pull Request resolved: pytorch#115183 Approved by: https://github.com/drisspg, https://github.com/atalman, https://github.com/huydhn
Validated with final rc. No failure |
Removing from 2.2.0 milestone |
torch.div
on empty tensors causes segmentation faultTensorIteratorBase::is_scalar
return false
for empty numpy tensors, but true for empty Torch ones
Unassigning myself, changing title and removing crash and high priority, as underlying crash was fixed by #115183 but still question remains what is scalar from TensorIterator point of view and why native kernels are even called ones structured kernel execution on an empty tensors has finished |
Uh oh!
There was an error while loading. Please reload this page.
🐛 Describe the bug
Following example causes null pointer dereference at
pytorch/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp
Line 229 in e396687
Versions
2.1
cc @ezyang @gchanan @zou3519 @kadeng @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10
The text was updated successfully, but these errors were encountered: