Using cpu memory as additional memory for GPU

username: salahelabyad
cooked: <p>Is there a way in pytorch to borrow memory from the CPU when training on GPU. I am training a model related to video processing and would like to increase the batch size. This is to know if increasing batch size can improve the results of the model by better training it, especially the batchnorm3d part.</p>
<p>I am trying to train a model that requires a lot of memory and my CPU has more memory and can handle a larger batch size, but the GPU is much faster but limitied in memory. So I want to add the memory in the CPU as usable memory for the GPU somehow. To be able to increase batch size (I use batchnorm3d and from what I understand the minibatch size is a major factor).</p>
<p>I want to know if there is something in pytorch or some external library for pytroch that can allow that. And whether that sollution is available for windows or not as I do not use linux (unless maybe if it is the only way and no alternatives can be found).</p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="salahelabyad" data-post="1" data-topic="100862">
<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/salahelabyad/48/30356_2.png" class="avatar"> salahelabyad:</div>
<blockquote>
<p>So I want to add the memory in the CPU as usable memory for the GPU somehow.</p>
</blockquote>
</aside>
<p>I think Microsoft released a PyTorch package some time ago, where intermediate tensors could be pushed to the CPU temporarily to reduce the GPU memory usage.<br>
However, I can’t remember the name at the moment and don’t know if it’s still maintained.</p>
<p>That being said, you could trace compute for memory via <code>torch.utils.checkpoint</code>. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=12" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>

username: salahelabyad
cooked: <p>I looked into torch.utils.checkpoint, it does satisfy what I needed.</p>
<p>I also tried searching again with different keywords and found this repository <a href="https://github.com/IBM/pytorch-large-model-support" rel="noopener nofollow ugc">https://github.com/IBM/pytorch-large-model-support</a> It enables memory swapping between CPU memory and GPU (similar to memory swap between CPU RAM and storage memory). I will leave the link here maybe it can help someone later on.</p>
<p>I will look into microsoft releases, if I happen to find anything related to the topic I’ll try to remember to update the post.</p>
<p>Thanks for the help <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=9" title=":smiley:" class="emoji" alt=":smiley:"></p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="salahelabyad" data-post="3" data-topic="100862">
<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/salahelabyad/48/30356_2.png" class="avatar"> salahelabyad:</div>
<blockquote>
<p>I will look into microsoft releases, if I happen to find anything related to the topic I’ll try to remember to update the post.</p>
</blockquote>
</aside>
<p>Ah no, you were right. It was indeed the linked repository by IBM, I just misremembered it which also explains why I couldn’t find it. Thanks for the link. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=12" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<p>Based on the last commits it seems that PyTorch <code>1.5.0</code> is at least supported.</p>

username: m-yahya-khattak
cooked: <p>I’m having the exact same issue. But I can’t figure out how to setup this module(pytorch-large-model-support) with my with my code.</p>