Memory problem of testing large 8K images on GPUs

111414: <p>Thanks for noticing this post!</p>
<p>I have an image denoising network (it is a CNN) that takes an image of size <code>1*H*W</code> as input and generates a smoothed image version of size <code>1*H*W</code>. Now I have four NVIDIA RTX 3090 GPUs and 100 large 8K images of size <code>1*7680*4320</code>. I want to run a test on them. However, the memory of one GPU seems not enough for such a high resolution. The following shows my requirements and some efforts/questions:</p>
<p><strong>Q1.</strong> I want to test all of the 100 large 8K images, <em>i.e.</em>, all the images should be passed through my network to get their denoised (smoothed) versions.<br>
<strong>Q2.</strong> It seems that the test on GPU requires very much memory (maybe about 40~80GB). One 3090 GPU only has about 24~25GB of memory, so I can not accomplish the test on one 3090 GPU.<br>
<strong>Q3.</strong> I have tried a test on the CPU. Although the memory problem may be avoided, the test speed is too low (about 10 minutes per image). Therefore, I hope I can test the images on GPUs.<br>
<strong>Q4.</strong> The images should not be split into smaller patches or blocks. In other words, I want to pass the complete (whole) 8K images through my network.<br>
<strong>Q5.</strong> I have activated all four 3090 GPUs and tried the modules of <code>torch.nn.DataParallel</code>. However, it seems that only the first GPU is utilized. Is there a way to take full use of all the four 3090 GPUs, to support the test of large 8K images?</p>
<p>I have tried <code>torch.cuda.empty_cache()</code>, activated <code>torch.no_grad()</code>, and so on. However, it seems that the memory is still not enough.</p>
<p>I do not know if there are some mechanisms to test one image on the four GPUs or perform calculations on GPUs with the help of local host memory.</p>
<p>My mind may be in a muddle now. So the above things may be not well-organized.<br>
Any suggestion is welcomed.<br>
I am still searching, thinking, and trying …</p>
<p>Thanks a lot for reading such a long post!</p>

ptrblck: <aside class="quote no-group" data-username="111414" data-post="1" data-topic="167654">
<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/111414/48/31166_2.png" class="avatar"> 111414:</div>
<blockquote>
<p>I have activated all four 3090 GPUs and tried the modules of <code>torch.nn.DataParallel</code>. However, it seems that only the first GPU is utilized. Is there a way to take full use of all the four 3090 GPUs, to support the test of large 8K images?</p>
</blockquote>
</aside>
<p><code>DataParallel</code> will clone the model to all available devices and will not reduce the memory requirement, so I’m unsure why a) only a single device was used and b) why it was working at all since you were previously running our of memory.</p>
<aside class="quote no-group" data-username="111414" data-post="1" data-topic="167654">
<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/111414/48/31166_2.png" class="avatar"> 111414:</div>
<blockquote>
<p>I have tried <code>torch.cuda.empty_cache()</code>,</p>
</blockquote>
</aside>
<p>Calling <code>empty_cache()</code> won’t reduce the GPUuu memory usage, but will instead only slow down your code. This operation is used to free the PyTorch internal CUDA cache to allow other processes to use the GPU. PyTorch itself will need to call the expensive (since synchronizing) <code>cudaMalloc</code> calls again to allocate the previously freed memory.</p>
<aside class="quote no-group" data-username="111414" data-post="1" data-topic="167654">
<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/111414/48/31166_2.png" class="avatar"> 111414:</div>
<blockquote>
<p>I do not know if there are some mechanisms to test one image on the four GPUs or perform calculations on GPUs with the help of local host memory.</p>
</blockquote>
</aside>
<p>You could try to use pipeline parallelism e.g. via <a href="https://github.com/pytorch/tau"><code>pytorch/tau</code></a>, could check <a href="https://pytorch.org/blog/introducing-pytorch-fully-sharded-data-parallel-api/">FSDP</a>, CPU offloading, or checkpointing via <code>torch.utils.checkpoint</code> to trade compute for memory.</p>