fmassa:

for i, (x, y) in enumerate(train_loader): x = Variable(x) y = Variable(y)


How about the case when the tensor is inside a function, if we exit the function, does that mean the data stored to the device (GPU in this case) will be deleted?
def foo():
    data, target = data.to(device), target.to(device) 
    for i, (data, target) in enumerate(train_loader):
           # do something
           result = ...
    del data, target # is this step necessary?
    return result
 
foo() # first call
foo() # second call