Hi,
I am trying to do a classification problem using NNs,but I get the following error when calling backward() :
Trying to backward through the graph a second time, but the buffers have already been freed
I can’t understand what s wrong with my computation graph since I am only passing through my model and then computing the loss.
def forward(self, x):
   output = torch.softmax(self.out.forward(x), dim=-1)
   return output

def train(self,some_params): 

   optim.zero_grad()

   output = self(train_data)
   likelihood = output.gather(1,train_labels[:, n].detach().long().unsqueeze(1))
   loss = -torch.log(likelihood)
   loss = torch.mean(loss)
   loss.backward()