Thank you! But I still get the same error following your code:
Traceback (most recent call last):
  File "/Users/audrey/PycharmProjects/PyTorchLearning/main.py", line 31, in <module>
    bias.grad.data.zero_()
AttributeError: 'NoneType' object has no attribute 'data'

Then I changed bias.item() into bias
predict = torch.mm(feature, weight) + bias

No error appeared anymore! I wonder why bias.item() doesn’t work.
Anyway, my code can run successfully, thanks!