[Running on windows 10] torch._C._cuda_init() RuntimeError: CUDA error: unknown error

guifachild123: <p>I installed pytorch, and my cuda version is upto date. But when I run my command, I get the following error:<br>
My system:</p>
<pre><code>Windows 10
NVIDIA GeForce GTX 960M
Python 3.6(Anaconda)
PyTorch 1.1.0
CUDA 10
</code></pre>
<pre><code class="lang-auto">import torch
import torch.nn as nn
from data_util import config
use_cuda = config.use_gpu and torch.cuda.is_available()
def init_lstm_wt(lstm):
    for names in lstm._all_weights:
        for name in names:
            if name.startswith('weight_'):
                wt = getattr(lstm, name)
                wt.data.uniform_(-config.rand_unif_init_mag, config.rand_unif_init_mag)
            elif name.startswith('bias_'):
                # set forget bias to 1
                bias = getattr(lstm, name)
                n = bias.size(0)
                start, end = n // 4, n // 2
                bias.data.fill_(0.)
                bias.data[start:end].fill_(1.)
def init_wt_normal(wt):
    wt.data.normal_(std=config.trunc_norm_init_std)
class Encoder(nn.Module):
    def __init__(self):
        super(Encoder, self).__init__()
        self.embedding = nn.Embedding(config.vocab_size, config.emb_dim)
        init_wt_normal(self.embedding.weight)
        self.lstm = nn.LSTM(config.emb_dim, config.hidden_dim, num_layers=1, batch_first=True, bidirectional=True)
        init_lstm_wt(self.lstm)
        self.W_h = nn.Linear(config.hidden_dim * 2, config.hidden_dim * 2, bias=False)

class Decoder(nn.Module):
    def __init__(self):
        super(Decoder, self).__init__()
        self.embedding = nn.Embedding(config.vocab_size, config.emb_dim)
        init_wt_normal(self.embedding.weight)
class Model(object):
    def __init__(self, model_file_path=None, is_eval=False):
        encoder = Encoder()
        decoder = Decoder()
        if use_cuda:
            encoder = encoder.cuda()
            decoder = decoder.cuda()
model=Model()
</code></pre>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "G:/public_workspace/pointer_summarizer-pytorch-2.7/data_util/test4.py", line 41, in &lt;module&gt;
    model=Model()
  File "G:/public_workspace/pointer_summarizer-pytorch-2.7/data_util/test4.py", line 39, in __init__
    encoder = encoder.cuda()
  File "D:\soft\anaconda\lib\site-packages\torch\nn\modules\module.py", line 266, in cuda
    return self._apply(lambda t: t.cuda(device))
  File "D:\soft\anaconda\lib\site-packages\torch\nn\modules\module.py", line 194, in _apply
    module._apply(fn)
  File "D:\soft\anaconda\lib\site-packages\torch\nn\modules\module.py", line 200, in _apply
    param.data = fn(param.data)
  File "D:\soft\anaconda\lib\site-packages\torch\nn\modules\module.py", line 266, in &lt;lambda&gt;
    return self._apply(lambda t: t.cuda(device))
  File "D:\soft\anaconda\lib\site-packages\torch\cuda\__init__.py", line 176, in _lazy_init
    torch._C._cuda_init()
RuntimeError: CUDA error: unknown error
</code></pre>
<p>I annotated a part ,and the error disappeared</p>
<pre><code class="lang-auto">import torch
import torch.nn as nn
from data_util import config
use_cuda = config.use_gpu and torch.cuda.is_available()
def init_lstm_wt(lstm):
    for names in lstm._all_weights:
        for name in names:
            if name.startswith('weight_'):
                wt = getattr(lstm, name)
                wt.data.uniform_(-config.rand_unif_init_mag, config.rand_unif_init_mag)
            elif name.startswith('bias_'):
                # set forget bias to 1
                bias = getattr(lstm, name)
                n = bias.size(0)
                start, end = n // 4, n // 2
                bias.data.fill_(0.)
                bias.data[start:end].fill_(1.)
def init_wt_normal(wt):
    wt.data.normal_(std=config.trunc_norm_init_std)
class Encoder(nn.Module):
    def __init__(self):
        super(Encoder, self).__init__()
        self.embedding = nn.Embedding(config.vocab_size, config.emb_dim)
        init_wt_normal(self.embedding.weight)
        # self.lstm = nn.LSTM(config.emb_dim, config.hidden_dim, num_layers=1, batch_first=True, bidirectional=True)
        # init_lstm_wt(self.lstm)
        # self.W_h = nn.Linear(config.hidden_dim * 2, config.hidden_dim * 2, bias=False)

class Decoder(nn.Module):
    def __init__(self):
        super(Decoder, self).__init__()
        self.embedding = nn.Embedding(config.vocab_size, config.emb_dim)
        init_wt_normal(self.embedding.weight)
class Model(object):
    def __init__(self, model_file_path=None, is_eval=False):
        encoder = Encoder()
        decoder = Decoder()
        if use_cuda:
            encoder = encoder.cuda()
            decoder = decoder.cuda()
model=Model()
</code></pre>
<p>what can i do to solve the problem?</p>

peterjc123: <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="420" height="420">
</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>


yuanzhoulvpi: <p>我也遇到相同的问题，不知道为什么。请问您解决了，吗？<br>
I also encountered the same problem, I don’t know why. Have you solved it?</p>

guifachild123: <p>I reinstalled Cuda 9.0 and the problem disappeared.</p>

yuanzhoulvpi: <p>对的，我将cuda从10降低到9.2，问题就解决了</p>