I am not sure to understand what you’re doing. Why would you set gradients during the forward pass?
If you want to accumulate gradients in a Variable, I guess the cleanest way to do it is:
your_var.backward(your_grad)