Solved by ptrblck in post #2 
              
              
                Your code won’t work and will raise: 
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

if you try to call backward() on out or an output of any successive operation on it, since it was calculated in the no_grad block: 
G = nn.Linear(1, 1)
F = nn.Linear(1, 1)
x = …