I am trying to update Fisher matrix using this code:
def _update_fisher_params(self, current_ds, batch_size, num_batch):
	log_liklihoods = []
	i=1
	for inputs, target in tqdm(current_ds):
		inputs=inputs.cuda()
		target= target.cuda()
		if i >= num_batch:
			break

		output = F.log_softmax(self.model(inputs), dim=1).detach().requires_grad_(True)
		i+=1
		log_liklihoods.append(output[:, target])
	
	log_likelihood = torch.cat(log_liklihoods).mean()
	grad_log_liklihood = autograd.grad(log_likelihood, self.model.parameters(), create_graph=True, retain_graph =True)

I have tried create_graph=True and retain_graph=True also. But still, it gives the error: RuntimeError: One of the differentiated Tensors appears to not have been used in the graph. Set allow_unused=True if this is the desired behavior.
Also, if I remove detach() from my code, it says Cuda out of memory at the line where I append my tensors to the list(log_liklihoods).
Can someone please tell me where am I wrong? I am unable to understand anymore