Solved by KFrank in post #4 
              
              
                Hi Sebastian! 

Your error is caused by python scoping rules and is not specific to 
pytorch nor torch.autograd.functional.jacobian. 
Please see this python FAQ: 
Why do lambdas defined in a loop with different values all return the same result? 
Here is a tweaked version of your code that shows how…