Skip to content

torch._foreach_mul_ segmentation fault #113156

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

Closed
alanhe151220037 opened this issue Nov 7, 2023 · 6 comments
Closed

torch._foreach_mul_ segmentation fault #113156

alanhe151220037 opened this issue Nov 7, 2023 · 6 comments
Assignees
Labels
module: crash Problem manifests as a hard crash, as opposed to a RuntimeError module: edge cases Adversarial inputs unlikely to occur in practice module: error checking Bugs related to incorrect/lacking error checking module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@alanhe151220037
Copy link
Contributor

alanhe151220037 commented Nov 7, 2023

🐛 Describe the bug

The following example will cause segmentation fault.

import torch
import numpy as np
x_array = np.array([],dtype=np.float16)
x_tensor = torch.from_numpy(x_array)
torch._foreach_mul_((x_tensor,),1.0)
Segmentation fault (core dumped)

Strangely, only torch._foreach_mul_ will have this problem and torch._foreach_div_ is fine. Although I haven't quite understand the direct segmentation fault reason, but I think this may caused by the following code that mul_.Scalar calls mul.out but div_.scalar calls div_.Tensor.

Tensor& mul_(Tensor& self, const Scalar& other) {
return at::mul_out(self, wrapped_scalar_tensor(other), self); // redispatch!
}

Tensor& div_(Tensor& self, const Scalar& other) {
return self.div_(wrapped_scalar_tensor(other)); // redispatch!
}

And, after I rewrite the mul_.Scalar like div_.scalar, it works!

Versions

PyTorch version: 2.2.0a0+git0d669f0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.5 LTS (aarch64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.20.5
Libc version: glibc-2.31

Python version: 3.9.17 (main, Jul 5 2023, 20:44:37) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-4.19.90-2107.6.0.0098.oe1.bclinux.aarch64-aarch64-with-glibc2.31
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

cc @malfet @mruberry @rgommers

@jon-chuang
Copy link
Collaborator

Does this occur without np?

@malfet malfet added module: crash Problem manifests as a hard crash, as opposed to a RuntimeError module: error checking Bugs related to incorrect/lacking error checking labels Nov 7, 2023
@malfet malfet self-assigned this Nov 7, 2023
@malfet malfet added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Nov 7, 2023
@malfet
Copy link
Contributor

malfet commented Nov 7, 2023

I suspect root of the problem is the same as #113037 ....

@malfet malfet added module: edge cases Adversarial inputs unlikely to occur in practice module: numpy Related to numpy support, and also numpy compatibility of our operators labels Nov 7, 2023
@malfet
Copy link
Contributor

malfet commented Nov 7, 2023

Does this occur without np?

I suspect that it would not, because some of the assumption we made in PyTorch about what constitute a scalar (or tensor-wrapped-scalar) are wrong for empty tensors created from numpy

@alanhe151220037
Copy link
Contributor Author

Does this occur without np?

No,only with np

@malfet
Copy link
Contributor

malfet commented Nov 7, 2023

Yes, this might not look the same, but this is a duplicate of #113037 as it crashes because iter.is_scalar(2) returns true on an empty tensor

malfet added a commit that referenced this issue Nov 7, 2023
`TensorIterator::is_scalr()` should return false for empty numpy tensor
(i.e. ones created using `torch.from_numpy(np.empty([1, 2, 0]))`)

Fixes #113037 and #113156
malfet added a commit that referenced this issue Nov 8, 2023
`TensorIterator::is_scalr()` should return false for empty numpy tensor
(i.e. ones created using `torch.from_numpy(np.empty([1, 2, 0]))`)

Fixes #113037 and #113156
@malfet
Copy link
Contributor

malfet commented Dec 15, 2023

Closing as duplicate of #113037 (also it is already fixed in nightlies)

@malfet malfet closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: crash Problem manifests as a hard crash, as opposed to a RuntimeError module: edge cases Adversarial inputs unlikely to occur in practice module: error checking Bugs related to incorrect/lacking error checking module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants