I recently asked on the pytorch beginner forum if it was good practice to wrap the data with Variable each step or pre-wrap the data before training starts. It seems that its better (for some unknown reason to me) to wrap each step rather than before the training starts. Do people know why thats true?

Context, saw the practice here:

  
      github.com
  
  
    vinhkhuc/PyTorch-Mini-Tutorials/blob/master/2_logistic_regression.py#L20 6

def build_model(input_dim, output_dim):
# We don't need the softmax layer here since CrossEntropyLoss already
# uses it internally.
model = torch.nn.Sequential()
model.add_module("linear",
                 torch.nn.Linear(input_dim, output_dim, bias=False))
return model




def train(model, loss, optimizer, x_val, y_val):
x = Variable(x_val, requires_grad=False)
y = Variable(y_val, requires_grad=False)


# Reset gradient
optimizer.zero_grad()


# Forward
fx = model.forward(x)
output = loss.forward(fx, y)


# Backward