Repository: pytorch
Issue: AttributeError: 'NoneType' object has no attribute 'is_failed'
Labels: oncall: distributed,triaged

### 🐛 Describe the bug

When I run a distributed training with multiple GPUs in the same node, I get this error
This happens only when I use multiple GPUs in the same node. Using one GPU per node is working fine.

```
Traceback (most recent call last):                                      
  File "/home/3458/pytorch/venv/bin/torchrun", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/3458/pytorch/venv/lib/python3.11/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 348, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/3458/pytorch/venv/lib/python3.11/site-packages/torch/distributed/run.py", line 901, in main
    run(args)
  File "/home/3458/pytorch/venv/lib/python3.11/site-packages/torch/distributed/run.py", line 892, in run
    elastic_launch(
  File "/home/3458/pytorch/venv/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 133, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/3458/pytorch/venv/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 259, in launch_agent
    if result.is_failed():
       ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'is_failed'
```

Here is my torchrun command (in sbatch)
```
common_torchrun_cmd="torchrun \
    --nnodes $NUM_NODES \
    --nproc_per_node 2 \
    --rdzv_id $RANDOM \
    --rdzv_endpoint $MASTER_NODE_IP:$MASTER_PORT \
    --rdzv_backend c10d \
    cifar10_lightning.py \
    --epochs=1 \
    --batch-size=$BATCH \
    --exp-name=$EXP_NAME \
    --num-nodes=$NUM_NODES \
    --strategy=$STRATEGY \
    --model=$MODEL \
    --precision=$PRECISION"

srun $common_torchrun_cmd
```

I use PyTorch Lightning but it has no issues
```
def main():
    seed_everything(42)  # for reproducibility

    model = Model(loss_function=nn.CrossEntropyLoss(), num_classes=10)

    logger = CSVLogger(f"logs/{args.exp_name}/", name="csv_metrics")

    trainer = Trainer(
        max_epochs=args.epochs,
        strategy="ddp",
        accelerator="gpu",
        logger=logger,
        enable_progress_bar=True,
        num_nodes=args.num_nodes,
        log_every_n_steps=1,
        enable_model_summary=True,
        detect_anomaly=False,
        enable_checkpointing=False,
    )

    trainer.fit(model)
```

### Versions

Environment
```
$ python collect_env.py
Collecting environment information...
PyTorch version: 2.4.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: CentOS Linux release 7.8.2003 (Core) (x86_64)
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Clang version: Could not collect
CMake version: version 2.8.12.2
Libc version: glibc-2.17

Python version: 3.11.7 (main, Dec 15 2023, 18:12:31) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-3.10.0-1127.19.1.el7.x86_64-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: 12.4.131
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: Tesla V100-SXM2-32GB
Nvidia driver version: 550.54.15
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
Byte Order:            Little Endian
CPU(s):                48
On-line CPU(s) list:   0-47
Thread(s) per core:    1
Core(s) per socket:    24
Socket(s):             2
NUMA node(s):          4
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 85
Model name:            Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz
Stepping:              7
CPU MHz:               1000.000
CPU max MHz:           2401.0000
CPU min MHz:           1000.0000
BogoMIPS:              4800.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              1024K
L3 cache:              36608K
NUMA node0 CPU(s):     0-3,7,8,12-14,18-20
NUMA node1 CPU(s):     4-6,9-11,15-17,21-23
NUMA node2 CPU(s):     24-27,31-33,37-39,43,44
NUMA node3 CPU(s):     28-30,34-36,40-42,45-47
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 aperfmperf eagerfpu 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 epb cat_l3 cdp_l3 invpcid_single intel_ppin intel_pt ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke avx512_vnni md_clear spec_ctrl intel_stibp flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.25.0
[pip3] pytorch-lightning==2.4.0
[pip3] torch==2.4.0
[pip3] torch-tb-profiler==0.4.3
[pip3] torch-vision==0.1.6.dev0
[pip3] torchmetrics==1.4.0.post0
[pip3] torchvision==0.19.0
[pip3] triton==3.0.0
[conda] Could not collect
```

cc @XilunWu @H-Huang @awgu @kwen2501 @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @c-p-i-o