.data has still the same semantics, but it’s recommended to use .detach() instead.
Have a look at the Migration Guide 28 (“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 and possibly an error in future versions.