print('t=%d,loss=%.4f'%(t+1,loss.data[0])) 问题就出现在这个代码上。 结果还是会照常显示,但是就会有warning。 UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number loss.data[0] 改成loss.item()就好了