Description
🐛 Describe the bug
🐛 Describe the bug
Inconsistent result of torch.eye() in CPU vs GPU
Program
import torch
import numpy as np
def test(n, out):
out_gpu = out.cuda()
try:
out_gpu = torch.eye(n=n, out=out_gpu)
except RuntimeError as e:
print(e)
print(out_gpu.cpu())
out_cpu = out.cpu()
try:
out_cpu = torch.eye(n=n, out=out_cpu)
except RuntimeError as e:
print(e)
print(out_cpu)
n = 4
np_array = np.array([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]], dtype=np.float32)
out = torch.from_numpy(np_array)
test(4, out)
Output
tensor([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
Trying to resize storage that is not resizable
Traceback (most recent call last):
File "/mnt/data-ssd-1/luozh/CSS/llmFuzzDL/test.py", line 29, in
test(4, out)
File "/mnt/data-ssd-1/luozh/CSS/llmFuzzDL/test.py", line 17, in test
print(out_cpu)
File "/mnt/data-ssd-1/luozh/.virtualenvs/pythonProject/lib/python3.12/site-packages/torch/_tensor.py", line 590, in repr
return torch._tensor_str._str(self, tensor_contents=tensor_contents)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/data-ssd-1/luozh/.virtualenvs/pythonProject/lib/python3.12/site-packages/torch/_tensor_str.py", line 710, in _str
return _str_intern(self, tensor_contents=tensor_contents)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/data-ssd-1/luozh/.virtualenvs/pythonProject/lib/python3.12/site-packages/torch/_tensor_str.py", line 631, in _str_intern
tensor_str = _tensor_str(self, indent)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/data-ssd-1/luozh/.virtualenvs/pythonProject/lib/python3.12/site-packages/torch/_tensor_str.py", line 364, in _tensor_str
return _tensor_str_with_formatter(self, indent, summarize, formatter)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/data-ssd-1/luozh/.virtualenvs/pythonProject/lib/python3.12/site-packages/torch/_tensor_str.py", line 311, in _tensor_str_with_formatter
self[i], indent + 1, summarize, formatter1, formatter2
~~~~^^^
RuntimeError: setStorage: sizes [4], strides [1], storage offset 8, and itemsize 4 requiring a storage size of 48 are out of bounds for storage of size 36
### Versions
PyTorch version: 2.7.0+cu126
Is debug build: False
CUDA used to build PyTorch: 12.6
ROCM used to build PyTorch: N/A
OS: Ubuntu 24.04.2 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: 19.0.0git
CMake version: version 3.28.3
Libc version: glibc-2.39
Python version: 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-11-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: 12.0.140
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060
Nvidia driver version: 560.35.03
cuDNN version: Probably one of the following:
/usr/local/cuda-12.6/targets/x86_64-linux/lib/libcudnn.so.8
/usr/local/cuda-12.6/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
/usr/local/cuda-12.6/targets/x86_64-linux/lib/libcudnn_adv_train.so.8
/usr/local/cuda-12.6/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
/usr/local/cuda-12.6/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
/usr/local/cuda-12.6/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
/usr/local/cuda-12.6/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 20
On-line CPU(s) list: 0-19
Vendor ID: GenuineIntel
Model name: 12th Gen Intel(R) Core(TM) i7-12700K
CPU family: 6
Model: 151
Thread(s) per core: 2
Core(s) per socket: 12
Socket(s): 1
Stepping: 2
CPU(s) scaling MHz: 95%
CPU max MHz: 5000.0000
CPU min MHz: 800.0000
BogoMIPS: 7219.20
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault cat_l2 cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 512 KiB (12 instances)
L1i cache: 512 KiB (12 instances)
L2 cache: 12 MiB (9 instances)
L3 cache: 25 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-19
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Versions of relevant libraries:
[pip3] hypothesis-torch==1.0.7
[pip3] numpy==2.1.3
[pip3] nvidia-cublas-cu12==12.6.4.1
[pip3] nvidia-cuda-cupti-cu12==12.6.80
[pip3] nvidia-cuda-nvrtc-cu12==12.6.77
[pip3] nvidia-cuda-runtime-cu12==12.6.77
[pip3] nvidia-cudnn-cu12==9.5.1.17
[pip3] nvidia-cufft-cu12==11.3.0.4
[pip3] nvidia-curand-cu12==10.3.7.77
[pip3] nvidia-cusolver-cu12==11.7.1.2
[pip3] nvidia-cusparse-cu12==12.5.4.2
[pip3] nvidia-cusparselt-cu12==0.6.3
[pip3] nvidia-nccl-cu12==2.26.2
[pip3] nvidia-nvjitlink-cu12==12.6.85
[pip3] nvidia-nvtx-cu12==12.6.77
[pip3]
[pip3] optree==0.15.0
[pip3] torch==2.7.0
[pip3] triton==3.3.0
[conda] Could not collect
### Versions
When calling torch.eye the CPU and CUDA implementations produce different outputs