Repository: pytorch
Issue: Importing polars before torch causes a segfault
Labels: needs reproduction,module: binaries,module: crash,triaged

### 🐛 Describe the bug

```
Python 3.11.9 (main, Apr  2 2024, 08:25:04) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import polars as pl
>>> 

Python 3.11.9 (main, Apr  2 2024, 08:25:04) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import polars as pl
>>> import torch
Segmentation fault (core dumped)


Program received signal SIGSEGV, Segmentation fault.
0x00007ffff221fbb6 in _rjem_je_free_default () from /nix/store/ap4afbp3jrp8mp4vam2lq1fqnw5cmbjn-jemalloc-5.3.0/lib/libjemalloc.so.2
(gdb) backtrace
#0  0x00007ffff221fbb6 in _rjem_je_free_default () from /nix/store/ap4afbp3jrp8mp4vam2lq1fqnw5cmbjn-jemalloc-5.3.0/lib/libjemalloc.so.2
#1  0x00007ffff1146a9e in _GLOBAL__sub_I_StorageImpl.cpp ()
   from /nix/store/mdg7l6hsmvsbxx47xkcpz0d5gyblcnjn-python3-3.11.9-env/lib/python3.11/site-packages/torch/lib/libc10.so
#2  0x00007ffff7fce08e in call_init () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/ld-linux-x86-64.so.2
#3  0x00007ffff7fce17c in _dl_init () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/ld-linux-x86-64.so.2
#4  0x00007ffff7fca56e in _dl_catch_exception () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/ld-linux-x86-64.so.2
#5  0x00007ffff7fd4ae6 in dl_open_worker () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/ld-linux-x86-64.so.2
#6  0x00007ffff7fca4e1 in _dl_catch_exception () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/ld-linux-x86-64.so.2
#7  0x00007ffff7fd4e5c in _dl_open () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/ld-linux-x86-64.so.2
#8  0x00007ffff769d19c in dlopen_doit () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/libc.so.6
#9  0x00007ffff7fca4e1 in _dl_catch_exception () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/ld-linux-x86-64.so.2
#10 0x00007ffff7fca603 in _dl_catch_error () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/ld-linux-x86-64.so.2
#11 0x00007ffff769cc97 in _dlerror_run () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/libc.so.6
#12 0x00007ffff769d251 in dlopen@GLIBC_2.2.5 () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/libc.so.6
#13 0x00007ffff7b66a95 in _PyImport_FindSharedFuncptr () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#14 0x00007ffff7b66fb0 in _imp_create_dynamic () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#15 0x00007ffff7a40cf6 in cfunction_vectorcall_FASTCALL () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#16 0x00007ffff78fa99c in _PyEval_EvalFrameDefault () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#17 0x00007ffff7b2b57a in _PyEval_Vector () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#18 0x00007ffff7a1aa67 in object_vacall () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#19 0x00007ffff7a746da in PyObject_CallMethodObjArgs () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#20 0x00007ffff7946c21 in PyImport_ImportModuleLevelObject () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#21 0x00007ffff78fed3e in _PyEval_EvalFrameDefault () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#22 0x00007ffff7b2bc9c in _PyEval_Vector.constprop.0 () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#23 0x00007ffff7b2be3a in PyEval_EvalCode () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#24 0x00007ffff7b5757d in builtin_exec () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#25 0x00007ffff79661c2 in cfunction_vectorcall_FASTCALL_KEYWORDS () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#26 0x00007ffff78fa99c in _PyEval_EvalFrameDefault () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#27 0x00007ffff7b2b57a in _PyEval_Vector () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#28 0x00007ffff7a1aa67 in object_vacall () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#29 0x00007ffff7a746da in PyObject_CallMethodObjArgs () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#30 0x00007ffff7946c21 in PyImport_ImportModuleLevelObject () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#31 0x00007ffff78fed3e in _PyEval_EvalFrameDefault () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#32 0x00007ffff7b2bc9c in _PyEval_Vector.constprop.0 () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#33 0x00007ffff7b2be3a in PyEval_EvalCode () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#34 0x00007ffff7b56a10 in run_mod () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#35 0x00007ffff7b56d18 in PyRun_InteractiveOneObjectEx () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#36 0x00007ffff7b7359e in _PyRun_InteractiveLoopObject () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#37 0x00007ffff7b77959 in PyRun_AnyFileExFlags () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#38 0x00007ffff7b79b1e in Py_RunMain () from /nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/libpython3.11.so.1.0
#39 0x00007ffff763d10e in __libc_start_call_main () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/libc.so.6
#40 0x00007ffff763d1c9 in __libc_start_main_impl () from /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib/libc.so.6
#41 0x0000000000401075 in _start ()
```

Polars is on version 0.20.15, pytorch 2.2.2. Please let me know what other information would be helpful.

### Versions

PyTorch version: 2.2.2
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: NixOS 24.05 (Uakari) (x86_64)
GCC version: (GCC) 13.2.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.39

Python version: 3.11.8 (main, Feb  6 2024, 21:21:21) [GCC 13.2.0] (64-bit runtime)
Python platform: Linux-6.8.7-x86_64-with-glibc2.39
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:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        48 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               16
On-line CPU(s) list:                  0-15
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen 7 7700X 8-Core Processor
CPU family:                           25
Model:                                97
Thread(s) per core:                   2
Core(s) per socket:                   8
Socket(s):                            1
Stepping:                             2
CPU(s) scaling MHz:                   54%
CPU max MHz:                          5573.0000
CPU min MHz:                          400.0000
BogoMIPS:                             9000.29
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                       AMD-V
L1d cache:                            256 KiB (8 instances)
L1i cache:                            256 KiB (8 instances)
L2 cache:                             8 MiB (8 instances)
L3 cache:                             32 MiB (1 instance)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-15
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 Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Mitigation; Safe RET
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; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] torch==2.2.2
[pip3] triton==2.1.0
[conda] Could not collect

cc @seemethere @malfet @osalpekar @atalman