<p dir="auto">When I run this code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="N, C = 1, 1
criterion = nn.NLLLoss()
model = nn.Conv2d(C, 3, (3, 3)).cuda()
inp = Variable(torch.randn(N, 1, 3, 3)).cuda()
pred = model(inp)
target = Variable(torch.from_numpy(np.array([3]))).view(1, 1, 1).cuda()
criterion(pred, target)"><pre class="notranslate"><code class="notranslate">N, C = 1, 1
criterion = nn.NLLLoss()
model = nn.Conv2d(C, 3, (3, 3)).cuda()
inp = Variable(torch.randn(N, 1, 3, 3)).cuda()
pred = model(inp)
target = Variable(torch.from_numpy(np.array([3]))).view(1, 1, 1).cuda()
criterion(pred, target)
</code></pre></div>
<p dir="auto">I get this error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cuda runtime error (59) : device-side assert triggered at /opt/conda/conda-bld/pytorch_1518244421288/work/torch/lib/THC/generic/THCTensorCopy.c:70"><pre class="notranslate"><code class="notranslate">cuda runtime error (59) : device-side assert triggered at /opt/conda/conda-bld/pytorch_1518244421288/work/torch/lib/THC/generic/THCTensorCopy.c:70
</code></pre></div>
<p dir="auto">Due to the value of <code class="notranslate">target</code> being <code class="notranslate">3</code>, and not in the set of <code class="notranslate">{0, 1, 2}</code>. It took me a while to figure out and I was wondering this is an easy to fix issue, and if it is I was wondering how I would get started as I'm quite eager to contribute to Pytorch</p>
<p dir="auto">Hi<br>
I have written the following code to train my model, after a few iterations it stops throwing a similar error as shown in the image. Note that error is similar but not same, it changes everytime. I have read all the answers here and pytorch forum for the similar errors, none of them works. Please help ...</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/18963158/37559304-9b509616-2a49-11e8-81e8-30335762ffe2.png"><img src="https://user-images.githubusercontent.com/18963158/37559304-9b509616-2a49-11e8-81e8-30335762ffe2.png" alt="w1" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/18963158/37559306-a1f21738-2a49-11e8-8fb1-5dabf0b5bbdf.png"><img src="https://user-images.githubusercontent.com/18963158/37559306-a1f21738-2a49-11e8-8fb1-5dabf0b5bbdf.png" alt="w2" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Note that it is running for few iterations hence the starting few outputs</strong><br>
Thank you.</p>