Solved by albanD in post #2 
              
              
                Hi, 
First, make sure your inputs require gradients: 

If they don’t, just call requires_grad_() on them before giving them to your net
If they do and are leaf (inp1.is_leaf()) then you’re good to go
If they do but are not leafs, you can do inp1.retain_grad() to make sure the .grad field will be pop…