Torch.distributed.barrier doesn't work with pytorch 2.0 and Backend=NCCL

yeonju: <p>I still have the same problem with this (<a href="https://github.com/pytorch/pytorch/issues/98763" class="inline-onebox" rel="noopener nofollow ugc">torch.distributed.barrier Bug with pytorch 2.0 and Backend=NCCL · Issue #98763 · pytorch/pytorch · GitHub</a>)</p>
<pre><code class="lang-python">import os
import torch
import torch.distributed as dist
import torch.multiprocessing as mp

def run(rank, size):
    """ Distributed function to be implemented later. """
    print('Rank {} of {}.'.format(rank, size))
    torch.distributed.barrier()
    print('after barrier')
    pass

def init_process(rank, size, fn, backend='nccl'):
    """ Initialize the distributed environment. """
    os.environ['MASTER_ADDR'] = '127.0.0.1'
    os.environ['MASTER_PORT'] = '29500'
    torch.cuda.set_device(rank)
    dist.init_process_group(backend, rank=rank, world_size=size)
    fn(rank, size)


if __name__ == "__main__":
    size = 6
    processes = []
    mp.set_start_method("spawn")
    for rank in range(size):
        p = mp.Process(target=init_process, args=(rank, size, run))
        p.start()
        processes.append(p)

    for p in processes:
        p.join()
</code></pre>
<p>It stuck at barrier. It doesn’t print “after barrier”.<br>
And when it is in the barrier, GPU-util is almost 100%.<br>
What can be the problem? I already changed torch version, nvidia driver, cuda version, cudnn version so many times. Can you give me any recommendation that I can do?<br>
I already checked this code in another computer. It works well on the other computers.</p>
<h3><a name="versions-1" class="anchor" href="#versions-1"></a>Versions</h3>
<p>Collecting environment information…<br>
PyTorch version: 2.0.1+cu117<br>
Is debug build: False<br>
CUDA used to build PyTorch: 11.7<br>
ROCM used to build PyTorch: N/A</p>
<p>OS: Ubuntu 20.04.6 LTS (x86_64)<br>
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0<br>
Clang version: Could not collect<br>
CMake version: version 3.27.7<br>
Libc version: glibc-2.31</p>
<p>Python version: 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0] (64-bit runtime)<br>
Python platform: Linux-5.15.0-86-generic-x86_64-with-glibc2.31<br>
Is CUDA available: True<br>
CUDA runtime version: 11.7.99<br>
CUDA_MODULE_LOADING set to: LAZY<br>
GPU models and configuration:<br>
GPU 0: NVIDIA RTX A6000<br>
GPU 1: NVIDIA RTX A6000<br>
GPU 2: NVIDIA RTX A6000<br>
GPU 3: NVIDIA RTX A6000<br>
GPU 4: NVIDIA RTX A6000<br>
GPU 5: NVIDIA RTX A6000</p>
<p>Nvidia driver version: 535.113.01<br>
cuDNN version: Could not collect<br>
HIP runtime version: N/A<br>
MIOpen runtime version: N/A<br>
Is XNNPACK available: True</p>
<p>CPU:<br>
Architecture:                       x86_64<br>
CPU op-mode(s):                     32-bit, 64-bit<br>
Byte Order:                         Little Endian<br>
Address sizes:                      46 bits physical, 48 bits virtual<br>
CPU(s):                             40<br>
On-line CPU(s) list:                0-39<br>
Thread(s) per core:                 2<br>
Core(s) per socket:                 10<br>
Socket(s):                          2<br>
NUMA node(s):                       2<br>
Vendor ID:                          GenuineIntel<br>
CPU family:                         6<br>
Model:                              85<br>
Model name:                         Intel(R) Xeon(R) Silver 4114 CPU @ 2.20GHz<br>
Stepping:                           4<br>
CPU MHz:                            800.000<br>
CPU max MHz:                        3000.0000<br>
CPU min MHz:                        800.0000<br>
BogoMIPS:                           4400.00<br>
Virtualization:                     VT-x<br>
L1d cache:                          640 KiB<br>
L1i cache:                          640 KiB<br>
L2 cache:                           20 MiB<br>
L3 cache:                           27.5 MiB<br>
NUMA node0 CPU(s):                  0-9,20-29<br>
NUMA node1 CPU(s):                  10-19,30-39<br>
Vulnerability Gather data sampling: Mitigation; Microcode<br>
Vulnerability Itlb multihit:        KVM: Mitigation: VMX disabled<br>
Vulnerability L1tf:                 Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable<br>
Vulnerability Mds:                  Mitigation; Clear CPU buffers; SMT vulnerable<br>
Vulnerability Meltdown:             Mitigation; PTI<br>
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable<br>
Vulnerability Retbleed:             Mitigation; IBRS<br>
Vulnerability Spec rstack overflow: Not affected<br>
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl and seccomp<br>
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization<br>
Vulnerability Spectre v2:           Mitigation; IBRS, IBPB conditional, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected<br>
Vulnerability Srbds:                Not affected<br>
Vulnerability Tsx async abort:      Mitigation; Clear CPU buffers; SMT vulnerable<br>
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 pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm 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 md_clear flush_l1d arch_capabilities</p>
<p>Versions of relevant libraries:<br>
[pip3] numpy==1.26.1<br>
[pip3] open-clip-torch==2.22.0<br>
[pip3] torch==2.0.1+cu117<br>
[pip3] torchaudio==2.0.2+cu117<br>
[pip3] torchvision==0.15.2+cu117<br>
[pip3] triton==2.0.0<br>
[conda] numpy                     1.26.1                   pypi_0    pypi<br>
[conda] open-clip-torch           2.22.0                   pypi_0    pypi<br>
[conda] torch                     2.0.1+cu117              pypi_0    pypi<br>
[conda] torchaudio                2.0.2+cu117              pypi_0    pypi<br>
[conda] torchvision               0.15.2+cu117             pypi_0    pypi<br>
[conda] triton                    2.0.0                    pypi_0    pypi</p>
<pre><code class="lang-auto">### Tasks
</code></pre>

yeonju: <p>After setting NCCL_P2P_DISABLE=1, it was solved. Sorry for my silly question. I hope this can help the people who have the same problems.</p>

H-Huang: <p>That is interesting, disabling nccl p2p should not be necessary. If you reenable p2p and set <code>NCCL_DEBUG=INFO</code> I am curious about what the logs output, this is still something that we should fix. I am wondering why it doesn’t work on your specific machine.</p>

chopby: <p>I encountered a similar issue. When using 3090 or A5000, there were no problems, but when I ran the same code on A6000, it got stuck at the barrier. Looking at NCCL_DEBUG, it showed ‘Init COMPLETE’ and then went into an infinite loop without any further output. Anyway, it works after setting NCCL_P2P_DISABLE. Thank you!</p>