RuntimeError: CUDA error: unknown error in torch 1.1.0

username: YANG_YAN
cooked: <p>I have some problems when I try to use GPU.<br>
Here is my code from example:</p>
<pre><code class="lang-auto">device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
densenet121 = models.densenet121(pretrained=True)
densenet121.to(device)
</code></pre>
<p>When I run the code above, I get the error:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "d:\All Project\VScode\Python\learn_framework\CNN\test.py", line 63, in &lt;module&gt;
    densenet121.to(device)
  File "D:\Python36\lib\site-packages\torch\nn\modules\module.py", line 386, in to
    return self._apply(convert)
  File "D:\Python36\lib\site-packages\torch\nn\modules\module.py", line 193, in _apply
    module._apply(fn)
  File "D:\Python36\lib\site-packages\torch\nn\modules\module.py", line 193, in _apply
    module._apply(fn)
  File "D:\Python36\lib\site-packages\torch\nn\modules\module.py", line 199, in _apply
    param.data = fn(param.data)
  File "D:\Python36\lib\site-packages\torch\nn\modules\module.py", line 384, in convert
    return t.to(device, dtype if t.is_floating_point() else None, non_blocking)
  File "D:\Python36\lib\site-packages\torch\cuda\__init__.py", line 163, in _lazy_init
    torch._C._cuda_init()
RuntimeError: CUDA error: unknown error
</code></pre>
<p>But if I run code like this:</p>
<pre><code class="lang-auto">device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
torch.randn(1).to(device)
densenet121 = models.densenet121(pretrained=True)
densenet121.to(device)
print(next(densenet121.parameters()).is_cuda)
</code></pre>
<p>It will work and print a ‘True’.<br>
I don’t know what the problem is and don’t want to add ‘torch.randn(1).to(device)’ in front of the code every time.<br>
My machine:<br>
Windows 10 Enterprise, 64-bit<br>
nvidia driver: 418.96<br>
GPU: GeForce 940MX<br>
CUDA: release 10.0, V10.0.130<br>
Pytorch version: 1.1.0</p>
<p>Please help:pleading_face:</p>

username: peterjc123
cooked: <aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/issues/20990" target="_blank" rel="nofollow noopener">github.com/pytorch/pytorch</a>
  </header>
  <article class="onebox-body">
    <a href="https://github.com/rohanpandey" rel="nofollow noopener">
<img src="https://avatars1.githubusercontent.com/u/31413869?v=2&amp;s=96" class="thumbnail onebox-avatar" width="60" height="60">
</a>

<h4><a href="https://github.com/pytorch/pytorch/issues/20990" target="_blank" rel="nofollow noopener">Issue: Unable to use Pytorch with CUDA</a></h4>

<div class="date" style="margin-top:10px;">
	<div class="user" style="margin-top:10px;">
	opened by <a href="https://github.com/rohanpandey" target="_blank" rel="nofollow noopener">rohanpandey</a>
	on <a href="https://github.com/pytorch/pytorch/issues/20990" target="_blank" rel="nofollow noopener">2019-05-27</a>
	</div>
	<div class="user">
	closed by <a href="https://github.com/rohanpandey" target="_blank" rel="nofollow noopener">rohanpandey</a>
	on <a href="https://github.com/pytorch/pytorch/issues/20990" target="_blank" rel="nofollow noopener">2019-05-27</a>
	</div>
</div>

<pre class="content" style="white-space: pre-wrap;">I am unable to use pytorch with CUDA despite having installed it.
OS: Windows 10
Pytorch Version: 1.1.0
CUDA Version: 10.0
I get the following...</pre>

<div class="labels">
 	<span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">module: windows</span>
</div>

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