Skip to content

torchrun failed to start workers on single node multi XPU #158722

@Xiao-Chenguang

Description

@Xiao-Chenguang

🐛 Describe the bug

torchrun with multi XPU failed to start workers. It only works with mpirun with PMI environment variables properly set in python scripts.

Here is a minimal example:

import os

import torch
import torch.distributed as dist

if "PMI_SIZE" in os.environ:
    # if invoked by mpirun, use PMI env vars
    os.environ["MASTER_ADDR"] = "127.0.0.1"
    os.environ["MASTER_PORT"] = "29500"
    os.environ["RANK"] = str(os.environ.get("PMI_RANK", 0))
    os.environ["WORLD_SIZE"] = str(os.environ.get("PMI_SIZE", 1))
else:
    # if invoked by torchrun, set PMI env vars
    os.environ["PMI_RANK"] = os.environ["RANK"]
    os.environ["PMI_SIZE"] = os.environ["WORLD_SIZE"]

backend = "xccl"
dist.init_process_group(backend)

my_rank = dist.get_rank()
my_size = dist.get_world_size()
print("my rank = %d  my size = %d" % (my_rank, my_size))

device = torch.device("xpu:%d" % my_rank)

x = torch.ones([2, 2]).to(device)
y = torch.ones([4, 4]).to(device)
for _ in range(3):
    x += my_rank
    y *= my_rank + 2
    print("my rank = %d  x = %s  y = %s" % (my_rank, x, y))
    dist.all_reduce(x)
    dist.all_reduce(y)
    print("my rank = %d  x = %s  y = %s" % (my_rank, x, y))
    print("=" * 20)
dist.destroy_process_group()

It works with mpirun -np 2 python example.py but not with torchrun --nproc-per-node 2 example.py.

Error message is:

my rank = 1  my size = 2
my rank = 0  my size = 2
my rank = 1  x = tensor([[2., 2.],
        [2., 2.]], device='xpu:1')  y = tensor([[3., 3., 3., 3.],
        [3., 3., 3., 3.],
        [3., 3., 3., 3.],
        [3., 3., 3., 3.]], device='xpu:1')
2025:07:20-21:10:27:(1988946) |CCL_WARN| could not get local_idx/count from environment variables, trying to get them from ATL
my rank = 0  x = tensor([[1., 1.],
        [1., 1.]], device='xpu:0')  y = tensor([[2., 2., 2., 2.],
        [2., 2., 2., 2.],
        [2., 2., 2., 2.],
        [2., 2., 2., 2.]], device='xpu:0')
2025:07:20-21:10:27:(1988945) |CCL_WARN| could not get local_idx/count from environment variables, trying to get them from ATL
Abort(1090831) on node 0 (rank 0 in comm 0): Fatal error in PMPI_Init_thread: Unknown error class, error stack:
MPIR_Init_thread(196): 
MPID_Init(1612)......: 
MPIR_pmi_init(180)...: PMI2_Job_GetId returned 14
Abort(1090831) on node 0 (rank 0 in comm 0): Fatal error in PMPI_Init_thread: Unknown error class, error stack:
MPIR_Init_thread(196): 
MPID_Init(1612)......: 
MPIR_pmi_init(180)...: PMI2_Job_GetId returned 14
E0720 21:10:28.361000 1988922 torch/distributed/elastic/multiprocessing/api.py:874] failed (exitcode: 1) local_rank: 0 (pid: 1988945) of binary: /rds/project/rds-CNuoyfv7vNc/Chenguang/projects/mgpu/.venv/bin/python3
Traceback (most recent call last):
  File "/rds/project/rds-CNuoyfv7vNc/Chenguang/projects/mgpu/.venv/bin/torchrun", line 10, in <module>
    sys.exit(main())
  File "/rds/project/rds-CNuoyfv7vNc/Chenguang/projects/mgpu/.venv/lib/python3.10/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 357, in wrapper
    return f(*args, **kwargs)
  File "/rds/project/rds-CNuoyfv7vNc/Chenguang/projects/mgpu/.venv/lib/python3.10/site-packages/torch/distributed/run.py", line 901, in main
    run(args)
  File "/rds/project/rds-CNuoyfv7vNc/Chenguang/projects/mgpu/.venv/lib/python3.10/site-packages/torch/distributed/run.py", line 892, in run
    elastic_launch(
  File "/rds/project/rds-CNuoyfv7vNc/Chenguang/projects/mgpu/.venv/lib/python3.10/site-packages/torch/distributed/launcher/api.py", line 143, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
  File "/rds/project/rds-CNuoyfv7vNc/Chenguang/projects/mgpu/.venv/lib/python3.10/site-packages/torch/distributed/launcher/api.py", line 277, in launch_agent
    raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError: 
============================================================
ccl-test.py FAILED
------------------------------------------------------------
Failures:
[1]:
  time      : 2025-07-20_21:10:28
  host      : pvc-s-2.data.cluster
  rank      : 1 (local_rank: 1)
  exitcode  : 1 (pid: 1988946)
  error_file: <N/A>
  traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
------------------------------------------------------------
Root Cause (first observed failure):
[0]:
  time      : 2025-07-20_21:10:28
  host      : pvc-s-2.data.cluster
  rank      : 0 (local_rank: 0)
  exitcode  : 1 (pid: 1988945)
  error_file: <N/A>
  traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
============================================================

Python environments:

Package Version
accelerate 1.9.0
certifi 2024.8.30
charset-normalizer 3.3.2
dpcpp-cpp-rt 2025.1.1
filelock 3.18.0
fsspec 2025.5.1
huggingface-hub 0.25.1
idna 3.10
impi-rt 2021.15.0
intel-cmplr-lib-rt 2025.1.1
intel-cmplr-lib-ur 2025.1.1
intel-cmplr-lic-rt 2025.1.1
intel-opencl-rt 2025.1.1
intel-openmp 2025.1.1
intel-pti 0.12.3
intel-sycl-rt 2025.1.1
jinja2 3.1.6
markupsafe 2.1.5
mkl 2025.1.0
mpmath 1.3.0
networkx 3.4.2
numpy 2.1.2
oneccl 2021.15.2
oneccl-devel 2021.15.2
onemkl-sycl-blas 2025.1.0
onemkl-sycl-dft 2025.1.0
onemkl-sycl-lapack 2025.1.0
onemkl-sycl-rng 2025.1.0
onemkl-sycl-sparse 2025.1.0
packaging 24.1
pillow 11.3.0
psutil 6.0.0
pytorch-triton-xpu 3.4.0+gitae324eea
pyyaml 6.0.2
requests 2.32.3
safetensors 0.4.5
setuptools 78.1.0
sympy 1.14.0
tbb 2022.1.0
tcmlib 1.3.0
timm 1.0.17
torch 2.8.0.dev20250627+xpu
torchvision 0.23.0.dev20250627+xpu
tqdm 4.66.5
typing-extensions 4.14.0
umf 0.10.0
urllib3 2.2.3

python version: 3.10
OS: Linux

Versions

PyTorch version: 2.8.0.dev20250627+xpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Rocky Linux 9.6 (Blue Onyx) (x86_64)
GCC version: (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5)
Clang version: Could not collect
CMake version: version 3.26.5
Libc version: glibc-2.34

Python version: 3.10.17 (main, Apr 9 2025, 04:03:39) [Clang 20.1.0 ] (64-bit runtime)
Python platform: Linux-5.14.0-427.70.1.el9_4.x86_64-x86_64-with-glibc2.34
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: True
XPU used to build PyTorch: 20250101
Intel GPU driver version:

Intel GPU models onboard:

  • Intel(R) Data Center GPU Max 1550
  • Intel(R) Data Center GPU Max 1550
  • Intel(R) Data Center GPU Max 1550
  • Intel(R) Data Center GPU Max 1550
    Intel GPU models detected:
  • [0] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1550', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', driver_version='1.6.32567+19', total_memory=65536MB, max_compute_units=512, gpu_eu_count=512, gpu_subslice_count=64, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
  • [1] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1550', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', driver_version='1.6.32567+19', total_memory=65536MB, max_compute_units=512, gpu_eu_count=512, gpu_subslice_count=64, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
    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: 52 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 96
On-line CPU(s) list: 0-95
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Platinum 8468
CPU family: 6
Model: 143
Thread(s) per core: 1
Core(s) per socket: 48
Socket(s): 2
Stepping: 8
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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl 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 cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced 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 avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts 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
L1d cache: 4.5 MiB (96 instances)
L1i cache: 3 MiB (96 instances)
L2 cache: 192 MiB (96 instances)
L3 cache: 210 MiB (2 instances)
NUMA node(s): 2
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95
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

Versions of relevant libraries:
[pip3] Could not collect
[conda] Could not collect

cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta @gujinghui @EikanWang @fengyuan14 @guangyey

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: xpuIntel XPU related issuesoncall: distributedAdd this issue/PR to distributed oncall triage queuetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions