Skip to content

Commit

Permalink
Remove duplicate no_grad context managers (#16773)
Browse files Browse the repository at this point in the history
  • Loading branch information
carmocca authored Feb 16, 2023
1 parent 51d44f5 commit cc22ddc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/lightning/pytorch/loops/epoch/training_epoch_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from collections import OrderedDict
from typing import Any, Dict, Optional, Union

import torch

import lightning.pytorch as pl
from lightning.pytorch import loops # import as loops to avoid circular imports
from lightning.pytorch.loops.fetchers import _DataFetcher, _DataLoaderIterDataFetcher
Expand Down Expand Up @@ -284,8 +282,7 @@ def _run_validation(self) -> None:
# reload dataloaders
self.val_loop._reload_evaluation_dataloaders()

with torch.no_grad():
self.val_loop.run()
self.val_loop.run()

def _accumulated_batches_reached(self) -> bool:
"""Determine if accumulation will be finished by the end of the current batch."""
Expand Down
3 changes: 1 addition & 2 deletions src/lightning/pytorch/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,7 @@ def _run_sanity_check(self) -> None:
]

# run eval step
with torch.no_grad():
val_loop.run()
val_loop.run()

call._call_callback_hooks(self, "on_sanity_check_end")

Expand Down

0 comments on commit cc22ddc

Please sign in to comment.