Tried to allocate 7869836414.81 GiB

username: ben_mi
cooked: <p>I wanted to check how many combinations the <code>torch.combinations()</code> function would return for different <code>r</code> values.</p>
<pre><code class="lang-auto">values = torch.arange(23, dtype=torch.uint8, device="cuda:0")
combinations = torch.combinations(values, r=23)
</code></pre>
<p>Even though I picked <code>r=23</code> which should just return <code>1</code> combination, I got the above mentioned error: <code>CUDA out of memory error. Tried to allocate 7869836414.81 GiB (...)</code>.</p>
<p>Why does this happen?</p>

username: Nikronic
cooked: <p>Hi,</p>
<aside class="quote no-group" data-username="ben_mi" data-post="1" data-topic="88880">
<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/b/a9adbd/48.png" class="avatar"> ben_mi:</div>
<blockquote>
<p><code>values = torch.arange(23, dtype=torch.uint8, device="cuda:0")</code></p>
</blockquote>
</aside>
<p>This line generates a list <code>[0, 1, ..., 22]</code>. If you want just a single number, close the range on it [23, 24].</p>
<pre><code class="lang-auto">values = torch.arange(23, 24, dtype=torch.uint8, device="cuda:0")
</code></pre>
<p>Bests</p>

username: ben_mi
cooked: <p>Thanks for your reply.</p>
<p>I mean when I run:</p>
<pre><code class="lang-auto">values = torch.arange(23, dtype=torch.uint8, device="cuda:0")
</code></pre>
<p>it creates a list with 23 values like you said: <code>[0, 1, ..., 22]</code>.<br>
So I wanted to test how many different combinations <code>torch.combinations()</code> returns when I increase the <code>r</code> value, which determines how many values are in a combination.</p>
<p>I get an error for values of <code>r &gt; 7</code> I think, which makes sense because it finds a lot of different combinations, which take up a lot of memory. But when I tested the function with <code>r=23</code>, I was surprised to get a <code>CUDA out of memory error</code>, since the list is 23 elements long and <code>torch.combinations()</code> should therefore just return the original list again. I tried it for a smaller list as well:</p>
<pre><code class="lang-auto">values = torch.arange(5)
combinations = torch.combinations(values, r=5)
# len(combinations) = 1
</code></pre>
<p>So I was wondering why I got an error with my first example.</p>

username: Nikronic
cooked: <p>Ow, sorry about my first answer, I was totally somewhere else. Actually, it seems you are right, it should return only a list of 22 numbers. The strange part is if you run your code for i=1 to i=9 it just works fine but after that it does not work and tries to allocate 9GB!</p>
<p>I ran below code:</p>
<pre><code class="lang-auto">import time
for i in range(1, 10):
    t = time.time()
    values = torch.arange(i)
    combinations = torch.combinations(values, r=i, )
    print('for i=',i,' =&gt; ',time.time() - t)
    print(combinations)

# here is the strange output (look at the time)
# for i= 1  =&gt;  0.0003619194030761719
# tensor([[0]])
# for i= 2  =&gt;  0.0005240440368652344
# tensor([[0, 1]])
# for i= 3  =&gt;  0.00019550323486328125
# tensor([[0, 1, 2]])
# for i= 4  =&gt;  0.000286102294921875
# tensor([[0, 1, 2, 3]])
# for i= 5  =&gt;  0.0006687641143798828
# tensor([[0, 1, 2, 3, 4]])
# for i= 6  =&gt;  0.001373291015625
# tensor([[0, 1, 2, 3, 4, 5]])
# for i= 7  =&gt;  0.018665552139282227
# tensor([[0, 1, 2, 3, 4, 5, 6]])
# for i= 8  =&gt;  0.36806702613830566
# tensor([[0, 1, 2, 3, 4, 5, 6, 7]])
# for i= 9  =&gt;  8.350317239761353
# tensor([[0, 1, 2, 3, 4, 5, 6, 7, 8]])
</code></pre>
<p>For <code>i=10</code> I could not get any answer!</p>
<p>Here is the code using <code>itertools</code> which is the base code of <code>torch.combinations</code>:</p>
<pre><code class="lang-auto">
import itertools

for i in range(1, 11):
    t = time.time()
    values = torch.arange(i)
    combinations = list(itertools.combinations(values, r=i))
    combinations = torch.tensor(combinations)
    print('for i=',i,' =&gt; ',time.time() - t)
    print(combinations)

# output

# for i= 1  =&gt;  0.0003228187561035156
# tensor([[0]])
# for i= 2  =&gt;  0.0002307891845703125
# tensor([[0, 1]])
# for i= 3  =&gt;  7.605552673339844e-05
# tensor([[0, 1, 2]])
# for i= 4  =&gt;  0.0005385875701904297
# tensor([[0, 1, 2, 3]])
# for i= 5  =&gt;  0.00017261505126953125
# tensor([[0, 1, 2, 3, 4]])
# for i= 6  =&gt;  0.0003154277801513672
# tensor([[0, 1, 2, 3, 4, 5]])
# for i= 7  =&gt;  9.918212890625e-05
# tensor([[0, 1, 2, 3, 4, 5, 6]])
# for i= 8  =&gt;  0.00019240379333496094
# tensor([[0, 1, 2, 3, 4, 5, 6, 7]])
# for i= 9  =&gt;  9.393692016601562e-05
# tensor([[0, 1, 2, 3, 4, 5, 6, 7, 8]])
# for i= 10  =&gt;  0.0001595020294189453
# tensor([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
</code></pre>
<p>And the expected part is that it creates all the answers within same amount of time.<br>
Can you report it on Github account of PyTorch?</p>
<p>Edit: add link to issue<br>
</p><aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/issues/41325" target="_blank" rel="nofollow noopener">github.com/pytorch/pytorch</a>
  </header>
  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/pytorch/issues/41325" target="_blank" rel="nofollow noopener">torch.combinations() - Tried to allocate 7869836414.81 GiB</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2020-07-12" data-time="22:44:50" data-timezone="UTC">10:44PM - 12 Jul 20 UTC</span>
      </div>


      <div class="user">
        <a href="https://github.com/bennymi" target="_blank" rel="nofollow noopener">
          <img alt="bennymi" src="https://avatars3.githubusercontent.com/u/20195536?v=4" class="onebox-avatar-inline" width="20" height="20">
          bennymi
        </a>
      </div>
    </div>
  </div>
</div>

<div class="github-row">
  <p class="github-content">🐛 Bug
When using torch.combinations(list, r=len(list)) with the r value set to the length of the list, I get a CUDA out...</p>
</div>

<div class="labels">
</div>

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

<p>Thank you</p>

username: ben_mi
cooked: <p>Thanks <a class="mention" href="/u/nikronic">@Nikronic</a>. Yes I’ll do that</p>