When we define our model in PyTorch. We run through different #epochs. I want to know that in the iteration of epochs.
What is the difference between the two following snippets of code in which the order is different? These two snippet versions are:
- I found over tutorials
- The code provided by my supervisor for the project.
Tutorial Version
for i in range(epochs):
logits = model(x)
loss = loss_fcn(logits,lables)
loss.backward()
optimizer.step()
optimizer.zero_grad()
Supervisor Version
for i in range(epochs):
logits = model(x)
loss = loss_fcn(logits,lables)
optimizer.zero_grad()
loss.backward()
optimizer.step()