Hi,
I cant apply nn.Softmax() along each dimension separately.
I have a tensor in one dimension of size 4. I want to apply softmax on the first 2 values and the last 2 values separately.
in each way I tried to do it I get:
“RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [6, 4]], which is output 0 of TBackward, is at version 2; expected version 1 instead.”
adding my net architecture:
class Net(nn.Module):
def init(self):
super(Net, self).init()
self.fc1 = nn.Linear(4, 6)
self.fc2 = nn.Linear(6, 8)
self.fc3 = nn.Linear(8, 16)
self.fc4 = nn.Linear(16, 32)
self.fc5 = nn.Linear(32, 32)
self.fc6 = nn.Linear(32, 16)
self.fc7 = nn.Linear(16, 8)
self.fc8 = nn.Linear(8, 6)
self.fc9 = nn.Linear(6, 4)
def forward(self, x):
    x = F.relu(self.fc1(x))
    x = F.relu(self.fc2(x))
    x = F.relu(self.fc3(x))
    x = F.relu(self.fc4(x))
    x = F.relu(self.fc5(x))
    x = F.relu(self.fc6(x))
    x = F.relu(self.fc7(x))
    x = F.relu(self.fc8(x))
    x = F.relu(self.fc9(x))

    # x = x.view(2, 2)
    # x = x.reshape(2, 2)
    # x = F.softmax(x, dim=1)
    # x = x.view(4)

    # x1 = F.softmax(x[0, 0:2], dim=0)
    # x2 = F.softmax(x[0, 2:4], dim=0)
    x1 = x[0:2]
    x2 = x[2:4]
    x1 = F.softmax(x1, dim=0)
    x2 = F.softmax(x2, dim=0)
    x = torch.cat((x1, x2), 0)

    # x = F.softmax(x, dim=1)
    return x


can anyone please help me?