The error comes most likely from
running_loss += loss.item()

as loss doesn’t seem to be a scalar.
You could uncomment one of these lines 38 to reduce the loss.
@PistonY These scripts 23 of @Thomas_Wolf provide this functionality.