Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving issue#2083 #2400

Merged
merged 3 commits into from
Jun 1, 2023
Merged

Resolving issue#2083 #2400

merged 3 commits into from
Jun 1, 2023

Conversation

zabboud
Copy link
Contributor

@zabboud zabboud commented Jun 1, 2023

Fixes #2083

Description

Added model.eval() in test loop and comments to explain what model.eval() does. Added additional comments before torch.no_grad() to explain the differences between model.eval() and torch.no_grad() and their uses.

Changes:

def train_loop(dataloader, model, loss_fn, optimizer):
    ....
    # Set the model to training mode - important for batch normalization and dropout layers
    # Unnecessary in this situation but added for best practices
    model.train()
    .....


def test_loop(dataloader, model, loss_fn):
    # Set the model to evaluation mode - important for batch normalization and dropout layers
    # Unnecessary in this situation but added for best practices
    model.eval()
       .....

    # Evaluating the model with torch.no_grad() ensures that no gradients are computed during test mode
    # also serves to reduce unnecessary gradient computations and memory usage for tensors with requires_grad=True
    with torch.no_grad():
             .....

Checklist

  • The issue that is being fixed is referred in the description (see above "Fixes model.eval() #2083 ")
  • Only one issue is addressed in this pull request
  • Labels from the issue that this PR is fixing are added to this pull request
  • No unnecessary issues are included into this pull request.

cc @suraj813

@netlify
Copy link

netlify bot commented Jun 1, 2023

Deploy Preview for pytorch-tutorials-preview ready!

Name Link
🔨 Latest commit 0f854b7
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-tutorials-preview/deploys/64791f251c30bb0007630b8f
😎 Deploy Preview https://deploy-preview-2400--pytorch-tutorials-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@svekars svekars merged commit 9b54056 into pytorch:main Jun 1, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docathon-h1-2023 A label for the docathon in H1 2023 easy intro
Projects
None yet
Development

Successfully merging this pull request may close these issues.

model.eval()
4 participants