Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tensor.dtype.to_complex() crashes kernel after ~100 calls in ipython kernelΒ #124868

@RichieHakim

Description

@RichieHakim

πŸ› Describe the bug

The following block of code consistently crashes an ipython kernel without an error traceback after ~100 iterations in the loop:

import torch
for i in range(1000):
    d = torch.float32.to_complex()

Running on torch==2.2.2+cu121, and I tried in on a couple google colab instance with torch==2.2.1+cu121 and torch==2.2.0+cpu with the same result.
It crashes with all real dtypes.

It does not crash in a terminal python kernel, but does sometimes cause a segmentation fault after the script ends.

For anyone looking for a workaround, you can just use this:

def dtype_to_complex(dtype: torch.dtype) -> torch.dtype:
    """
    Converts a real torch dtype to a complex dtype. \n
    RH 2024

    Args:
        dtype (torch.dtype): 
            Real dtype to convert to complex dtype.

    Returns:
        (torch.dtype): 
            complex_dtype (torch.dtype):
                Complex dtype.
    """
    map = {
        torch.float16: torch.complex32,
        torch.bfloat16: torch.complex64,
        torch.float32: torch.complex64,
        torch.float64: torch.complex128,
    }
    if dtype not in map:
        raise ValueError(f'{dtype} does not have a complex equivalent in map.')
    return map[dtype]

Versions

environment:

python collect_env.py
Collecting environment information...
PyTorch version: 2.2.2+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: Could not collect
CMake version: version 3.26.4
Libc version: glibc-2.31

Python version: 3.11.3 (main, May 15 2023, 15:45:52) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-105-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 11.7.64
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090
Nvidia driver version: 535.171.04
cuDNN version: Could not collect
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
Byte Order:                         Little Endian
Address sizes:                      46 bits physical, 48 bits virtual
CPU(s):                             36
On-line CPU(s) list:                0-35
Thread(s) per core:                 2
Core(s) per socket:                 18
Socket(s):                          1
NUMA node(s):                       1
Vendor ID:                          GenuineIntel
CPU family:                         6
Model:                              85
Model name:                         Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz
Stepping:                           7
CPU MHz:                            3000.000
CPU max MHz:                        4800.0000
CPU min MHz:                        1200.0000
BogoMIPS:                           6000.00
Virtualization:                     VT-x
L1d cache:                          576 KiB
L1i cache:                          576 KiB
L2 cache:                           18 MiB
L3 cache:                           24.8 MiB
NUMA node0 CPU(s):                  0-35
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        KVM: Mitigation: VMX disabled
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Mitigation; TSX disabled
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 pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault cat_l3 cdp_l3 invpcid_single ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_pkg_req avx512_vnni md_clear flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] onnx==1.15.0
[pip3] onnx-graphsurgeon==0.3.27
[pip3] onnx-simplifier==0.4.33
[pip3] onnx2torch==1.5.13
[pip3] onnxconverter-common==1.13.0
[pip3] onnxruntime==1.17.0
[pip3] onnxruntime-gpu==1.15.1
[pip3] sk2torch==1.2.0
[pip3] skl2onnx==1.16.0
[pip3] torch==2.2.2
[pip3] torchaudio==2.2.2
[pip3] torchkbnufft==1.4.0
[pip3] torchvision==0.17.2
[pip3] triton==2.2.0
[conda] blas                      1.0                         mkl  
[conda] mkl                       2023.1.0         h213fc3f_46344  
[conda] mkl-service               2.4.0           py311h5eee18b_1  
[conda] mkl_fft                   1.3.8           py311h5eee18b_0  
[conda] mkl_random                1.2.4           py311hdb19cb5_0  
[conda] numpy                     1.26.4          py311h08b1b3b_0  
[conda] numpy-base                1.26.4          py311hf175353_0  
[conda] onnx2torch                1.5.13                   pypi_0    pypi
[conda] sk2torch                  1.2.0                    pypi_0    pypi
[conda] torch                     2.2.2                    pypi_0    pypi
[conda] torchaudio                2.2.2                    pypi_0    pypi
[conda] torchkbnufft              1.4.0                    pypi_0    pypi
[conda] torchvision               0.17.2                   pypi_0    pypi
[conda] triton                    2.2.0                    pypi_0    pypi

cc @ezyang @anjali411 @dylanbespalko @mruberry @lezcano @nikitaved @amjames @albanD

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: complexRelated to complex number support in PyTorchmodule: crashProblem manifests as a hard crash, as opposed to a RuntimeErrormodule: python frontendFor issues relating to PyTorch's Python frontendtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions