Solved by albanD in post #2 
              
              
                Hi, 
If you only want the gradient for the input, the simplest thing I can think of is: 
model = # Your model
input = # Your input

# Make sure input requires grad
input.requires_grad_(True)

# Do the forward as usual
output = model(input)
loss = crit(output, label)

# Ask only for the grad wrt the …