It’s pretty hard to help you here since I can’t reproduce your error. I would recommend you to use a debugger and look at your loss variable and figure out how to access the loss from what is likely some sort of tensor. The error message indicates that you might want to use a .item() somewhere.