akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
Mobilenetv1 crash in macbookpro

jiang_yang: <p>Help, when I set groups=1, all ok, but the sample code crash.</p>
<pre><code class="lang-auto">import torch.nn as nn
import torch
import torch.nn.functional as F


class MobileNetV1R(nn.Module):
    def __init__(self, num_classes=1024):
        super(MobileNetV1R, self).__init__()

        def conv_bn(inp, oup, stride):
            return nn.Sequential(
                nn.Conv2d(inp, oup, 3, stride, 1, bias=False),
                nn.BatchNorm2d(oup),
                nn.ReLU(inplace=True)
            )

        def conv_dw(inp, oup, stride):
            return nn.Sequential(
                nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False),
                nn.BatchNorm2d(inp),
                nn.ReLU(inplace=True),

                nn.Conv2d(inp, oup, 1, 1, 0, bias=False),
                nn.BatchNorm2d(oup),
                nn.ReLU(inplace=True),
            )

        self.model = nn.Sequential(
            conv_bn(3, 32, 2),
            conv_dw(32, 64, 1),
            conv_dw(64, 128, 2),
            conv_dw(128, 128, 1),
            conv_dw(128, 256, 2),
            conv_dw(256, 256, 1),
            conv_dw(256, 512, 2),
            conv_dw(512, 512, 1),
            conv_dw(512, 512, 1),
            conv_dw(512, 512, 1),
            conv_dw(512, 512, 1),
            conv_dw(512, 512, 1),
            conv_dw(512, 1024, 2),
            conv_dw(1024, 1024, 1),
        )
        self.fc = nn.Linear(1024, num_classes)

    def forward(self, x):
        x = self.model(x)
        x = F.avg_pool2d(x, 7)
        x = x.view(-1, 1024)
        x = self.fc(x)
        return x


image = torch.ones((2, 3, 300, 300))
net = MobileNetV1R()
optimizer = torch.optim.SGD(net.parameters(), lr=0.001)
for i in range(5):
    predict = net(image)
    optimizer.zero_grad()
    loss = torch.sum(torch.abs(predict))
    loss.backward()
    optimizer.step()
    print(loss)

print('finish')
</code></pre>
Can't do autograd on assignment operation(seems like an inevitable inplace operation)

sans: <p>Hello everybody! Here’s my problem:<br>
My pytorch version is 0.3, so I have to use variable to do autograd in my network. I want to get the output from my network and do some matrix calculation and then get the loss value.This is what I try to do:<br>
I got an output from my designed network, it’s a vector, say 100 dims. And I want to assign the elements from this vector to a 10x10 matrix. And the position of these elements is determined by a 100-dim index array I have calculated already, like this:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/b/be4933b2c8cf94453e2f5bc96bea1efed4cc5f63.png" data-download-href="https://discuss.pytorch.org/uploads/default/be4933b2c8cf94453e2f5bc96bea1efed4cc5f63" title="TIM%E6%88%AA%E5%9B%BE20190328160609"><img src="https://discuss.pytorch.org/uploads/default/original/2X/b/be4933b2c8cf94453e2f5bc96bea1efed4cc5f63.png" alt="TIM%E6%88%AA%E5%9B%BE20190328160609" data-base62-sha1="r9lykVUmTRZbbbbxT23EQgEn22n" width="690" height="347" data-dominant-color="F6F5F5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">TIM%E6%88%AA%E5%9B%BE20190328160609</span><span class="informations">837×422 12.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
But when I try to do this, I encountered this problem:<br>
<strong>in-place operations can be only used on variables that don’t share storage with any other variables, but detected that there are 2 objects sharing it</strong><br>
So I can’t do inplace operations on variable, but I need the resulted matrix to calcalate loss value and then do autograd. It really confuses me a lot… So I want to ask everybody, is there a way for me to achieve this purpose?     Thanks a lot!!!</p>

aiyulu: <p>Hi, I am caughted in the same problem, can you tell me how do you fix it the end?</p>