how to backward if my loss is something about the derivative of the net output?
for example:
my input is ‘u’, then my net output can be seemed as f(u).
and my target is target = a*( f ’ (u)|u ) + b,        " f ’ (u)|u" means the derivative of ’ f ’ w.r.t ‘u’
so my loss may will be ‘| ground truth - target |’.
Is this kind of loss can be backwarded in pytorch?
I tried to backward something about the derivative, but it can’t work.
here is my code :
import torch
from torch.autograd import Variable
x = Variable(torch.ones(2, 2), requires_grad=True)
y = x + 2
out = y
out.backward(torch.ones(2, 2))
k = 2*x.grad
k.backward()
the error is :
k.backward()
RuntimeError: element 0 of variables tuple is volatile
it seems like pytorch will not save the parameters when it calculates the derivative.
Has there any method to solve this kind of questions?
Thank you.