Repository: pytorch
Issue: Volatile GPU-Util keeps 100% when using torch.distributed.isend/irecv
Labels: oncall: distributed,triaged

### 🐛 Describe the bug

```python
import ray
import time
import torch
import torch.distributed as dist
from ray.air.util.torch_dist import (
    TorchDistributedWorker,
    init_torch_dist_process_group,
    shutdown_torch_dist_process_group,
)
from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy

@ray.remote(num_gpus=1)
class TestWorker(TorchDistributedWorker):
    def __init__(self):
        super().__init__()

    def run(self):
        rank = torch.distributed.get_rank()
        dev = f"cuda:{ray.get_gpu_ids()[0]}"
        tensor = torch.tensor([rank]).to(dev)

        if rank == 0:
            dist.send(tensor, 1)
        if rank == 1:
            dist.recv(tensor, 0)

        if rank == 0:
            print(time.time(), "send start")
            for i in range(8):
                tensor = torch.empty([512, 512, 512]).fill_(i).to(dev)
                dist.isend(tensor, 1)
            tensor = torch.tensor([rank]).to(dev)
            print(time.time(), "send end")
        if rank == 1:
            print(time.time(), "recv start")
            for i in range(8):
                time.sleep(5)
                tensor = torch.empty([512, 512, 512]).to(dev)
                dist.recv(tensor, 0)
                print(tensor[0][0][0])
            tensor = torch.tensor([rank]).to(dev)
            print(time.time(), "recv end")

        return tensor

def run_workers():
    placement_group = ray.util.placement_group(
        [{"CPU": 1, "GPU": 1}] * 4,
        strategy="STRICT_PACK",
    )
    ray.get(placement_group.ready(), timeout=1000)

    workers = [
        TestWorker.options(
            scheduling_strategy=PlacementGroupSchedulingStrategy(
                placement_group=placement_group
            )
        ).remote()
        for _ in range(4)
    ]

    init_torch_dist_process_group(workers, backend="nccl")
    ray.get([w.run.remote() for w in workers])
    shutdown_torch_dist_process_group(workers)

if __name__ == "__main__":
    run_workers()

```

when I run code above and watch GPU states using `watch -n 0.1 nvidia-smi`, I found that Volatile GPU-Util keeps 100%.
![image](https://github.com/pytorch/pytorch/assets/56420840/a0c5ddfa-a62b-455a-a8d5-754ba27e9b57)
I am not sure whether this async behavior will affect other compute tasks?

Whats more, I found that isend and irecv don't make effect if I don't do one synchronized send recv before them. Is there any more elegant approach to solve this? I refered to https://github.com/pytorch/pytorch/issues/122597 but `TORCH_NCCL_USE_COMM_NONBLOCKING=1` doesn't work for me.

### Versions

> PyTorch version: 2.1.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.3) 9.4.0
> Clang version: Could not collect
> CMake version: version 3.29.3
> Libc version: glibc-2.31
> 
> Python version: 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0] (64-bit runtime)
> Python platform: Linux-6.8.0-31-generic-x86_64-with-glibc2.31
> 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 4090
> GPU 1: NVIDIA GeForce RTX 4090
> GPU 2: NVIDIA GeForce RTX 4090
> GPU 3: NVIDIA GeForce RTX 4090
> GPU 4: NVIDIA GeForce RTX 4090
> GPU 5: NVIDIA GeForce RTX 4090
> GPU 6: NVIDIA GeForce RTX 4090
> GPU 7: NVIDIA GeForce RTX 4090
> 
> Nvidia driver version: 535.171.04
> cuDNN version: Probably one of the following:
> /usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.0
> /usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.0
> /usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.0
> /usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.0
> /usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.0
> /usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.0
> /usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.0
> 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:                        52 bits physical, 57 bits virtual
> CPU(s):                               128
> On-line CPU(s) list:                  0-127
> Thread(s) per core:                   2
> Core(s) per socket:                   32
> Socket(s):                            2
> NUMA node(s):                         2
> Vendor ID:                            GenuineIntel
> CPU family:                           6
> Model:                                143
> Model name:                           Intel(R) Xeon(R) Gold 6462C
> Stepping:                             8
> CPU MHz:                              3898.526
> CPU max MHz:                          3900.0000
> CPU min MHz:                          800.0000
> BogoMIPS:                             6600.00
> Virtualization:                       VT-x
> L1d cache:                            3 MiB
> L1i cache:                            2 MiB
> L2 cache:                             128 MiB
> L3 cache:                             120 MiB
> NUMA node0 CPU(s):                    0-31,64-95
> NUMA node1 CPU(s):                    32-63,96-127
> 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:   Not affected
> 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; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
> Vulnerability Srbds:                  Not affected
> Vulnerability Tsx async abort:        Not affected
> 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 tsc_known_freq 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 cat_l2 cdp_l3 intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect user_shstk avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr ibt amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
> 
> Versions of relevant libraries:
> [pip3] mypy-extensions==1.0.0
> [pip3] numpy==1.26.0
> [pip3] torch==2.1.2
> [pip3] torchaudio==2.1.0
> [pip3] torchelastic==0.2.2
> [pip3] torchvision==0.16.0
> [pip3] triton==2.1.0
> [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_46343  
> [conda] mkl-service               2.4.0           py310h5eee18b_1  
> [conda] mkl_fft                   1.3.8           py310h5eee18b_0  
> [conda] mkl_random                1.2.4           py310hdb19cb5_0  
> [conda] numpy                     1.26.0          py310h5f9d8c6_0  
> [conda] numpy-base                1.26.0          py310hb5e798b_0  
> [conda] pytorch-cuda              12.1                 ha16c6d3_5    pytorch
> [conda] pytorch-mutex             1.0                        cuda    pytorch
> [conda] torch                     2.1.2                    pypi_0    pypi
> [conda] torchaudio                2.1.0               py310_cu121    pytorch
> [conda] torchelastic              0.2.2                    pypi_0    pypi
> [conda] torchvision               0.16.0              py310_cu121    pytorch
> [conda] triton                    2.1.0                    pypi_0    pypiROCM Version: Could not collect
> Neuron SDK Version: N/A
> vLLM Version: 0.4.0
> vLLM Build Flags:
> CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
> GPU Topology:
> GPU0    GPU1    GPU2    GPU3    GPU4    GPU5    GPU6    GPU7    CPU Affinity    NUMA Affinity   GPU NUMA ID
> GPU0     X      PIX     NODE    NODE    SYS     SYS     SYS     SYS     0-31,64-95      0               N/A
> GPU1    PIX      X      NODE    NODE    SYS     SYS     SYS     SYS     0-31,64-95      0               N/A
> GPU2    NODE    NODE     X      PIX     SYS     SYS     SYS     SYS     0-31,64-95      0               N/A
> GPU3    NODE    NODE    PIX      X      SYS     SYS     SYS     SYS     0-31,64-95      0               N/A
> GPU4    SYS     SYS     SYS     SYS      X      PIX     NODE    NODE    32-63,96-127    1               N/A
> GPU5    SYS     SYS     SYS     SYS     PIX      X      NODE    NODE    32-63,96-127    1               N/A
> GPU6    SYS     SYS     SYS     SYS     NODE    NODE     X      PIX     32-63,96-127    1               N/A
> GPU7    SYS     SYS     SYS     SYS     NODE    NODE    PIX      X      32-63,96-127    1               N/A
> 
> Legend:
> 
>   X    = Self
>   SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
>   NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
>   PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
>   PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
>   PIX  = Connection traversing at most a single PCIe bridge
>   NV#  = Connection traversing a bonded set of # NVLinks

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