Debugging for error from torch.distributed.run

username: Hyeonuk_Woo
cooked: <p>Hi, I train my model with multi-gpu within single node.</p>
<p><code>python -u -m torch.distributed.run --nnodes=1 --nproc_per_node=gpu train.py</code></p>
<p>Unlike single GPU learning, error messages are not displayed normally during multi-GPU learning. I just get the message ChildFailedError. If I train with a single GPU without using DDP, the specific reason for the error is normally output (dimension error, out of memory error etc…).<br>
In a multi-GPU environment, does it not tell you a specific error originally?</p>
<p>.Below is the error message displayed when using multi-GPU. The cause of the error found out by using Single-GPU is memory overflow.</p>
<pre><code class="lang-auto">*****************************************
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:root:entering barrier
0
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 429248 closing signal SIGTERM
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 429250 closing signal SIGTERM
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 429251 closing signal SIGTERM
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 429252 closing signal SIGTERM
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 429253 closing signal SIGTERM
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 429254 closing signal SIGTERM
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 429255 closing signal SIGTERM
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 1 (pid: 429249) of binary: /home/dngusdnr1/anaconda3/envs/pytorch3d/bin/python
Traceback (most recent call last):
  File "/home/dngusdnr1/anaconda3/envs/pytorch3d/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/dngusdnr1/anaconda3/envs/pytorch3d/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/dngusdnr1/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/torch/distributed/run.py", line 723, in &lt;module&gt;
    main()
  File "/home/dngusdnr1/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 345, in wrapper
    return f(*args, **kwargs)
  File "/home/dngusdnr1/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/torch/distributed/run.py", line 719, in main
    run(args)
  File "/home/dngusdnr1/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/torch/distributed/run.py", line 710, in run
    elastic_launch(
  File "/home/dngusdnr1/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/torch/distributed/launcher/api.py", line 131, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
  File "/home/dngusdnr1/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/torch/distributed/launcher/api.py", line 259, in launch_agent
    raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError: 
============================================================
test.py FAILED
------------------------------------------------------------
Failures:
  &lt;NO_OTHER_FAILURES&gt;
------------------------------------------------------------
Root Cause (first observed failure):
[0]:
  time      : 2022-02-07_17:26:52
  host      : nova004
  rank      : 1 (local_rank: 1)
  exitcode  : 1 (pid: 429249)
  error_file: &lt;N/A&gt;
  traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
============================================================
</code></pre>

username: pbelevich
cooked: <p><a class="mention" href="/u/aivanou">@aivanou</a> <a class="mention" href="/u/kiuk_chung">@Kiuk_Chung</a>  ?</p>

username: Kiuk_Chung
cooked: <p>Take a look at the message towards the end of the paste that says <code>To enable traceback see: https://pytorch.org/docs/stable/elastic…</code>.  You have to annotate your main function with <code>@record</code> to have trainer errors propagate to the launcher process.</p>
<p>When you are running DDP, the trainers are created as child process of the launcher. When these child processes fail with an error (exception) by default the parent process (launcher) only knows about the exit code and not the full trace info (you can’t “try-catch” exceptions between processes). The <code>@record</code> annotation essentially wraps your trainer’s main function with a try-catch-write-the-traceinfo-into-a-file. Then the launcher looks at these trace files and writes and error summary for each rank (if a trace file was written)</p>

username: aivanou
cooked: <p><a class="mention" href="/u/hyeonuk_woo">@Hyeonuk_Woo</a> can you please give example of <code>train.py</code> that does not produce any errors?</p>
<p>I tried to just raise an exception and got the following output: <a href="https://pastebin.com/89GLnUy6" class="inline-onebox" rel="noopener nofollow ugc">*****************************************Setting OMP_NUM_THREADS environment v - Pastebin.com</a></p>
<p>Where you can see the root exception.</p>
<p>Also, can you try running it with:</p>
<p><code>LOGLEVEL=INFO python -u -m torch.distributed.run --nnodes=1 --nproc_per_node=gpu train.py</code> ?</p>

username: zimian_wei
cooked: <p>Have you solved this problem? I encountered the same situation.</p>

username: abrahamowos
cooked: <p>Please how do I add this to the HuggingFace trainer?</p>