Training runs 50% slower when using 2 GPUs comparing to 1

fabiansc: <p>Hi,</p>
<p>I’m trying to train an InternImage model and I’m running into a weird issue using either Torchrun or torch.distributed.launch</p>
<p>I’m using the PyTorch Nvidia docker 22.04 with CUDA 11.6.2 and PyTorch 1.12.<br>
When I’m training the model using “python train.py …” the model runs well, however, when I try to take advantage of my 2 GPUs, I"m running into problems.</p>
<p>I can see that both my GPUs are running since their temperature is going up and their memory usage is going up, but while training the model with 1 GPU takes me 2.5 days, using the 2 GPUs, the model ETA is &gt; 3.5 days.</p>
<p>I don’t care that much about the time, but the main problem is that the training crashes after 1000 iterations, when it’s saving the first checkpoint. None of these issues is observed when I use 1 GPU.</p>
<p>I also looked at the status when the crash happens, there’s no RAM or GPU memory usage issue.</p>
<p>I’ll appreciate your help troubleshooting this problem.</p>
<p>I’m using WSL2, with Nvidia docker 22.04, and I have two RTX3090 GPUs.</p>
<p>This is the error I’m getting:</p>
<h1>
<a name="warningtorchdistributedelasticmultiprocessingapisending-process-19682-closing-signal-sigterm-errortorchdistributedelasticmultiprocessingapifailed-exitcode-9-local_rank-0-pid-19681-of-binary-optcondabinpython-traceback-most-recent-call-last-file-optcondabintorchrun-line-33-in-module-sysexitload_entry_pointtorch1120a0bd13bc6-console_scripts-torchrun-file-optcondalibpython38site-packagestorchdistributedelasticmultiprocessingerrors__init__py-line-345-in-wrapper-return-fargs-kwargs-file-optcondalibpython38site-packagestorchdistributedrunpy-line-761-in-main-runargs-file-optcondalibpython38site-packagestorchdistributedrunpy-line-752-in-run-elastic_launch-file-optcondalibpython38site-packagestorchdistributedlauncherapipy-line-131-in-__call__-return-launch_agentself_config-self_entrypoint-listargs-file-optcondalibpython38site-packagestorchdistributedlauncherapipy-line-245-in-launch_agent-raise-childfailederror-torchdistributedelasticmultiprocessingerrorschildfailederror-1" class="anchor" href="#warningtorchdistributedelasticmultiprocessingapisending-process-19682-closing-signal-sigterm-errortorchdistributedelasticmultiprocessingapifailed-exitcode-9-local_rank-0-pid-19681-of-binary-optcondabinpython-traceback-most-recent-call-last-file-optcondabintorchrun-line-33-in-module-sysexitload_entry_pointtorch1120a0bd13bc6-console_scripts-torchrun-file-optcondalibpython38site-packagestorchdistributedelasticmultiprocessingerrors__init__py-line-345-in-wrapper-return-fargs-kwargs-file-optcondalibpython38site-packagestorchdistributedrunpy-line-761-in-main-runargs-file-optcondalibpython38site-packagestorchdistributedrunpy-line-752-in-run-elastic_launch-file-optcondalibpython38site-packagestorchdistributedlauncherapipy-line-131-in-__call__-return-launch_agentself_config-self_entrypoint-listargs-file-optcondalibpython38site-packagestorchdistributedlauncherapipy-line-245-in-launch_agent-raise-childfailederror-torchdistributedelasticmultiprocessingerrorschildfailederror-1"></a>WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 19682 closing signal SIGTERM<br>
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: -9) local_rank: 0 (pid: 19681) of binary: /opt/conda/bin/python<br>
Traceback (most recent call last):<br>
File “/opt/conda/bin/torchrun”, line 33, in <br>
sys.exit(load_entry_point(‘torch==1.12.0a0+bd13bc6’, ‘console_scripts’, ‘torchrun’)())<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/elastic/multiprocessing/errors/<strong>init</strong>.py”, line 345, in wrapper<br>
return f(*args, **kwargs)<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/run.py”, line 761, in main<br>
run(args)<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/run.py”, line 752, in run<br>
elastic_launch(<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/launcher/api.py”, line 131, in <strong>call</strong><br>
return launch_agent(self._config, self._entrypoint, list(args))<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/launcher/api.py”, line 245, in launch_agent<br>
raise ChildFailedError(<br>
torch.distributed.elastic.multiprocessing.errors.ChildFailedError:</h1>
<h2>
<a name="trainpy-failed-2" class="anchor" href="#trainpy-failed-2"></a>train.py FAILED</h2>
<h2>
<a name="failures-no_other_failures-3" class="anchor" href="#failures-no_other_failures-3"></a>Failures:<br>
&lt;NO_OTHER_FAILURES&gt;</h2>
<h1>
<a name="root-cause-first-observed-failure-0-time-2023-04-06_211835-host-f56b97aeeef1-rank-0-local_rank-0-exitcode-9-pid-19681-error_file-na-traceback-signal-9-sigkill-received-by-pid-19681-4" class="anchor" href="#root-cause-first-observed-failure-0-time-2023-04-06_211835-host-f56b97aeeef1-rank-0-local_rank-0-exitcode-9-pid-19681-error_file-na-traceback-signal-9-sigkill-received-by-pid-19681-4"></a>Root Cause (first observed failure):<br>
[0]:<br>
time      : 2023-04-06_21:18:35<br>
host      : f56b97aeeef1<br>
rank      : 0 (local_rank: 0)<br>
exitcode  : -9 (pid: 19681)<br>
error_file: &lt;N/A&gt;<br>
traceback : Signal 9 (SIGKILL) received by PID 19681</h1>
<p>root@f56b97aeeef1:/workspace/InternImage/segmentation# /opt/conda/lib/python3.8/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 38 leaked semaphore objects to clean up at shutdown<br>
warnings.warn('resource_tracker: There appear to be %d ’<br>
/opt/conda/lib/python3.8/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 38 leaked semaphore objects to clean up at shutdown<br>
warnings.warn('resource_tracker: There appear to be %d ’</p>

ptrblck: <p>I don’t see a clear error being raised besides the <code>SIGKILL</code>, which could generally indicate that you might be running out of host RAM.<br>
Are you seeing the same issues using a newer container or the current <code>2.0.0</code> binaries?<br>
Also, you could try to rerun the code with more debugging flags mentioned e.g. <a href="https://pytorch.org/docs/stable/distributed.html#torch-distributed-debug">here</a>:</p>
<pre><code class="lang-auto">NCCL_DEBUG=INFO TORCH_DISTRIBUTED_DEBUG=INFO TORCH_SHOW_CPP_STACKTRACES=1 torchrun ...
</code></pre>
<p>to get more information about the failure.</p>

fabiansc: <p>Thanks for your response!</p>
<p>I followed the Performance tab in Task Manager (Windows) and I didn’t observe any memory spike, it’s constantly around 60%.I can give a newer version a try, but the model I’m trying to run has binaries adapted up to CUDA 11.6 and Torch 1.12. (That’s doesn’t say it wouldn’t work with newer versions of course)</p>
<p>The current 2.0.0 binaries gave me a hard time with converting models to ONNX, so I’m waiting for ONNX to catch up in order to go back to using them.</p>
<p>I ran the code with all the flags mentioned, and here’s the output I get now:</p>
<h1>
<a name="h-2023-04-09-104057962-mmseg-info-iter-950160000-lr-1059e-06-eta-3-days-83044-time-1835-data_time-0059-memory-17117-decodeloss_ce-00644-decodeacc_seg-991115-auxloss_ce-00824-auxacc_seg-984049-loss-01468-grad_norm-13862-2023-04-09-104229634-mmseg-info-saving-checkpoint-at-1000-iterations-warningtorchdistributedelasticmultiprocessingapisending-process-12289-closing-signal-sigterm-errortorchdistributedelasticmultiprocessingapifailed-exitcode-9-local_rank-0-pid-12288-of-binary-optcondabinpython-traceback-most-recent-call-last-file-optcondabintorchrun-line-33-in-module-sysexitload_entry_pointtorch1120a0bd13bc6-console_scripts-torchrun-file-optcondalibpython38site-packagestorchdistributedelasticmultiprocessingerrors__init__py-line-345-in-wrapper-return-fargs-kwargs-file-optcondalibpython38site-packagestorchdistributedrunpy-line-761-in-main-runargs-file-optcondalibpython38site-packagestorchdistributedrunpy-line-752-in-run-elastic_launch-file-optcondalibpython38site-packagestorchdistributedlauncherapipy-line-131-in-__call__-return-launch_agentself_config-self_entrypoint-listargs-file-optcondalibpython38site-packagestorchdistributedlauncherapipy-line-245-in-launch_agent-raise-childfailederror-torchdistributedelasticmultiprocessingerrorschildfailederror-1" class="anchor" href="#h-2023-04-09-104057962-mmseg-info-iter-950160000-lr-1059e-06-eta-3-days-83044-time-1835-data_time-0059-memory-17117-decodeloss_ce-00644-decodeacc_seg-991115-auxloss_ce-00824-auxacc_seg-984049-loss-01468-grad_norm-13862-2023-04-09-104229634-mmseg-info-saving-checkpoint-at-1000-iterations-warningtorchdistributedelasticmultiprocessingapisending-process-12289-closing-signal-sigterm-errortorchdistributedelasticmultiprocessingapifailed-exitcode-9-local_rank-0-pid-12288-of-binary-optcondabinpython-traceback-most-recent-call-last-file-optcondabintorchrun-line-33-in-module-sysexitload_entry_pointtorch1120a0bd13bc6-console_scripts-torchrun-file-optcondalibpython38site-packagestorchdistributedelasticmultiprocessingerrors__init__py-line-345-in-wrapper-return-fargs-kwargs-file-optcondalibpython38site-packagestorchdistributedrunpy-line-761-in-main-runargs-file-optcondalibpython38site-packagestorchdistributedrunpy-line-752-in-run-elastic_launch-file-optcondalibpython38site-packagestorchdistributedlauncherapipy-line-131-in-__call__-return-launch_agentself_config-self_entrypoint-listargs-file-optcondalibpython38site-packagestorchdistributedlauncherapipy-line-245-in-launch_agent-raise-childfailederror-torchdistributedelasticmultiprocessingerrorschildfailederror-1"></a>2023-04-09 10:40:57,962 - mmseg - INFO - Iter [950/160000]      lr: 1.059e-06, eta: 3 days, 8:30:44, time: 1.835, data_time: 0.059, memory: 17117, decode.loss_ce: 0.0644, decode.acc_seg: 99.1115, aux.loss_ce: 0.0824, aux.acc_seg: 98.4049, loss: 0.1468, grad_norm: 1.3862<br>
2023-04-09 10:42:29,634 - mmseg - INFO - Saving checkpoint at 1000 iterations<br>
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 12289 closing signal SIGTERM<br>
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: -9) local_rank: 0 (pid: 12288) of binary: /opt/conda/bin/python<br>
Traceback (most recent call last):<br>
File “/opt/conda/bin/torchrun”, line 33, in <br>
sys.exit(load_entry_point(‘torch==1.12.0a0+bd13bc6’, ‘console_scripts’, ‘torchrun’)())<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/elastic/multiprocessing/errors/<strong>init</strong>.py”, line 345, in wrapper<br>
return f(*args, **kwargs)<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/run.py”, line 761, in main<br>
run(args)<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/run.py”, line 752, in run<br>
elastic_launch(<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/launcher/api.py”, line 131, in <strong>call</strong><br>
return launch_agent(self._config, self._entrypoint, list(args))<br>
File “/opt/conda/lib/python3.8/site-packages/torch/distributed/launcher/api.py”, line 245, in launch_agent<br>
raise ChildFailedError(<br>
torch.distributed.elastic.multiprocessing.errors.ChildFailedError:</h1>
<h2>
<a name="trainpy-failed-2" class="anchor" href="#trainpy-failed-2"></a>train.py FAILED</h2>
<h2>
<a name="failures-no_other_failures-3" class="anchor" href="#failures-no_other_failures-3"></a>Failures:<br>
&lt;NO_OTHER_FAILURES&gt;</h2>
<h1>
<a name="root-cause-first-observed-failure-0-time-2023-04-09_104314-host-f56b97aeeef1-rank-0-local_rank-0-exitcode-9-pid-12288-error_file-na-traceback-signal-9-sigkill-received-by-pid-12288-4" class="anchor" href="#root-cause-first-observed-failure-0-time-2023-04-09_104314-host-f56b97aeeef1-rank-0-local_rank-0-exitcode-9-pid-12288-error_file-na-traceback-signal-9-sigkill-received-by-pid-12288-4"></a>Root Cause (first observed failure):<br>
[0]:<br>
time      : 2023-04-09_10:43:14<br>
host      : f56b97aeeef1<br>
rank      : 0 (local_rank: 0)<br>
exitcode  : -9 (pid: 12288)<br>
error_file: &lt;N/A&gt;<br>
traceback : Signal 9 (SIGKILL) received by PID 12288</h1>
<p>/opt/conda/lib/python3.8/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 38 leaked semaphore objects to clean up at shutdown<br>
warnings.warn('resource_tracker: There appear to be %d ’<br>
root@f56b97aeeef1:/workspace/InternImage/segmentation# /opt/conda/lib/python3.8/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 38 leaked semaphore objects to clean up at shutdown<br>
warnings.warn('resource_tracker: There appear to be %d ’</p>
<p>It seems to be stuck, it didn’t got me back to command line but rather it’s stuck with the “warngings.warn…”</p>
<p>Is there anything else to try before trying to use a more recent container? If a newer container doesn’t fix the problem, what else cold cause this?</p>

ptrblck: <p>I would try to narrow down why the <code>SIGKILL</code> is sent to the process as it still seems as if you would be running out of host RAM.<br>
<code>dmesg</code> can give you often more information and might show which process killed your training.</p>

fabiansc: <p>OK, so I agree it’s a memory issue.<br>
I took the same model and the “base” version of it didn’t crash when training with 2 GPUs.The problem is with heavier “XL” version.</p>
<p>I also dug a bit deeper. It’s not related to the checkpoint save since the checkpoint is created well. It crashes right as the model is about to start the validation evaluation step.</p>
<p>Is there anything that can be done to fix it?<br>
This is the repeating error on dmesg:</p>
<p>misc dxg: dxgk: dxgkio_reserve_gpu_va: Ioctl failed: -75</p>
<p>Is there any way to reduce the memory load while running evaluation?</p>

ptrblck: <p>The error message seems to be raised by WSL2 and I guess WSL2 itself might be running into trouble once you are running out of host RAM.<br>
You could try to delete unneeded objects before starting the evaluation run or generally wrap the training and evaluation into functions as Python will delete objects when exiting functions if these are not referenced anymore.</p>