Solved by albanD in post #2 
              
              
                Hi, 
If you’re not running with creat_graph=True, then the backward runs with autograd disabled. 
If you need to enable it locally you can use with torch.enable_grad():. Also I would advise you to use autograd.grad here to get the gradient more easily: 
            local_net = nn.Sequential(nn.Linea…