Skip to content

Commit

Permalink
corrected comment regarding .train and .eval (#2659)
Browse files Browse the repository at this point in the history
Co-authored-by: Svetlana Karslioglu <svekars@meta.com>
  • Loading branch information
Viditagarwal7479 and svekars authored Nov 7, 2023
1 parent 88e017e commit 789fc09
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions beginner_source/introyt/tensorboardyt_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ def forward(self, x):
# Check against the validation set
running_vloss = 0.0

net.train(False) # Don't need to track gradents for validation
# In evaluation mode some model specific operations can be omitted eg. dropout layer
net.train(False) # Switching to evaluation mode, eg. turning off regularisation
for j, vdata in enumerate(validation_loader, 0):
vinputs, vlabels = vdata
voutputs = net(vinputs)
vloss = criterion(voutputs, vlabels)
running_vloss += vloss.item()
net.train(True) # Turn gradients back on for training
net.train(True) # Switching back to training mode, eg. turning on regularisation

avg_loss = running_loss / 1000
avg_vloss = running_vloss / len(validation_loader)
Expand Down

0 comments on commit 789fc09

Please sign in to comment.