Skip to content

Commit

Permalink
[fix] Use torch.inference_mode inplace of torch.no_grad (#3188)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdumin authored Jul 14, 2024
1 parent dd246b3 commit 756f41a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions examples/pytorch_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# Initialize a new Run
aim_run = Run()

# Device configuration
device = torch.device('cpu')
# moving model to gpu if available
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

# Hyper parameters
num_epochs = 5
Expand Down Expand Up @@ -118,8 +118,7 @@ def forward(self, x):


# Test the model
model.eval()
with torch.no_grad():
with torch.inference_mode():
correct = 0
total = 0
for images, labels in test_loader:
Expand Down
7 changes: 3 additions & 4 deletions examples/pytorch_track_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# Initialize a new Run
aim_run = Run()

# Device configuration
device = torch.device('cpu')
# moving model to gpu if available
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

# Hyper parameters
num_epochs = 5
Expand Down Expand Up @@ -122,8 +122,7 @@ def forward(self, x):


# Test the model
model.eval()
with torch.no_grad():
with torch.inference_mode():
correct = 0
total = 0
for images, labels in tqdm(test_loader, total=len(test_loader)):
Expand Down

0 comments on commit 756f41a

Please sign in to comment.