I write a new loss in pytorch, and I define a nn.Parameter that should update with an expression.
But I can’t get the right grad when setting with self.parameter.grad or self.parameter._grad.
class Loss(nn.Module):
    def __init__(...):
        self.parameter = nn.Parameter(...) # init parameters that need to be manually updated
    def forward(...):
        ...
        print(self.parameter.grad) # it is still autograd result, not zero
        self.paramter._grad = Variable(tensor.zeros(...)) # for example, set it to zero

The question is where and how can I set the grad manually.