Created
April 4, 2020 23:25
-
-
Save bhpfelix/2e9cbb8df73eae389478e4c4cdd13326 to your computer and use it in GitHub Desktop.
RuntimeError: Trying to backward through the graph a second time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import numpy as np | |
# This will be share by both iterations and will make the second backward fail ! | |
a = torch.ones(3, requires_grad=True) * 4 | |
# Instead, do | |
# a = torch.tensor(np.ones(3) * 4, requires_grad=True) | |
for i in range(10): | |
d = torch.sum(a) | |
# The first here will work but the second will not ! | |
d.backward() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment