You should always use .detach() if you want to detach a tensor from the graph. The other option .data is for older versions of PyTorch, and it is likely that it will be removed from the future versions of PyTorch.