Having problem with Inplace operation

username: qing_y
cooked: <p>Good afternoon everyone,</p>
<p>I am new to PyTorch and I am having trouble with my code. The problem is that it seems that the operation that I am using is inplace, but I cant seem to understand how to fix it.</p>
<pre><code class="lang-auto">class GCNNet(torch.nn.Module):
    def __init__(self, embedding_dim=10, hidden_dim=10, dropout=0, with_edge_attention=True, \
                 with_node_attention=True):
        super(GCNNet, self).__init__()
        self.dropout = dropout
        self.conv1 = GCNConv(embedding_dim, hidden_dim, cached=True, normalize=True)
        self.conv2 = GCNConv(hidden_dim, hidden_dim, cached=True, normalize=True)
        self.with_node_attention = with_node_attention
        self.with_edge_attention = with_edge_attention
        self.node_att_mlp = nn.Linear(embedding_dim, 2)
        self.edge_att_mlp = nn.Linear(embedding_dim * 2, 2)

    def forward(self, x, edge_index): #x.shape ([132, 50])
        row, col = edge_index
        edge_rep = torch.cat([x[row], x[col]], dim=-1) #([1208, 100])

        if self.with_node_attention:
            node_att = self.node_att_mlp(x)
            node_att = F.softmax(node_att, dim=-1)  #([1208, 2])
        else:
            node_att = 0.5 * torch.ones(x.shape[0], 2).cuda()

        if self.with_edge_attention:
            edge_att_mlp = self.edge_att_mlp(edge_rep)  # [1208,100]  == &gt; [1208,2]
            edge_att = F.softmax(edge_att_mlp, dim=-1)  #[1208, 2]
        else:
            edge_att = 0.5 * torch.ones(edge_rep.shape[0], 2).cuda()

        node_weight_c = node_att[:, 0]  #node_weight_t = node_att[:, 1]
        edge_weight_c = edge_att[:, 0]  #edge_weight_t = edge_att[:, 1]

        xc = node_weight_c.view(-1, 1) * x #[132, 50])
        #xt = node_weight_t.view(-1, 1) * x

        xc = xc + self.conv1(xc, edge_index, edge_weight_c)
        xc = F.relu(xc)
        xc = F.dropout(xc, self.dropout, training=self.training)
        xc = xc + self.conv2(xc, edge_index, edge_weight_c)
        return xc

</code></pre>
<p>The error message is as follow:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/7/67ed35652d963e9426dfe028fc5e4d1658c2cee1.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/67ed35652d963e9426dfe028fc5e4d1658c2cee1" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67ed35652d963e9426dfe028fc5e4d1658c2cee1_2_690x476.jpeg" alt="image" data-base62-sha1="ePnoA5mP76GVjkbQjAFUKCFgs2B" width="690" height="476" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67ed35652d963e9426dfe028fc5e4d1658c2cee1_2_690x476.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67ed35652d963e9426dfe028fc5e4d1658c2cee1_2_1035x714.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67ed35652d963e9426dfe028fc5e4d1658c2cee1_2_1380x952.jpeg 2x" data-dominant-color="343232"><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">image</span><span class="informations">1556×1074 407 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></p>
<p>Thanks a lot for helping me out!<br>
Vicky</p>

username: ConvolutionalAtom
cooked: <p>It seems that there is some inplace operation on weight parameter of linear layer <code>self.edge_att_mlp</code>.<br>
Are you using custom backward hook (that might include some inplace ops)?</p>
<p>Also, it would be better if you include text format instead of image (even the error messages) since text is easier to read and copy-pasted easily,</p>
<p>Edit: if possible, provide also executable piece of code for your error</p>