Runtime error while do training

class segmodel(nn.Module):
def init(self, depth=3,num_classes=22):
super().init()
self.pt = MLPin()
self.encod1 = encoder1()
self.encod2 = encoder()
self.encod3 = encoder()
self.encod4 = encoder()
self.decod1 = decoder()
self.decod2 = decoder()
self.decod3 = decoder()
self.decod4 = decoder()
self.conv1 = nn.Conv1d(1, 64, 1)
self.bn1 = nn.BatchNorm1d(64)
self.conv2 = nn.Conv1d(64, 128, 1)
self.bn2 = nn.BatchNorm1d(128)
self.drop1 = nn.Dropout(0.2)
self.conv3 = nn.Conv1d(128, num_classes, 1)

def forward(self, x):
    x1 = self.pt(x)
    x2 = self.encod1(x)
    x3 = self.decod1(x2)

    x4 = self.encod2(x3)
    x5 = self.decod2(x4)

    x6 = self.encod3(x5)
    x6 = x4 +x6
    x7 = self.decod3(x6)
    x7 = x3 +x7
    x8 = self.encod4(x7)
    x8 = x2+ x8
    x9 = self.decod4(x8)

    x10 = x9+x1
    x10 = torch.reshape(x10,(batch_size,num_point*Number_of_Slices,1))

    x10 = x10.permute(0, 2, 1)


    x10 = F.relu(self.bn1(self.conv1(x10)), inplace=True)
    print(x10.shape)


    x10 = self.drop1(F.relu(self.bn2(self.conv2(x10)), inplace=True))
    print(x10.shape)
    x10 = self.conv3(x10)
    print(x10.shape)


    x10 = F.softmax(x10, dim=1)

    x10 = x10.permute(0, 2, 1)

    # x10= x10.contiguous().view(-1, 22)
    # x10 = torch.reshape(x10,(batch_size*Number_of_Slices*num_point,22))


    return x10

class decoder(nn.Module):
def init(self):
super().init()
self.mpl1 = MLP2()
self.mpl2 = MLP2()
self.mpl3 = MLP2()
self.sft = nn.Softmax(dim=2)
self.conv1 = nn.Conv1d(batch_size*Number_of_Slices,Number_of_Slices,1)
# self.adaptive1 = nn.AdaptiveAvgPool1d(1)
# self.adaptive2 = nn.AdaptiveAvgPool1d(2)

def forward(self, x):
    out1 = self.mpl1(x)
    out1 =out1.mean(dim=(1) )

    out2 = self.mpl2(x)
    out2 = out2.mean(dim=(2))

    f1 = torch.reshape(out1, (batch_size * num_point, 1))
    f2 = torch.reshape(out2, (batch_size * Number_of_Slices, 1))
    f1 = torch.squeeze(f1)
    f2 = torch.squeeze(f2)
    f3 = torch.outer(f1, f2)
    f4 = torch.reshape(f3, (batch_size, num_point, batch_size * Number_of_Slices))
    f4 = torch.permute(f4, (0, 2, 1))

    out3 = self.sft(f4)
    out3 = self.conv1(out3)
    out4 = self.mpl3(x)
    out5 = out3 + out4
    out = out5 + x
    #
    # feature_vector1 = feature_maps.mean(dim=(1))  # or dim=(2, 3)
    # feature_vector2 = feature_maps.mean(dim=(2))
    # f1 = torch.reshape(feature_vector1, (16384, 1))
    # f2 = torch.reshape(feature_vector2, (288, 1))
    # f1 = torch.squeeze(f1)
    # f2 = torch.squeeze(f2)
    #
    # print(feature_vector1.shape)
    # print(feature_vector2.shape)
    #
    # f3 = torch.outer(f1, f2)
    # f4 = torch.reshape(f3, (8, 2048, 288))
    # f4 = torch.permute(f4, (0, 2, 1))


    return out

I got this error. Does reshaping creates problem. Please help me out in this.
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File “/home/cyz/anaconda3/envs/ibrahim/lib/python3.8/site-packages/torch/autograd/init.py”, line 154, in backward
Variable._execution_engine.run_backward(
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

Double post from here.

@ptrblck Could you see the issue in the code please? I have been trying but could not succeed yet.

Thank you.

Please post a minimal, executable code snippet as your current one uses undefined modules.
You can post code snippets by wrapping them into three backticks ```.