Please Help me solve this error Process finished with exit code -1073741819 (0xC0000005)

username: _ike
cooked: <p>My environment is python3.6.9 windows10 torch1.2.0. cuda9.2</p>
<p>My problem is when I running FC network the code works well in both CPU and GPU.<br>
But when it comes to CNN, I can only train it on CPU. It raises an error when I try to train it on GPU.</p>
<p>like that: Process finished with exit code -1073741819 (0xC0000005)<br>
I find the error raised when the code goes to loss.backword.</p>
<p>Please help me. Thank you a lot!</p>
<p>The error happened when I use the first column instead of the second.</p>
<p>device = torch.device(“cuda:0”)</p>
<p>device = torch.device(“cuda:0” if opt.cuda else “cpu”)</p>

username: _ike
cooked: <p>Finally, I figured out this.</p>
<p>This error occurs just because one of my variables is not loaded in cuda.</p>
<p>When I add this output = Variable(netD(real_cpu),requires_grad=True) the problem solved.</p>

username: albanD
cooked: <p>Hi,</p>
<p>Out of curiosity, do you have custom cpp code in your backward?<br>
Because pytorch should never raise such an unfriendly error message.<br>
If you did not have custom code, can you provide a small code snippet to reproduce this please?</p>

username: _ike
cooked: <pre><code class="lang-auto">class Discriminator(nn.Module):
    def __init__(self):
        super(Discriminator, self).__init__()

        self.main = nn.Sequential(
            # input is (nc) x 64 x 64
            nn.Conv2d(nc, ndf, 4, 2, 1, bias=False),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. (ndf) x 32 x 32
            nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 2),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. (ndf*2) x 16 x 16
            nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 4),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. (ndf*4) x 8 x 8
            nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 8),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. (ndf*8) x 4 x 4
            nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=False),
            nn.Sigmoid()
        )
    def forward(self, input):
        output = self.main(input)

        return output.view(-1, 1).squeeze(1)
</code></pre>
<p>Actually, the solution I provided won’t work, I have to use CPU train my network. This is the netD that cannot process backward bu GPU.<br>
And the full code is here <a href="https://github.com/IkeYang/AndrewNg_ML_practise/blob/master/GAN" rel="nofollow noopener">https://github.com/IkeYang/AndrewNg_ML_practise/blob/master/GAN</a><br>
Futhermore, when I subsitute the conv layer with linear, it works on GPU.<br>
That’s quite weird.</p>

username: albanD
cooked: <p>Which version of pytorch are you using?</p>

username: _ike
cooked: <p>It’s torch 1.2.0.<br>
And my other environment is python3.6.9 windows10  cuda9.2</p>

username: ptrblck
cooked: <p>Could you remove the <code>inplace=True</code> arguments and run the code again? The error message is quite unhelpful.</p>
<p>EDIT: might also be related to <a href="https://discuss.pytorch.org/t/the-application-will-happen-exception-0xc0000005-when-it-unloads-dll-using-libtorch-1-2/57946">this topic</a>.</p>

username: _ike
cooked: <p>It won’t work too. Actually, the code works well until meeting the loss.backward(). And the gradient can go through the loss function but not the network.<br>
Additionally, <a href="https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html" rel="nofollow noopener">https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html</a> this tutorial also raise the same error.</p>

username: _ike
cooked: <p>In the end, I switch my python to 3.5. And it works. Amazing… but my whole week is done. <img src="https://discuss.pytorch.org/images/emoji/apple/joy.png?v=9" title=":joy:" class="emoji" alt=":joy:"></p>

username: KeyunYang
cooked: <p>I also ran into this problem with cu9.2， windows10 and python3.7, but switching to python3.5 using your method still didn’t work</p>

username: J_Johnson
cooked: <p>Are you using an lr_scheduler?<br>
<a href="https://pytorch.org/docs/stable/optim.html#torch.optim.lr_scheduler.LambdaLR" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/docs/stable/optim.html#torch.optim.lr_scheduler.LambdaLR</a></p>