dfalbel / torch

torch from R!
http://dfalbel.github.io/torch
Other
50 stars 5 forks source link

torch.no_grad #7

Closed dfalbel closed 5 years ago

dfalbel commented 5 years ago

Recently in pytorch it's not recommended to modify tensor$data. We should instead use a context manager like:

x = torch.randn(3, requires_grad=True)
print(x.requires_grad)
print((x ** 2).requires_grad)

with torch.no_grad():
    print((x ** 2).requires_grad)

We must be able to do this from R. I am not sure how yet. I think this is the relevant file in pytorch's code.