OOM when using DDP

jhp: <p>Hi i;m stuck right now in OOM issue.</p>
<pre><code class="lang-auto">| distributed init (rank 0): env://                                                                                                                                                                                                                                              
| distributed init (rank 2): env://                                                                                                                                                                                                                                              
| distributed init (rank 3): env://                                                                                                                                                                                                                                              
| distributed init (rank 1): env://                                                                                                                                                                                                                                              
Traceback (most recent call last):                                                                                                                                                                                                                                               
  File "main.py", line 228, in &lt;module&gt;                                                                                                                                                                                                                                          
    main(args)                                                                                                                                                                                                                                                                   
  File "main.py", line 45, in main                                                                                                                                                                                                                                               
    utils.init_distributed_mode(args)                                                                                                                                                                                                                                            
  File "/home/user/detr/util/misc.py", line 304, in init_distributed_mode                                                                                                                                                                                             
    torch.distributed.barrier()                                                                                                                                                                                                                                                  
  File "/home/user/.conda/envs/vt/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 2420, in barrier                                                                                                                                                  
    work = default_pg.barrier(opts=opts)                                                                                                                                                                                                                                         
RuntimeError: CUDA error: out of memory
</code></pre>
<p>Dont know why this happens even though no memory or process is on GPU.</p>
<p>Also I found that just a simple tensor load on GPU did not work. (i.e a=torch.randn((2,3)).to(‘cuda’) raise OOM)</p>
<p>I solve this issue by reboot the machine and I wonder is there any other solution except for reboot?</p>

ptrblck: <p>You could try to reset your device via:</p>
<pre><code class="lang-python">sudo rmmod nvidia_uvm
sudo modprobe nvidia_uvm
</code></pre>
<p>as it seems to be in a “bad state” (e.g. after using hibernate/sleep in Linux).</p>

jhp: <aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="133449">
<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/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p><code>nvidia_uvm</code></p>
</blockquote>
</aside>
<p>Thanks for reply.<br>
If I reboot machine as you’ve suggested, wouldn’t the same problem happen anymore?</p>

ptrblck: <p>No, I don’t think a single reboot could solve the issue in future runs.<br>
Depending on the root cause, you might be running into it again. E.g. I have to reset the device every time after using Ubuntu’s sleep mode.</p>

jhp: <p>Oh that’s too bad… Thanks anyway.</p>
<p>Ah one more question!<br>
Will the fixed seed reset after reboot or reinstall cuda driver? (i.e I use <code>torch.manual_seed(seed)</code> for reproducibility, and I wonder about some initialization changes after reboot.</p>

ptrblck: <p>No, the pseudorandom number generator should not change unless the reboot also changed your setup, i.e. updated CUDA (cuRAND) etc. However, even in this case you would need to rebuild PyTorch to see any differences.</p>