Thank you for your reply! I think your code change the update of former layers because you make grad_input to zero, which means all former layers’ parameters will not change. But I have a parameter in my loss, and I need this parameter to be update manually, without changing former layers. I’ve tried your code, and get the following:
optimzer = optim.SGD(lossobject.parameters(), lr =0.01)
AttributeError: 'Loss' object has no attribute 'parameters'