Pytorch RuntimeError: [enforce fail at CPUAllocator.cpp:56] posix_memalign(&data, gAlignment, nbytes) == 0. 12 vs 0

username: rooom13
cooked: <aside class="onebox stackexchange">
  <header class="source">
      <a href="https://stackoverflow.com/questions/56272981/pytorch-runtimeerror-enforce-fail-at-cpuallocator-cpp56-posix-memaligndata" target="_blank" rel="nofollow noopener">stackoverflow.com</a>
  </header>
  <article class="onebox-body">
      <a href="https://stackoverflow.com/users/7519700/room13" target="_blank" rel="nofollow noopener">
    <img alt="room13" src="https://www.gravatar.com/avatar/cf7cdf0b4cf1e75d490b73fa72f3b07d?s=128&amp;d=identicon&amp;r=PG&amp;f=1" class="thumbnail onebox-avatar" width="128" height="128">
  </a>
<h4>
  <a href="https://stackoverflow.com/questions/56272981/pytorch-runtimeerror-enforce-fail-at-cpuallocator-cpp56-posix-memaligndata" target="_blank" rel="nofollow noopener">Pytorch RuntimeError: [enforce fail at CPUAllocator.cpp:56] posix_memalign(&amp;data, gAlignment, nbytes) == 0. 12 vs 0</a>
</h4>

<div class="tags">
  <strong>python, python-3.x, pytorch, recommendation-engine</strong>
</div>

<div class="date">
  asked by
  
  <a href="https://stackoverflow.com/users/7519700/room13" target="_blank" rel="nofollow noopener">
    room13
  </a>
  on <a href="https://stackoverflow.com/questions/56272981/pytorch-runtimeerror-enforce-fail-at-cpuallocator-cpp56-posix-memaligndata" target="_blank" rel="nofollow noopener">10:13AM - 23 May 19 UTC</a>
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: cgpeter96
cooked: <p>I also meet this problem,  Have you solve this problem？</p>

username: rooom13
cooked: <p>Not at all, but I realized that apparently I was not using the GPU but the CPU, I managed to send the data to the GPU with Tensor.to(‘cuda’)<br>
I hope it helps you</p>

username: cgpeter96
cooked: <p>it’s just like i have not enough memory to save  .because when i add  very very very much tensors to Tensors, it’s will happen this problem.</p>

username: rooom13
cooked: <p>Which is the dimensionality of your data?</p>

username: cgpeter96
cooked: <p>it’s seem to very large .I have 600000 samples to map the low dim vector(d=5650)，so I need a Tensor to load the vectors [600000x5650] <img src="https://discuss.pytorch.org/images/emoji/apple/rofl.png?v=9" title=":rofl:" class="emoji" alt=":rofl:">  , PyTorch maybe can’t load so much。<br>
just on CPUtensor</p>

username: rooom13
cooked: <p>Is your data sparse? Because maybe you could use csr_matrix object from scikit</p>

username: cgpeter96
cooked: <p>oh  thanks.   I try it.  now , i move all my data to numpy</p>

username: djseivad
cooked: <p><a href="http://man7.org/linux/man-pages/man3/posix_memalign.3.html" class="onebox" target="_blank" rel="nofollow noopener">http://man7.org/linux/man-pages/man3/posix_memalign.3.html</a></p>
<p>It is likely occurring from a data transfer from the gpu to cpu where your data is of size m and your available memory size is of n where n &lt; m =&gt; as the documentation states there are two types of errors</p>
<pre><code>   EINVAL The alignment argument was not a power of two, or was not a
          multiple of sizeof(void *).

   ENOMEM There was insufficient memory to fulfill the allocation
          request.
</code></pre>
<p>Considering my error occurred near the end of my training and am working with large datasets then for me it was likely an ENOMEM error.</p>