Variable.grad is not writable, while Variable._grad is writable. If you want to force the value of the gradient to equal another value, you must modify ._grad and not .grad otherwise, you will have the exception:
AttributeError: attribute 'grad' of 'torch._C._VariableBase' objects is not writable