I think you should either use Variables with requires_grad = True or a Parameter class for the weights. But I might be wrong…
And that code is just for a cell, right? You should have to do a for loop somewhere!