Different memory consumption for the same net

username: upiferico
cooked: <p>Hi! I am facing a very strange issue: I have 2 different environments for training NN: (Ubuntu 20.04)</p>
<ul>
<li>RTX 2070super mobile, CUDA 11.2, pytorch 1.10.0</li>
<li>RTX 3060ti , CUDA 11.4, pytorch 1.10.1</li>
</ul>
<p>On the first computer, training my NN consumes around 1400MB of GPU ram while the second one uses 2200MB. Their training configs are the same: Its a RL project using PyTorch and stableBaselines. The code is the same. Nonetheless, it still uses more ram from the GPU on the second computer which prevents me from using more parallel training.</p>
<p>I have been advised about pytorch <a href="https://pytorch.org/docs/stable/backends.html?highlight=cudnn#torch.backends.cudnn.benchmark" rel="noopener nofollow ugc">flags</a>. They are the same on both. I wonder if it is an issue with Cuda, PyTorch or a hidden default config of each GPU.</p>

username: ptrblck
cooked: <p>I don’t know how you’ve installed PyTorch but given that you mention CUDA 11.4, I assume you are using source builds.<br>
In this case, the different CUDA versions as well as cuDNN (which versions did you build with?) would most likely have a different memory footprint. If you don’t want to load e.g. the cuDNN kernels and are dynamically linking to it during the build, disable cuDNN via <code>torch.backends.cudnn.enabled=False</code> and check the memory usage again. Also, different GPU generations would load a different amount of kernels in libs such as cuDNN.<br>
It’s also important what exactly you are measuring since PyTorch uses a caching allocator and can thus reuse memory so you should check the allocated and reserved memory via e.g. <code>torch.cuda.memory_summary()</code>.</p>

username: upiferico
cooked: <p>Thank you for the reply!<br>
disabling cuDNN made just a little difference, around 50MB.<br>
I installed both drivers from the ubuntu official repo, one based on v470(cuda 11.4) and the older using v460(cuda 11.2) from the same source. PyTorch is installed via pip.<br>
Let me share  torch.cuda.memory_summary() result from both computers<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/b/db43988ecebb17fdab3abdff137a1c3aa543fea2.png" data-download-href="https://discuss.pytorch.org/uploads/default/db43988ecebb17fdab3abdff137a1c3aa543fea2" title="cuda memory comparision"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/b/db43988ecebb17fdab3abdff137a1c3aa543fea2_2_690x492.png" alt="cuda memory comparision" data-base62-sha1="vhHo9LKKe51SoXqGx7LVowU5nyO" width="690" height="492" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/b/db43988ecebb17fdab3abdff137a1c3aa543fea2_2_690x492.png, https://discuss.pytorch.org/uploads/default/optimized/3X/d/b/db43988ecebb17fdab3abdff137a1c3aa543fea2_2_1035x738.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/d/b/db43988ecebb17fdab3abdff137a1c3aa543fea2_2_1380x984.png 2x" data-dominant-color="262627"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">cuda memory comparision</span><span class="informations">1720×1227 474 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: ptrblck
cooked: <p>Since you’ve installed the pip wheels, the tagged CUDA runtime would be used (e.g. 11.3 if selected during the installation) and the local CUDA toolkit would be used if you are building PyTorch from source or a custom CUDA extension.<br>
As can be seen by <code>torch.cuda.memory_summary()</code> the allocated memory is equal (both <code>19294KB</code>) and the reserved memory (used for the cache) is different. If you don’t want to reuse this memory, clear it via <code>torch.cuda.empty_cache()</code>.</p>

username: upiferico
cooked: <p>After trying different configurations, I can see that the CUDA runtime version and the GPU generation affect the memory usage. I don’t get why both environments consistently use different cache memory allocations.<br>
I am not sure about using that empty_cache() function in the train loop.<br>
Anyway, I can settle with the higher memory usage, as surprisingly the environment with 3 agents perform better than the laptop with 4 (and GPU usage is at 100% on both, no CPU bottleneck)</p>