When a Cuda variable in PyTorch is assigned a new value, it becomes a CPU variable again (As illustrated by the code below). In this case, is the memory held by the variable on the GPU previously is freed automatically?
import torch
t1 = torch.empty(4,5)
if torch.cuda.is_available():
t1 = t1.cuda()
print(t1.is_cuda)
t1 = torch.empty(4,5)
print(t1.is_cuda)
The output of the above code is:
True
False