Solved by albanD in post #2 
              
              
                Hi, 
The problem I think is that you set j.requires_grad after you used it. So the graph is not created when you do the forward. 
You should move this at the beginning of the forward() function.