RuntimeError: cublas runtime error : resource allocation failed

Kalyan_Katikapalli: <p>I tried to run this simple model. Basically this model is for text classification. I have used random word embeddings.</p>
<pre><code class="lang-auto">import torch.nn as nn
import torch.nn.functional as F

class DSC_RE(nn.Module):
    def __init__(self, input_dim, embedding_dim, output_dim):

        super().__init__()

        self.embedding = nn.Embedding(input_dim, embedding_dim)

        self.fc = nn.Linear(embedding_dim, output_dim)

    def forward(self, text):

        #text = [batch size, sent len]

        text=torch.t(text)

        #text = [sent len, batch size]

        embed = self.embedding(text)

        #embed = [sent len, batch size, embedding dim]

        embed = embed.permute(1,2,0)

        #embed = [batch size, embedding dim, sent len]

        output = F.max_pool1d(embed, embed.size(2))

        #output = [batch size, embedding dim,1]

        output = output.squeeze(2)

        #output = [batch size, embedding dim]

        return self.fc(output)
</code></pre>
<p>However, I got this error when I ran the code</p>
<pre><code class="lang-auto">---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-11-d82622e3ea00&gt; in &lt;module&gt;()
      1 n_epochs=20
----&gt; 2 run_model(model,train_dataloader, test_dataloader,optimizer,criterion,n_epochs)

6 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in linear(input, weight, bias)
   1368     if input.dim() == 2 and bias is not None:
   1369         # fused op is marginally faster
-&gt; 1370         ret = torch.addmm(bias, input, weight.t())
   1371     else:
   1372         output = input.matmul(weight.t())

RuntimeError: cublas runtime error : resource allocation failed at /pytorch/aten/src/THC/THCGeneral.cpp:216
</code></pre>
<p>Any help is really appreciated…</p>
<p>I ran this code in Google Colab using Tesla K80 GPU and PyTorch 1.x version</p>

ptrblck: <p>Could you post the arguments of your model, i.e. <code>input_dim</code>, <code>embedding_dim</code>, and <code>output_dim</code>?<br>
Also, could you post the exact PyTorch and CUDA versions (<code>print(torch.__version__)</code>, <code>print(torch.version.cuda)</code>)?</p>

Kalyan_Katikapalli: <aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="62980">
<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/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p><code>print(torch.version.cuda)</code> )</p>
</blockquote>
</aside>
<p><a class="mention" href="/u/ptrblck">@ptrblck</a></p>
<p>Torch version - 1.3.1<br>
Cuda version - 10.1.243</p>
<p>Input_dim  =  1747 (Vocabulary size)<br>
embedding_dim = 100<br>
output_dim =1 (binary classification)</p>

mohsenkiskani: <p>Facing the same issue now. Were you able to find the solution? Any ideas?</p>

ptrblck: <p>I cannot reproduce <a class="mention" href="/u/kalyan_katikapalli">@Kalyan_Katikapalli</a>’s error using this code with the nightly binaries + CUDA10.1:</p>
<pre><code class="lang-python">model = DSC_RE(1747, 100, 1).cuda()
x = torch.randint(0, 1747, (100, 1)).cuda()
out = model(x)
</code></pre>
<p><a class="mention" href="/u/mohsenkiskani">@mohsenkiskani</a><br>
Could you post an executable code snippet to reproduce this error?</p>

mohsenkiskani: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> Thanks for trying to help. I solved my problem. The issue was that my tensor had an element which was larger than the <code>Input_dim </code> in my code.</p>