Skip to content

Instantly share code, notes, and snippets.

@vaibkumr
Last active January 6, 2019 12:34
Show Gist options
  • Select an option

  • Save vaibkumr/919e2292382bbda0b8c077fa122e6c7a to your computer and use it in GitHub Desktop.

Select an option

Save vaibkumr/919e2292382bbda0b8c077fa122e6c7a to your computer and use it in GitHub Desktop.
Check if tracking is enabled
import torch
# Creating the graph
x = torch.tensor(1.0, requires_grad = True)
# Check if tracking is enabled
print(x.requires_grad) #True
y = x * 2
print(y.requires_grad) #True
with torch.no_grad():
# Check if tracking is enabled
y = x * 2
print(y.requires_grad) #False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment