You are overwriting your parameters in the update block.
To avoid this. you could use inplace operations:
with torch.no_grad():
    w1.sub_(learningrate*w1.grad.data)
    w2.sub_(learningrate*w2.grad.data)
    w1.grad.zero_()
    w2.grad.zero_()