I am using autograd in order to get a derivative of the output w.r.t the input features, using the following code:
torch.autograd.grad(
                outputs=pred,
                inputs=input,    
                allow_unused=True, 
                retain_graph=True, 
                create_graph=True)[0])

I had to set ‘allow_unused=True’ after getting 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.

but then the gradients are always ‘None’.
What could be the reason for this behavior?