How to Use More Process Memory

Spencerfonbuena: <p>I am using WandB to track pytorch machine learning projects. I am using an Nvidia A100 GPU hosted with Vultr. I don’t know if this is a question for this forum, but I figured that it would at least be down the alley of the people on the pytorch forums.</p>
<p>On the WandB system reports, it shows that I am using 90% of the GPU processing memory, but only 15% of the process memory. I want to make sure that I am using my VM to it’s full extent, and am curious if there is a way to use more process memory to speed up training.</p>
<p>I imagine this is an involved question, so if anyone has any resources they can point me to to learn more about this topic I would be very grateful. The only insight I have is that the optimizer states and weights are all stored on the GPU for quick training. What I am unsure of, is if there is a pytorch method to offload some of that work to the CPU to increase speed, or if CPU use for training neural networks is more of a memory saver, but will slow down training speed.</p>

ptrblck: <aside class="quote no-group" data-username="Spencerfonbuena" data-post="1" data-topic="184459">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/dbc845/48.png" class="avatar"> Spencerfonbuena:</div>
<blockquote>
<p>On the WandB system reports, it shows that I am using 90% of the GPU processing memory, but only 15% of the process memory.</p>
</blockquote>
</aside>
<p>Could you describe the difference between “processing” and “process” memory?</p>

Spencerfonbuena: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/f/4facaad0813f1a73c99a048e208b341d10397e00.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/4facaad0813f1a73c99a048e208b341d10397e00" title="Screenshot 2023-07-18 at 9.16.15 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/f/4facaad0813f1a73c99a048e208b341d10397e00_2_690x239.jpeg" alt="Screenshot 2023-07-18 at 9.16.15 AM" data-base62-sha1="bmPENsTCEkMq0ydpBI0v4aCLkv6" width="690" height="239" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/f/4facaad0813f1a73c99a048e208b341d10397e00_2_690x239.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/4/f/4facaad0813f1a73c99a048e208b341d10397e00_2_1035x358.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/f/4facaad0813f1a73c99a048e208b341d10397e00_2_1380x478.jpeg 2x" data-dominant-color="ECF0F4"><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">Screenshot 2023-07-18 at 9.16.15 AM</span><span class="informations">1812×628 237 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><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/f/ef4f6f25938493da7052f7d4d3dcdb4daa39e2a6.png" data-download-href="https://discuss.pytorch.org/uploads/default/ef4f6f25938493da7052f7d4d3dcdb4daa39e2a6" title="Screenshot 2023-07-18 at 9.16.30 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/e/f/ef4f6f25938493da7052f7d4d3dcdb4daa39e2a6_2_690x239.png" alt="Screenshot 2023-07-18 at 9.16.30 AM" data-base62-sha1="y92iKfMakUpD08dBXIxM8HozcuG" width="690" height="239" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/e/f/ef4f6f25938493da7052f7d4d3dcdb4daa39e2a6_2_690x239.png, https://discuss.pytorch.org/uploads/default/optimized/3X/e/f/ef4f6f25938493da7052f7d4d3dcdb4daa39e2a6_2_1035x358.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/e/f/ef4f6f25938493da7052f7d4d3dcdb4daa39e2a6_2_1380x478.png 2x" data-dominant-color="FCFCFC"><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">Screenshot 2023-07-18 at 9.16.30 AM</span><span class="informations">1806×628 45.3 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>
<p>These are the reports that Wandb is giving. I am assuming that when it says process memory and system memory it is referring to the cpu, but I am not entirely sure. Hopefully this provides more context.</p>
<p>Thus far, the only forms of parallelism I know to use on a single GPU is increasing batch size, and increase the number of workers loading the data. Obviously, increasing batch size doesn’t do anything to offload memory to the cpu, or utilize better the cpu processing power, but it does maximize GPU usage.</p>
<p>The system I am using has 12 Vcpus, and so I set my number of workers to 12, as per the warning signal pytorch gives when putting num_workers &gt; number of cpus available.</p>

ptrblck: <p>I’m not familiar with wandb, but if I understand your question correctly you want to offload data to the CPU to be able to utilize these cores. In that case you could use <a href="https://discuss.pytorch.org/t/modifying-forward-backward-pass/169687/2">these functions</a> to offload data to the host to save memory and could move it manually via <code>to("cpu")</code> and execute any CPU layers on this data afterwards. Note that you would usually not use this approach as it will create a slowdown, but I’m also not familiar with your setup and use case.</p>