Solved by ptrblck in post #2 
              
              
                .data has still the same semantics, but it’s recommended to use .detach() instead. 
Have a look at the Migration Guide (“What about .data?” section). 
To collect your loss, the recommended way is to use loss.item() instead of loss.data[0], since indexing into a scalar will give you a warning for now…