Repository: pytorch
Issue: Can only import torch after Tensorflow accessed its gpu device
Labels: module: cuda,triaged

### 🐛 Describe the bug

Hey folks,

I'm not sure wether this qualifies as a bug wrt torch, but I've struggled with this for a couple of days and wanted to share my -albeit hacky- solution and try to gain further insights as to what causes this deeply weird behaviour.
I would appreciate any hints as to what causes this behaviour, and how to get a clean solution for both libraries working in the same namespace.

I'm trying to get torch and tensorflow working in the same namespace, in a conda-environment that was set up according to the instructions provided over at https://www.tensorflow.org/install/pip.

providing this context:
```
which python3
/home/middeke-ma-a/.conda/envs/middeke_ma_a/bin/python3
export LD_LIBRARY_PATH=:/home/middeke-ma-a/.conda/envs/middeke_ma_a/lib/
```

this_works.py:
``` python3
import tensorflow as tf
tf.test.gpu_device_name() # [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
import torch
cond = (torch.cuda.is_available() and tf.test.gpu_device_name())
print(bool(cond)) # True
```

but this_doesnt_work.py:
``` python3
import tensorflow as tf
import torch # OSError: /home/middeke-ma-a/.conda/envs/middeke_ma_a/lib/python3.10/site-packages/nvidia/cublas/lib/libcublas.so.11: undefined symbol: cublasLtGetStatusString, version libcublasLt.so.11
```

When LD_LIBRARY_PATH is set, I can import tensorflow with gpu-support, but I can't import torch:
```
OSError: /home/middeke-ma-a/.conda/envs/middeke_ma_a/lib/python3.10/site-packages/nvidia/cublas/lib/libcublas.so.11: undefined symbol: cublasLtGetStatusString, version libcublasLt.so.11
```

When LD_LIBRARY_PATH isn't set, I can import torch (and `cuda.is_available() == True`), and tensorflow, but tensorflow can't access CUDA (`Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU`).

I understand that importing torch only works when LD_LIBRARY_PATH isn't set.
...So why does the import (and cuda in torch) work after importing + accessing the gpu-device in tf, all while LD_LIBRARY_PATH *is set*?

I would like a clean solution for this, but nothing I've tried so far works.  Wrapping the imports with `os.environ` accordingly has no meaningful effect; after unsetting LD_LIBRARY_PATH, the following script doesn't work:
```
import os
os.environ["LD_LIBRARY_PATH"] = ":/home/middeke-ma-a/.conda/envs/middeke_ma_a/lib/"
import tensorflow as tf # [...] Cannot dlopen some GPU libraries [...]
```

nor does unsetting the library path with os.environ before importing torch:
```
import tensorflow as tf
import os
os.environ["LD_LIBRARY_PATH"] = ""

import torch # OSError: /home/middeke-ma-a/.conda/envs/middeke_ma_a/lib/python3.10/site-packages/torch/lib/../../nvidia/cublas/lib/libcublas.so.11: undefined symbol: cublasLtGetStatusString, version libcublasLt.so.11
```

This being an issue that involves tensorflow and torch together, I'm not really sure who to ask about this. 

If this doesn't belong here, I'd appreciate a hint where to take this (Conda? Tensorflow?).


Kind regards

Max

### Versions

PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-60-generic-x86_64-with-glibc2.35
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1070
Nvidia driver version: 525.78.01
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   39 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          8
On-line CPU(s) list:             0-7
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
CPU family:                      6
Model:                           158
Thread(s) per core:              2
Core(s) per socket:              4
Socket(s):                       1
Stepping:                        9
CPU max MHz:                     4500.0000
CPU min MHz:                     800.0000
BogoMIPS:                        8400.00
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 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       128 KiB (4 instances)
L1i cache:                       128 KiB (4 instances)
L2 cache:                        1 MiB (4 instances)
L3 cache:                        8 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-7
Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:          Mitigation; IBRS
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; IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Mitigation; Microcode
Vulnerability Tsx async abort:   Mitigation; TSX disabled

Versions of relevant libraries:
[pip3] numpy==1.24.2
[pip3] torch==1.13.1
[conda] cudatoolkit               11.2.2              hbe64b41_10    conda-forge
[conda] numpy                     1.24.2                   pypi_0    pypi
[conda] torch                     1.13.1                   pypi_0    pypi


cc @ngimel