Skip to content

Converting a numpy array of size larger than 32,768 to a tensor causes a segmentation fault #130708

@chadeos

Description

@chadeos

🐛 Describe the bug

Consider the following code:

import numpy as np
import torch

x_array = np.zeros([32769])  # Problem goes away if array is 32,768 elements or smaller
x_list = [x_array[i] for i in range(x_array.shape[0])]
torch.tensor(x_list)  # Works fine
torch.tensor(x_array)  # Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

The effects are as the comments indicate. A list works but the numpy array does not. I was initially working with a higher dimensional ndarray but worked my way down to a one dimensional one as I narrowed down the problem.

Versions

Collecting environment information...
PyTorch version: 2.3.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 14.5 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.3.9.4)
CMake version: Could not collect
Libc version: N/A

Python version: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:54:21) [Clang 16.0.6 ] (64-bit runtime)
Python platform: macOS-14.5-arm64-arm-64bit
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

CPU:
Apple M1 Pro

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] torch==2.3.1
[conda] numpy                     1.26.4          py312h7f4fdc5_0  
[conda] numpy-base                1.26.4          py312he047099_0  
[conda] torch                     2.3.1                    pypi_0    pypi

cc @malfet @albanD @mruberry @rgommers

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: crashProblem manifests as a hard crash, as opposed to a RuntimeErrormodule: macosMac OS related issuesmodule: numpyRelated to numpy support, and also numpy compatibility of our operatorsneeds reproductionEnsure you have actionable steps to reproduce the issue. Someone else needs to confirm the repro.triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions