By implementing some c++ extensions I noticed that if I transfer GPU tensor to CPU using one-liner (
auto my_tensor_ptr = my_tensor.cpu().data_ptr<float>();), usually what happens is that this pointer becomes some kind of a dangling pointer and data indexed via brackets operator
 is not valid anymore. It can be easily fixed by introducing a temporary variable:
auto my_tensor_cpu = my_tensor.cpu(); auto my_tensor_ptr = my_tensor_cpu.data_ptr<float>();
Nevertheless, I sill don’t understand why does this deallocation occurs.
Any explanation will be highly appreciated.