Can I have different number of GPUs on different nodes while running distributed tasks?

imkzh: <p>Sadly, I have 2 nodes, one with 3 gpus and another with 2 gpus, and I failed to run a distributed training with all of them.</p>
<p>What I have tried:</p>
<ul>
<li>with <code>--nnodes=2 --nproc_per_node=3</code> on one node and <code>--nnodes=2 --nproc_per_node=2</code> on another.<br>
Pytorch seems support this setup, the program successfully rendezvoused with <code>global_world_sizes = [5,5,5] ([5,5] on another node)</code>, my training starts and then hang for ever (before dataloader, possibly on a barrier)</li>
</ul>
<details>
<summary>
log(--nodes=2 --nproc_per_node=x) first node</summary>
<pre data-code-wrap="console"><code class="lang-nohighlight">/home/train/.local/lib/python3.8/site-packages/torch/distributed/launch.py:163: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
  logger.warn(
The module torch.distributed.launch is deprecated and going to be removed in future.Migrate to torch.distributed.run
*****************************************
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. 
*****************************************
INFO:torch.distributed.launcher.api:Starting elastic_operator with launch configs:
  entrypoint       : STIP_main.py
  min_nodes        : 2
  max_nodes        : 2
  nproc_per_node   : 3
  run_id           : none
  rdzv_backend     : static
  rdzv_endpoint    : 10.12.0.2:30001
  rdzv_configs     : {'rank': 0, 'timeout': 900}
  max_restarts     : 3
  monitor_interval : 5
  log_dir          : None
  metrics_cfg      : {}

INFO:torch.distributed.elastic.agent.server.local_elastic_agent:log directory set to: /tmp/torchelastic_d9xbyhht/none_o0pk7dkt
INFO:torch.distributed.elastic.agent.server.api:[default] starting workers for entrypoint: python3
INFO:torch.distributed.elastic.agent.server.api:[default] Rendezvous'ing worker group
/home/train/.local/lib/python3.8/site-packages/torch/distributed/elastic/utils/store.py:52: FutureWarning: This is an experimental API and will be changed in future.
  warnings.warn(
INFO:torch.distributed.elastic.agent.server.api:[default] Rendezvous complete for workers. Result:
  restart_count=0
  master_addr=10.12.0.2
  master_port=30001
  group_rank=0
  group_world_size=2
  local_ranks=[0, 1, 2]
  role_ranks=[0, 1, 2]
  global_ranks=[0, 1, 2]
  role_world_sizes=[5, 5, 5]
  global_world_sizes=[5, 5, 5]

INFO:torch.distributed.elastic.agent.server.api:[default] Starting worker group
INFO:torch.distributed.elastic.multiprocessing:Setting worker0 reply file to: /tmp/torchelastic_d9xbyhht/none_o0pk7dkt/attempt_0/0/error.json
INFO:torch.distributed.elastic.multiprocessing:Setting worker1 reply file to: /tmp/torchelastic_d9xbyhht/none_o0pk7dkt/attempt_0/1/error.json
INFO:torch.distributed.elastic.multiprocessing:Setting worker2 reply file to: /tmp/torchelastic_d9xbyhht/none_o0pk7dkt/attempt_0/2/error.json
| distributed init (rank 0): env://
| distributed init (rank 2): env://
| distributed init (rank 1): env://
[W ProcessGroupNCCL.cpp:1569] Rank 0 using best-guess GPU 0 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect.Specify device_ids in barrier() to force use of a particular device.
[W ProcessGroupNCCL.cpp:1569] Rank 1 using best-guess GPU 1 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect.Specify device_ids in barrier() to force use of a particular device.
[W ProcessGroupNCCL.cpp:1569] Rank 2 using best-guess GPU 2 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect.Specify device_ids in barrier() to force use of a particular device.
Node0:1516058:1516058 [0] NCCL INFO Bootstrap : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1516058:1516058 [0] NCCL INFO NET/Plugin : No plugin found (libnccl-net.so), using internal implementation

Node0:1516058:1516058 [0] misc/ibvwrap.cc:63 NCCL WARN Failed to open libibverbs.so[.1]
Node0:1516058:1516058 [0] NCCL INFO NET/Socket : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1516058:1516058 [0] NCCL INFO Using network Socket
NCCL version 2.7.8+cuda11.1
Node0:1516059:1516059 [1] NCCL INFO Bootstrap : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1516059:1516059 [1] NCCL INFO NET/Plugin : No plugin found (libnccl-net.so), using internal implementation

Node0:1516059:1516059 [1] misc/ibvwrap.cc:63 NCCL WARN Failed to open libibverbs.so[.1]
Node0:1516059:1516059 [1] NCCL INFO NET/Socket : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1516059:1516059 [1] NCCL INFO Using network Socket
Node0:1516060:1516060 [2] NCCL INFO Bootstrap : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1516060:1516060 [2] NCCL INFO NET/Plugin : No plugin found (libnccl-net.so), using internal implementation

Node0:1516060:1516060 [2] misc/ibvwrap.cc:63 NCCL WARN Failed to open libibverbs.so[.1]
Node0:1516060:1516060 [2] NCCL INFO NET/Socket : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1516060:1516060 [2] NCCL INFO Using network Socket
Node0:1516060:1516101 [2] NCCL INFO threadThresholds 8/8/64 | 40/8/64 | 8/8/64
Node0:1516059:1516100 [1] NCCL INFO threadThresholds 8/8/64 | 40/8/64 | 8/8/64
Node0:1516060:1516101 [2] NCCL INFO Trees [0] -1/-1/-1-&gt;2-&gt;1|1-&gt;2-&gt;-1/-1/-1 [1] -1/-1/-1-&gt;2-&gt;1|1-&gt;2-&gt;-1/-1/-1
Node0:1516059:1516100 [1] NCCL INFO Trees [0] 2/3/-1-&gt;1-&gt;0|0-&gt;1-&gt;2/3/-1 [1] 2/-1/-1-&gt;1-&gt;0|0-&gt;1-&gt;2/-1/-1
Node0:1516058:1516099 [0] NCCL INFO Channel 00/02 :    0   1   2   3   4
Node0:1516058:1516099 [0] NCCL INFO Channel 01/02 :    0   1   2   3   4
Node0:1516058:1516099 [0] NCCL INFO threadThresholds 8/8/64 | 40/8/64 | 8/8/64
Node0:1516058:1516099 [0] NCCL INFO Trees [0] 1/-1/-1-&gt;0-&gt;-1|-1-&gt;0-&gt;1/-1/-1 [1] 1/-1/-1-&gt;0-&gt;4|4-&gt;0-&gt;1/-1/-1
Node0:1516060:1516101 [2] NCCL INFO Could not enable P2P between dev 2(=4000) and dev 1(=2000)
Node0:1516059:1516100 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node0:1516058:1516099 [0] NCCL INFO Channel 00 : 4[1000] -&gt; 0[1000] [receive] via NET/Socket/0
Node0:1516058:1516099 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node0:1516058:1516099 [0] NCCL INFO Channel 00 : 0[1000] -&gt; 1[2000] via direct shared memory
Node0:1516059:1516100 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 2(=4000)
Node0:1516059:1516100 [1] NCCL INFO Channel 00 : 1[2000] -&gt; 2[4000] via direct shared memory
Node0:1516060:1516101 [2] NCCL INFO Channel 00 : 2[4000] -&gt; 3[2000] [send] via NET/Socket/0
Node0:1516058:1516099 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node0:1516060:1516101 [2] NCCL INFO Could not enable P2P between dev 2(=4000) and dev 1(=2000)
Node0:1516060:1516101 [2] NCCL INFO Channel 00 : 2[4000] -&gt; 1[2000] via direct shared memory
Node0:1516059:1516100 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 2(=4000)
Node0:1516060:1516101 [2] NCCL INFO Could not enable P2P between dev 2(=4000) and dev 1(=2000)
Node0:1516059:1516100 [1] NCCL INFO Channel 00 : 3[2000] -&gt; 1[2000] [receive] via NET/Socket/0
Node0:1516059:1516100 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node0:1516059:1516100 [1] NCCL INFO Channel 00 : 1[2000] -&gt; 0[1000] via direct shared memory
Node0:1516058:1516099 [0] NCCL INFO Channel 01 : 4[1000] -&gt; 0[1000] [receive] via NET/Socket/0
Node0:1516058:1516099 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node0:1516058:1516099 [0] NCCL INFO Channel 01 : 0[1000] -&gt; 1[2000] via direct shared memory
Node0:1516060:1516101 [2] NCCL INFO Channel 01 : 2[4000] -&gt; 3[2000] [send] via NET/Socket/0
Node0:1516059:1516100 [1] NCCL INFO Channel 00 : 1[2000] -&gt; 3[2000] [send] via NET/Socket/0
Node0:1516059:1516100 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node0:1516059:1516100 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 2(=4000)
Node0:1516059:1516100 [1] NCCL INFO Channel 01 : 1[2000] -&gt; 2[4000] via direct shared memory
Node0:1516060:1516101 [2] NCCL INFO Could not enable P2P between dev 2(=4000) and dev 1(=2000)
Node0:1516060:1516101 [2] NCCL INFO Channel 01 : 2[4000] -&gt; 1[2000] via direct shared memory
Node0:1516058:1516099 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node0:1516059:1516100 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 2(=4000)
Node0:1516059:1516100 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node0:1516058:1516099 [0] NCCL INFO Channel 01 : 0[1000] -&gt; 4[1000] [send] via NET/Socket/0
Node0:1516059:1516100 [1] NCCL INFO Channel 01 : 1[2000] -&gt; 0[1000] via direct shared memory
Node0:1516058:1516099 [0] NCCL INFO 2 coll channels, 2 p2p channels, 1 p2p channels per peer
Node0:1516058:1516099 [0] NCCL INFO comm 0x7f3d64002e10 rank 0 nranks 5 cudaDev 0 busId 1000 - Init COMPLETE
Node0:1516058:1516058 [0] NCCL INFO Launch mode Parallel
Node0:1516060:1516101 [2] NCCL INFO 2 coll channels, 2 p2p channels, 1 p2p channels per peer
Node0:1516060:1516101 [2] NCCL INFO comm 0x7fd37c002e10 rank 2 nranks 5 cudaDev 2 busId 4000 - Init COMPLETE
Node0:1516059:1516100 [1] NCCL INFO 2 coll channels, 2 p2p channels, 1 p2p channels per peer
Node0:1516059:1516100 [1] NCCL INFO comm 0x7f18c8002e10 rank 1 nranks 5 cudaDev 1 busId 2000 - Init COMPLETE
loading annotations into memory...
Done (t=1.09s)
creating index...
index created!
loading annotations into memory...
Done (t=1.05s)
creating index...
index created!

[Logger] DETR Arguments:
	lr: 5e-05
	lr_backbone: 1e-05
	lr_drop: 80
	frozen_weights: None
	backbone: resnet50
	dilation: False
	position_embedding: sine
	enc_layers: 6
	dec_layers: 6
	num_queries: 100
	dataset_file: vcoco

[Logger] DETR_HOI Arguments:
	hoi_dec_layers: 6
	hoi_nheads: 8
	hoi_dim_feedforward: 2048
	hoi_idx_loss_coef: 1
	hoi_act_loss_coef: 1
	hoi_eos_coef: 0.1
	object_threshold: 0

[Logger] Number of total params:  56240935

[Logger] Number of trainable params:  14716167
Loading detr weights from args.detr_weights=pretrained/detr-r50-e632da11.pth

</code></pre>
</details>
<details>
<summary>
log(--nodes=2 --nproc_per_node=x) second node</summary>
<pre data-code-wrap="console"><code class="lang-nohighlight">/home/train/.local/lib/python3.8/site-packages/torch/distributed/launch.py:163: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
  logger.warn(
The module torch.distributed.launch is deprecated and going to be removed in future.Migrate to torch.distributed.run
*****************************************
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. 
*****************************************
INFO:torch.distributed.launcher.api:Starting elastic_operator with launch configs:
  entrypoint       : STIP_main.py
  min_nodes        : 2
  max_nodes        : 2
  nproc_per_node   : 2
  run_id           : none
  rdzv_backend     : static
  rdzv_endpoint    : 10.12.0.2:30001
  rdzv_configs     : {'rank': 1, 'timeout': 900}
  max_restarts     : 3
  monitor_interval : 5
  log_dir          : None
  metrics_cfg      : {}

INFO:torch.distributed.elastic.agent.server.local_elastic_agent:log directory set to: /tmp/torchelastic_oohtu0i7/none_d_b43gt4
INFO:torch.distributed.elastic.agent.server.api:[default] starting workers for entrypoint: python3
INFO:torch.distributed.elastic.agent.server.api:[default] Rendezvous'ing worker group
/home/train/.local/lib/python3.8/site-packages/torch/distributed/elastic/utils/store.py:52: FutureWarning: This is an experimental API and will be changed in future.
  warnings.warn(
INFO:torch.distributed.elastic.agent.server.api:[default] Rendezvous complete for workers. Result:
  restart_count=0
  master_addr=10.12.0.2
  master_port=30001
  group_rank=1
  group_world_size=2
  local_ranks=[0, 1]
  role_ranks=[3, 4]
  global_ranks=[3, 4]
  role_world_sizes=[5, 5]
  global_world_sizes=[5, 5]

INFO:torch.distributed.elastic.agent.server.api:[default] Starting worker group
INFO:torch.distributed.elastic.multiprocessing:Setting worker0 reply file to: /tmp/torchelastic_oohtu0i7/none_d_b43gt4/attempt_0/0/error.json
INFO:torch.distributed.elastic.multiprocessing:Setting worker1 reply file to: /tmp/torchelastic_oohtu0i7/none_d_b43gt4/attempt_0/1/error.json
| distributed init (rank 3): env://
| distributed init (rank 4): env://
[W ProcessGroupNCCL.cpp:1569] Rank 3 using best-guess GPU 1 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect.Specify device_ids in barrier() to force use of a particular device.
[W ProcessGroupNCCL.cpp:1569] Rank 4 using best-guess GPU 0 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect.Specify device_ids in barrier() to force use of a particular device.
Node1:3786256:3786256 [1] NCCL INFO Bootstrap : Using [0]enp5s0:10.12.0.3&lt;0&gt;
Node1:3786257:3786257 [0] NCCL INFO Bootstrap : Using [0]enp5s0:10.12.0.3&lt;0&gt;
Node1:3786256:3786256 [1] NCCL INFO NET/Plugin : No plugin found (libnccl-net.so), using internal implementation
Node1:3786257:3786257 [0] NCCL INFO NET/Plugin : No plugin found (libnccl-net.so), using internal implementation
Node1:3786256:3786256 [1] NCCL INFO NET/IB : No device found.
Node1:3786257:3786257 [0] NCCL INFO NET/IB : No device found.
Node1:3786257:3786257 [0] NCCL INFO NET/Socket : Using [0]enp5s0:10.12.0.3&lt;0&gt;
Node1:3786256:3786256 [1] NCCL INFO NET/Socket : Using [0]enp5s0:10.12.0.3&lt;0&gt;
Node1:3786257:3786257 [0] NCCL INFO Using network Socket
Node1:3786256:3786256 [1] NCCL INFO Using network Socket
Node1:3786257:3786293 [0] NCCL INFO threadThresholds 8/8/64 | 40/8/64 | 8/8/64
Node1:3786257:3786293 [0] NCCL INFO Trees [0] -1/-1/-1-&gt;4-&gt;3|3-&gt;4-&gt;-1/-1/-1 [1] 0/-1/-1-&gt;4-&gt;3|3-&gt;4-&gt;0/-1/-1
Node1:3786256:3786292 [1] NCCL INFO threadThresholds 8/8/64 | 40/8/64 | 8/8/64
Node1:3786256:3786292 [1] NCCL INFO Trees [0] 4/-1/-1-&gt;3-&gt;1|1-&gt;3-&gt;4/-1/-1 [1] 4/-1/-1-&gt;3-&gt;-1|-1-&gt;3-&gt;4/-1/-1
Node1:3786257:3786293 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node1:3786256:3786292 [1] NCCL INFO Channel 00 : 2[4000] -&gt; 3[2000] [receive] via NET/Socket/0
Node1:3786256:3786292 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node1:3786256:3786292 [1] NCCL INFO Channel 00 : 3[2000] -&gt; 4[1000] via direct shared memory
Node1:3786257:3786293 [0] NCCL INFO Channel 00 : 4[1000] -&gt; 0[1000] [send] via NET/Socket/0
Node1:3786256:3786292 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node1:3786257:3786293 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node1:3786257:3786293 [0] NCCL INFO Channel 00 : 4[1000] -&gt; 3[2000] via direct shared memory
Node1:3786257:3786293 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node1:3786256:3786292 [1] NCCL INFO Channel 00 : 3[2000] -&gt; 1[2000] [send] via NET/Socket/0
Node1:3786257:3786293 [0] NCCL INFO Channel 01 : 4[1000] -&gt; 0[1000] [send] via NET/Socket/0
Node1:3786256:3786292 [1] NCCL INFO Channel 00 : 1[2000] -&gt; 3[2000] [receive] via NET/Socket/0
Node1:3786256:3786292 [1] NCCL INFO Channel 01 : 2[4000] -&gt; 3[2000] [receive] via NET/Socket/0
Node1:3786256:3786292 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node1:3786256:3786292 [1] NCCL INFO Channel 01 : 3[2000] -&gt; 4[1000] via direct shared memory
Node1:3786256:3786292 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node1:3786257:3786293 [0] NCCL INFO Channel 01 : 0[1000] -&gt; 4[1000] [receive] via NET/Socket/0
Node1:3786257:3786293 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node1:3786257:3786293 [0] NCCL INFO Channel 01 : 4[1000] -&gt; 3[2000] via direct shared memory
Node1:3786256:3786292 [1] NCCL INFO 2 coll channels, 2 p2p channels, 1 p2p channels per peer
Node1:3786256:3786292 [1] NCCL INFO comm 0x7f0804002e10 rank 3 nranks 5 cudaDev 1 busId 2000 - Init COMPLETE
Node1:3786257:3786293 [0] NCCL INFO 2 coll channels, 2 p2p channels, 1 p2p channels per peer
Node1:3786257:3786293 [0] NCCL INFO comm 0x7fe758002e10 rank 4 nranks 5 cudaDev 0 busId 1000 - Init COMPLETE


</code></pre>
</details>
<hr>
<ul>
<li>with <code>--nnodes=5 --nproc_per_node=1</code> on both nodes, but run 3 instances on first node, and 2 instances on another.<br>
In this setup, the program throws an exception and hang, my program is not started.</li>
</ul>
<details>
<summary>
log(--nnodes=5 --nproc_per_node=1)</summary>
<pre data-code-wrap="console"><code class="lang-nohighlight">INFO:torch.distributed.elastic.agent.server.api:[default] Starting worker group
INFO:torch.distributed.elastic.multiprocessing:Setting worker0 reply file to: /tmp/torchelastic_qmf3r7x5/none_wf___urt/attempt_0/0/error.json
| distributed init (rank 0): env://
[W ProcessGroupNCCL.cpp:1569] Rank 0 using best-guess GPU 0 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect.Specify device_ids in barrier() to force use of a particular device.
Node0:1515236:1515236 [0] NCCL INFO Bootstrap : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1515236:1515236 [0] NCCL INFO NET/Plugin : No plugin found (libnccl-net.so), using internal implementation

Node0:1515236:1515236 [0] misc/ibvwrap.cc:63 NCCL WARN Failed to open libibverbs.so[.1]
Node0:1515236:1515236 [0] NCCL INFO NET/Socket : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1515236:1515236 [0] NCCL INFO Using network Socket
NCCL version 2.7.8+cuda11.1
Node0:1515236:1515389 [0] NCCL INFO Channel 00/02 :    0   1   2   3   4
Node0:1515236:1515389 [0] NCCL INFO Channel 01/02 :    0   1   2   3   4
Node0:1515236:1515389 [0] NCCL INFO threadThresholds 8/8/64 | 40/8/64 | 8/8/64
Node0:1515236:1515389 [0] NCCL INFO Trees [0] 1/-1/-1-&gt;0-&gt;-1|-1-&gt;0-&gt;1/-1/-1 [1] 1/-1/-1-&gt;0-&gt;4|4-&gt;0-&gt;1/-1/-1
Node0:1515236:1515389 [0] NCCL INFO Channel 00 : 4[2000] -&gt; 0[1000] [receive] via NET/Socket/0
Node0:1515236:1515389 [0] NCCL INFO Channel 00 : 0[1000] -&gt; 1[2000] via P2P/IPC
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying
Node0:1515236:1515389 [0] NCCL INFO Call to connect returned Connection refused, retrying

Node0:1515236:1515389 [0] include/socket.h:403 NCCL WARN Connect to 10.12.0.2&lt;58663&gt; failed : Connection refused
Node0:1515236:1515389 [0] NCCL INFO bootstrap.cc:95 -&gt; 2
Node0:1515236:1515389 [0] NCCL INFO bootstrap.cc:363 -&gt; 2
Node0:1515236:1515389 [0] NCCL INFO transport.cc:59 -&gt; 2
Node0:1515236:1515389 [0] NCCL INFO init.cc:766 -&gt; 2
Node0:1515236:1515389 [0] NCCL INFO init.cc:840 -&gt; 2
Node0:1515236:1515389 [0] NCCL INFO group.cc:73 -&gt; 2 [Async thread]

Traceback (most recent call last):
  File "STIP_main.py", line 300, in &lt;module&gt;
    main(args)
  File "STIP_main.py", line 43, in main
    utils.init_distributed_mode(args)
  File "/home/train/projects/python/stip/src/util/misc.py", line 304, in init_distributed_mode
    torch.distributed.barrier()
  File "/home/train/.local/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 2524, in barrier
    work = default_pg.barrier(opts=opts)
RuntimeError: NCCL error in: /pytorch/torch/lib/c10d/ProcessGroupNCCL.cpp:911, unhandled system error, NCCL version 2.7.8
ncclSystemError: System call (socket, malloc, munmap, etc) failed.
</code></pre>
</details>
<hr>
<ul>
<li>no problem with <code>--nnodes=2 --nproc_per_node=2</code> while wasting 1 gpu.</li>
</ul>
<details>
<summary>
log(--nnodes=2 --nproc_per_node=2)</summary>
<pre data-code-wrap="console"><code class="lang-nohighlight">/home/train/.local/lib/python3.8/site-packages/torch/distributed/launch.py:163: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
  logger.warn(
The module torch.distributed.launch is deprecated and going to be removed in future.Migrate to torch.distributed.run
*****************************************
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. 
*****************************************
INFO:torch.distributed.launcher.api:Starting elastic_operator with launch configs:
  entrypoint       : STIP_main.py
  min_nodes        : 2
  max_nodes        : 2
  nproc_per_node   : 2
  run_id           : none
  rdzv_backend     : static
  rdzv_endpoint    : 10.12.0.2:30001
  rdzv_configs     : {'rank': 0, 'timeout': 900}
  max_restarts     : 3
  monitor_interval : 5
  log_dir          : None
  metrics_cfg      : {}

INFO:torch.distributed.elastic.agent.server.local_elastic_agent:log directory set to: /tmp/torchelastic_x1c0_2bl/none_tv20nqe1
INFO:torch.distributed.elastic.agent.server.api:[default] starting workers for entrypoint: python3
INFO:torch.distributed.elastic.agent.server.api:[default] Rendezvous'ing worker group
/home/train/.local/lib/python3.8/site-packages/torch/distributed/elastic/utils/store.py:52: FutureWarning: This is an experimental API and will be changed in future.
  warnings.warn(
INFO:torch.distributed.elastic.agent.server.api:[default] Rendezvous complete for workers. Result:
  restart_count=0
  master_addr=10.12.0.2
  master_port=30001
  group_rank=0
  group_world_size=2
  local_ranks=[0, 1]
  role_ranks=[0, 1]
  global_ranks=[0, 1]
  role_world_sizes=[4, 4]
  global_world_sizes=[4, 4]

INFO:torch.distributed.elastic.agent.server.api:[default] Starting worker group
INFO:torch.distributed.elastic.multiprocessing:Setting worker0 reply file to: /tmp/torchelastic_x1c0_2bl/none_tv20nqe1/attempt_0/0/error.json
INFO:torch.distributed.elastic.multiprocessing:Setting worker1 reply file to: /tmp/torchelastic_x1c0_2bl/none_tv20nqe1/attempt_0/1/error.json
| distributed init (rank 1): env://
| distributed init (rank 0): env://
[W ProcessGroupNCCL.cpp:1569] Rank 0 using best-guess GPU 0 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect.Specify device_ids in barrier() to force use of a particular device.
[W ProcessGroupNCCL.cpp:1569] Rank 1 using best-guess GPU 1 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect.Specify device_ids in barrier() to force use of a particular device.
Node0:1515795:1515795 [0] NCCL INFO Bootstrap : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1515795:1515795 [0] NCCL INFO NET/Plugin : No plugin found (libnccl-net.so), using internal implementation

Node0:1515795:1515795 [0] misc/ibvwrap.cc:63 NCCL WARN Failed to open libibverbs.so[.1]
Node0:1515795:1515795 [0] NCCL INFO NET/Socket : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1515795:1515795 [0] NCCL INFO Using network Socket
NCCL version 2.7.8+cuda11.1
Node0:1515796:1515796 [1] NCCL INFO Bootstrap : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1515796:1515796 [1] NCCL INFO NET/Plugin : No plugin found (libnccl-net.so), using internal implementation

Node0:1515796:1515796 [1] misc/ibvwrap.cc:63 NCCL WARN Failed to open libibverbs.so[.1]
Node0:1515796:1515796 [1] NCCL INFO NET/Socket : Using [0]enp6s0:10.12.0.2&lt;0&gt;
Node0:1515796:1515796 [1] NCCL INFO Using network Socket
Node0:1515796:1515826 [1] NCCL INFO threadThresholds 8/8/64 | 32/8/64 | 8/8/64
Node0:1515796:1515826 [1] NCCL INFO Trees [0] 2/-1/-1-&gt;1-&gt;0|0-&gt;1-&gt;2/-1/-1 [1] -1/-1/-1-&gt;1-&gt;0|0-&gt;1-&gt;-1/-1/-1
Node0:1515795:1515825 [0] NCCL INFO Channel 00/02 :    0   1   2   3
Node0:1515795:1515825 [0] NCCL INFO Channel 01/02 :    0   1   2   3
Node0:1515795:1515825 [0] NCCL INFO threadThresholds 8/8/64 | 32/8/64 | 8/8/64
Node0:1515795:1515825 [0] NCCL INFO Trees [0] 1/-1/-1-&gt;0-&gt;-1|-1-&gt;0-&gt;1/-1/-1 [1] 1/-1/-1-&gt;0-&gt;3|3-&gt;0-&gt;1/-1/-1
Node0:1515796:1515826 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node0:1515795:1515825 [0] NCCL INFO Channel 00 : 3[2000] -&gt; 0[1000] [receive] via NET/Socket/0
Node0:1515795:1515825 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node0:1515795:1515825 [0] NCCL INFO Channel 00 : 0[1000] -&gt; 1[2000] via direct shared memory
Node0:1515796:1515826 [1] NCCL INFO Channel 00 : 1[2000] -&gt; 2[1000] [send] via NET/Socket/0
Node0:1515795:1515825 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node0:1515796:1515826 [1] NCCL INFO Channel 00 : 2[1000] -&gt; 1[2000] [receive] via NET/Socket/0
Node0:1515796:1515826 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node0:1515796:1515826 [1] NCCL INFO Channel 00 : 1[2000] -&gt; 0[1000] via direct shared memory
Node0:1515796:1515826 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node0:1515795:1515825 [0] NCCL INFO Channel 01 : 3[2000] -&gt; 0[1000] [receive] via NET/Socket/0
Node0:1515795:1515825 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node0:1515795:1515825 [0] NCCL INFO Channel 01 : 0[1000] -&gt; 1[2000] via direct shared memory
Node0:1515795:1515825 [0] NCCL INFO Could not enable P2P between dev 0(=1000) and dev 1(=2000)
Node0:1515796:1515826 [1] NCCL INFO Channel 01 : 1[2000] -&gt; 2[1000] [send] via NET/Socket/0
Node0:1515796:1515826 [1] NCCL INFO Could not enable P2P between dev 1(=2000) and dev 0(=1000)
Node0:1515796:1515826 [1] NCCL INFO Channel 01 : 1[2000] -&gt; 0[1000] via direct shared memory
Node0:1515796:1515826 [1] NCCL INFO 2 coll channels, 2 p2p channels, 1 p2p channels per peer
Node0:1515796:1515826 [1] NCCL INFO comm 0x7faa90002e10 rank 1 nranks 4 cudaDev 1 busId 2000 - Init COMPLETE
Node0:1515795:1515825 [0] NCCL INFO Channel 01 : 0[1000] -&gt; 3[2000] [send] via NET/Socket/0
Node0:1515795:1515825 [0] NCCL INFO 2 coll channels, 2 p2p channels, 1 p2p channels per peer
Node0:1515795:1515825 [0] NCCL INFO comm 0x7f5054002e10 rank 0 nranks 4 cudaDev 0 busId 1000 - Init COMPLETE
Node0:1515795:1515795 [0] NCCL INFO Launch mode Parallel
loading annotations into memory...
Done (t=1.01s)
creating index...
index created!
loading annotations into memory...
Done (t=1.02s)
creating index...
index created!

[Logger] DETR Arguments:
	lr: 5e-05
	lr_backbone: 1e-05
	lr_drop: 80
	frozen_weights: None
	backbone: resnet50
	dilation: False
	position_embedding: sine
	enc_layers: 6
	dec_layers: 6
	num_queries: 100
	dataset_file: vcoco

[Logger] DETR_HOI Arguments:
	hoi_dec_layers: 6
	hoi_nheads: 8
	hoi_dim_feedforward: 2048
	hoi_idx_loss_coef: 1
	hoi_act_loss_coef: 1
	hoi_eos_coef: 0.1
	object_threshold: 0

[Logger] Number of total params:  56240935

[Logger] Number of trainable params:  14716167
Loading detr weights from args.detr_weights=pretrained/detr-r50-e632da11.pth

&gt;&gt;&gt; Epoch #1
</code></pre>
</details>
<hr>
<ul>
<li>no problem with <code>--nnodes=1 --nproc_per_node=3</code> while wasting 1 node (2 gpus)</li>
</ul>
<hr>

aazzolini: <aside class="quote no-group" data-username="imkzh" data-post="1" data-topic="156709">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/imkzh/48/51491_2.png" class="avatar"> imkzh:</div>
<blockquote>
<p><code>rank 0</code></p>
</blockquote>
</aside>
<p><a class="mention" href="/u/d4l3k">@d4l3k</a> could you advise on the recommended way to launch this program with 3 GPUs on one node and 2 GPUs on the other?</p>

Levi_Ackerman: <p>I encountered the same issue before. Here is my solution:</p>
<ol>
<li>Launch one process per node using torchrun.</li>
<li>Initialize the first global process group, and each process collects the number of available CUDA devices of the node with torch.cuda.device_count(), and all gather the device information to all nodes.</li>
<li>Delete the above process group. For each node spawn the equal number of new processes as the number of CUDA devices of the node. Carefully calculate the new RANK and WORLD_SIZE for each new process. For example, if node 1 has 2 GPUs and node 2 has 3 GPUs, RANK should be “0, 1 for node 1” and “2, 3, 4 for node 2” and the total WORLD_SIZE is 5. Then initialize the final process group.</li>
</ol>

ojipadeson: <p><a class="mention" href="/u/levi_ackerman">@Levi_Ackerman</a> Could you give a running script? I have the same problem, but it’s hard for me to repeat your solution. Thank you very much!</p>

Kiuk_Chung: <p><a class="mention" href="/u/imkzh">@imkzh</a> seems like there is something in your training script that assumes homogeneous number of procs_per_node. Using a simple program that uses pytorch distributed to compute the world size by all-reducing a one-hot vector by rank (see the program here: <a href="https://github.com/pytorch/torchx/tree/main/torchx/examples/apps/compute_world_size" class="inline-onebox" rel="noopener nofollow ugc">torchx/torchx/examples/apps/compute_world_size at main · pytorch/torchx · GitHub</a>) I’ve been able to validate that heterogeneous nproc per node works when using torchrun:</p>
<p>Running 2 nodes, 1 proc on the first and 2 procs on the second for a total world size of 3</p>
<pre data-code-wrap="shell-session"><code class="lang-nohighlight">$ LOGLEVEL=INFO torchrun 
    --nnodes 2 
    --nproc_per_node 1 
    --rdzv_backend c10d 
    --rdzv_endpoint localhost:29500 
    main.py

$ LOGLEVEL=INFO torchrun 
    --nnodes 2 
    --nproc_per_node 2
    --rdzv_backend c10d 
    --rdzv_endpoint localhost:29500 
    main.py
</code></pre>
<p>Running the two commands above yields an output like so:</p>
<pre><code class="lang-auto">rank: 1, actual world_size: 3, computed world_size: 3
rank: 2, actual world_size: 3, computed world_size: 3
------------------------------------------------------
rank: 0, actual world_size: 3, computed world_size: 3
</code></pre>

Kiuk_Chung: <p>The above works equally well to GPUs (e.g. when the backend is nccl):</p>
<pre data-code-wrap="shell-session"><code class="lang-nohighlight">$ CUDA_VISIBLE_DEVICES=2 LOGLEVEL=INFO torchrun 
  --nnodes 2 
  --nproc_per_node 1 
  --rdzv_backend c10d 
  --rdzv_endpoint localhost:29500 
  main.py main.backend=nccl

$ CUDA_VISIBLE_DEVICES=0,1 LOGLEVEL=INFO torchrun 
  --nnodes 2 
  --nproc_per_node 2
  --rdzv_backend c10d 
  --rdzv_endpoint localhost:29500 
  main.py main.backend=nccl
</code></pre>