Skip to content

Importing torch.utils.benchmark causes torch.distributed to "Duplicate GPU detected" #129385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
qyhfrank opened this issue Jun 24, 2024 · 2 comments
Labels
module: benchmark related to torch.utils.benchmark e.g. Timer oncall: distributed Add this issue/PR to distributed oncall triage queue triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@qyhfrank
Copy link

qyhfrank commented Jun 24, 2024

🐛 Describe the bug

After learning about PyTorch Benchmark, I want to use it to conduct some performance tests on torch.distributed. I'm not sure if my use cases or usage are correct, but I did encounter the "Duplicate GPU detected" issue after importing torch.utils.benchmark. Here is a simple reproduction code.

import os
import torch
import torch.distributed as dist
import torch.utils.benchmark as benchmark

os.environ['CUDA_VISIBLE_DEVICES'] = os.environ['LOCAL_RANK']
dist.init_process_group(backend="nccl")

x = torch.randn(1024, 1024, device='cuda')

if dist.get_rank() == 0:
    dist.send(x[0], 1)
elif dist.get_rank() == 1:
    dist.recv(x[0], 0)

I got:

> torchrun --nproc_per_node=2 reproduce.py  
W0624 16:39:03.239000 140211528943424 torch/distributed/run.py:757] 
W0624 16:39:03.239000 140211528943424 torch/distributed/run.py:757] *****************************************
W0624 16:39:03.239000 140211528943424 torch/distributed/run.py:757] Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed. 
W0624 16:39:03.239000 140211528943424 torch/distributed/run.py:757] *****************************************
:4171735:4171735 [0] NCCL INFO Bootstrap : Using enp216s0np0:10.22.1.28<0>
:4171735:4171735 [0] NCCL INFO NET/Plugin : dlerror=libnccl-net.so: cannot open shared object file: No such file or directory No plugin found (libnccl-net.so), using internal implementation
:4171735:4171735 [0] NCCL INFO cudaDriverVersion 12040
NCCL version 2.20.5+cuda12.1
:4171736:4171736 [0] NCCL INFO cudaDriverVersion 12040
:4171736:4171736 [0] NCCL INFO Bootstrap : Using enp216s0np0:10.22.1.28<0>
:4171736:4171736 [0] NCCL INFO NET/Plugin : dlerror=libnccl-net.so: cannot open shared object file: No such file or directory No plugin found (libnccl-net.so), using internal implementation
:4171736:4171805 [0] NCCL INFO Failed to open libibverbs.so[.1]
:4171736:4171805 [0] NCCL INFO NET/Socket : Using [0]enp216s0np0:10.22.1.28<0> [1]eno1:202.45.128.187<0>
:4171736:4171805 [0] NCCL INFO Using non-device net plugin version 0
:4171736:4171805 [0] NCCL INFO Using network Socket
:4171735:4171803 [0] NCCL INFO Failed to open libibverbs.so[.1]
:4171735:4171803 [0] NCCL INFO NET/Socket : Using [0]enp216s0np0:10.22.1.28<0> [1]eno1:202.45.128.187<0>
:4171735:4171803 [0] NCCL INFO Using non-device net plugin version 0
:4171735:4171803 [0] NCCL INFO Using network Socket
:4171735:4171803 [0] NCCL INFO comm 0x8debb50 rank 0 nranks 2 cudaDev 0 nvmlDev 0 busId 18000 commId 0x4308f363c654c4af - Init START
:4171736:4171805 [0] NCCL INFO comm 0x8714a70 rank 1 nranks 2 cudaDev 0 nvmlDev 0 busId 18000 commId 0x4308f363c654c4af - Init START

:4171735:4171803 [0] init.cc:871 NCCL WARN Duplicate GPU detected : rank 0 and rank 1 both on CUDA device 18000
:4171735:4171803 [0] NCCL INFO init.cc:1501 -> 5

:4171736:4171805 [0] init.cc:871 NCCL WARN Duplicate GPU detected : rank 1 and rank 0 both on CUDA device 18000
:4171735:4171803 [0] NCCL INFO group.cc:64 -> 5 [Async thread]
:4171736:4171805 [0] NCCL INFO init.cc:1501 -> 5
:4171736:4171805 [0] NCCL INFO group.cc:64 -> 5 [Async thread]
:4171735:4171735 [0] NCCL INFO group.cc:418 -> 5
:4171735:4171735 [0] NCCL INFO group.cc:95 -> 5
:4171736:4171736 [0] NCCL INFO group.cc:418 -> 5
:4171736:4171736 [0] NCCL INFO group.cc:95 -> 5
[rank0]: Traceback (most recent call last):
[rank0]:   File "/path/to/reproduce.py", line 12, in <module>
[rank0]:     dist.send(x[0], 1)
[rank0]:   File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 75, in wrapper
[rank0]:     return func(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 1883, in send
[rank0]:     default_pg.send([tensor], dst, tag).wait()
[rank0]:     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: torch.distributed.DistBackendError: NCCL error in: /opt/conda/conda-bld/pytorch_1716905969073/work/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:1970, invalid usage (run with NCCL_DEBUG=WARN for details), NCCL version 2.20.5
[rank0]: ncclInvalidUsage: This usually reflects invalid usage of NCCL library.
[rank0]: Last error:
[rank0]: Duplicate GPU detected : rank 0 and rank 1 both on CUDA device 18000
[rank1]: Traceback (most recent call last):
[rank1]:   File "/path/to/reproduce.py", line 14, in <module>
[rank1]:     dist.recv(x[0], 0)
[rank1]:   File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 75, in wrapper
[rank1]:     return func(*args, **kwargs)
[rank1]:            ^^^^^^^^^^^^^^^^^^^^^
[rank1]:   File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 1929, in recv
[rank1]:     pg.recv([tensor], src, tag).wait()
[rank1]:     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank1]: torch.distributed.DistBackendError: NCCL error in: /opt/conda/conda-bld/pytorch_1716905969073/work/torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp:1970, invalid usage (run with NCCL_DEBUG=WARN for details), NCCL version 2.20.5
[rank1]: ncclInvalidUsage: This usually reflects invalid usage of NCCL library.
[rank1]: Last error:
[rank1]: Duplicate GPU detected : rank 1 and rank 0 both on CUDA device 18000
:4171736:4171816 [0] NCCL INFO comm 0x8714a70 rank 1 nranks 2 cudaDev 0 busId 18000 - Abort COMPLETE
:4171735:4171817 [0] NCCL INFO comm 0x8debb50 rank 0 nranks 2 cudaDev 0 busId 18000 - Abort COMPLETE
E0624 16:39:08.245000 140211528943424 torch/distributed/elastic/multiprocessing/api.py:826] failed (exitcode: 1) local_rank: 0 (pid: 4171735) of binary: /path/to/miniconda3/envs/main/bin/python
Traceback (most recent call last):
  File "/path/to/miniconda3/envs/main/bin/torchrun", line 33, in <module>
    sys.exit(load_entry_point('torch==2.3.1', 'console_scripts', 'torchrun')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 347, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/run.py", line 879, in main
    run(args)
  File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/run.py", line 870, in run
    elastic_launch(
  File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 132, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/miniconda3/envs/main/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 263, in launch_agent
    raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError: 
============================================================
nccl/reproduce.py FAILED
------------------------------------------------------------
Failures:
[1]:
  time      : 2024-06-24_16:39:08
  host      : 
  rank      : 1 (local_rank: 1)
  exitcode  : 1 (pid: 4171736)
  error_file: <N/A>
  traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
------------------------------------------------------------
Root Cause (first observed failure):
[0]:
  time      : 2024-06-24_16:39:08
  host      : 
  rank      : 0 (local_rank: 0)
  exitcode  : 1 (pid: 4171735)
  error_file: <N/A>
  traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
============================================================

But if I remove import torch.utils.benchmark as benchmark, then the program runs normally.

Versions

PyTorch version: 2.3.1
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.29.2
Libc version: glibc-2.35

Python version: 3.11.5 (main, Sep 11 2023, 13:54:46) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-112-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.1.105
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090
GPU 2: NVIDIA GeForce RTX 3090
GPU 3: NVIDIA GeForce RTX 3090

Nvidia driver version: 550.67
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
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz
CPU family: 6
Model: 85
Thread(s) per core: 2
Core(s) per socket: 16
Socket(s): 2
Stepping: 7
CPU max MHz: 3200.0000
CPU min MHz: 800.0000
BogoMIPS: 4200.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 smx 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 epb cat_l3 cdp_l3 invpcid_single intel_ppin 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 pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 1 MiB (32 instances)
L1i cache: 1 MiB (32 instances)
L2 cache: 32 MiB (32 instances)
L3 cache: 44 MiB (2 instances)
NUMA node(s): 2
NUMA node0 CPU(s): 0-15,32-47
NUMA node1 CPU(s): 16-31,48-63
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; BHI Syscall hardening, KVM SW loop
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Mitigation; TSX disabled

Versions of relevant libraries:
[pip3] numpy==1.26.0
[pip3] torch==2.3.1
[pip3] torchaudio==2.3.1
[pip3] torchvision==0.18.1
[pip3] triton==2.3.1
[conda] blas 1.0 mkl
[conda] ffmpeg 4.3 hf484d3e_0 pytorch
[conda] libjpeg-turbo 2.0.0 h9bf148f_0 pytorch
[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.0 py311h08b1b3b_0
[conda] numpy-base 1.26.0 py311hf175353_0
[conda] pytorch 2.3.1 py3.11_cuda12.1_cudnn8.9.2_0 pytorch
[conda] pytorch-cuda 12.1 ha16c6d3_5 pytorch
[conda] pytorch-mutex 1.0 cuda pytorch
[conda] torchaudio 2.3.1 py311_cu121 pytorch
[conda] torchtriton 2.3.1 py311 pytorch
[conda] torchvision 0.18.1 py311_cu121 pytorch

cc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu @fegin @XilunWu @wanchaol @fduwjj @wz337 @tianyu-l @wconstab @yf225 @chauhang @d4l3k

@jbschlosser jbschlosser added oncall: distributed Add this issue/PR to distributed oncall triage queue module: benchmark related to torch.utils.benchmark e.g. Timer labels Jun 26, 2024
@XilunWu
Copy link
Contributor

XilunWu commented Jul 1, 2024

Could be caused by #80876 (comment) so I suggest either try having CUDA_VISIBLE_DEVICES set up when launching the program or use https://pytorch.org/docs/stable/generated/torch.cuda.set_device.html

@XilunWu XilunWu added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jul 1, 2024
@qyhfrank
Copy link
Author

qyhfrank commented Jul 2, 2024

I think it actually solves the problem. I moved the line os.environ['CUDA_VISIBLE_DEVICES'] = os.environ['LOCAL_RANK'] above the line import torch.utils.benchmark as benchmark to set the cuda device earlier. Thanks for your help!

@XilunWu XilunWu closed this as completed Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: benchmark related to torch.utils.benchmark e.g. Timer oncall: distributed Add this issue/PR to distributed oncall triage queue triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants