Hey – according to these docs 19 Variable is deprecated, and it seems that you can write to the Tensor.grad attribute now. For example: (python 3.7, torch v1.2.0):
import torch

#case 1, an ordinary Tensor
a = torch.randn(1, requires_grad=True)
assert a.grad is None
a.grad = torch.ones_like(a)
a.grad.data = 2* torch.ones_like(a)
print(a.grad)  # prints tensor([2.])

# case 2, parameters in an nn.Module
class MyModel(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.layer = torch.nn.Linear(1,1)
    
model = MyModel()
for param in model.parameters():
    assert param.grad is None
    param.grad = torch.ones_like(param.data)
    param.grad.data = 2 * torch.ones_like(param.data)
    print(param.grad) #more 2's, no error