Solved by ptrblck in post #2 
              
              
                I’m not sure how linearZ is supposed to work, as it seems like you would like to calculate the gradients in backward as well as manipulate some model parameters. 
Could you explain the use case a bit as I think both steps (gradient calculation and parameter manipulation) should be done separately. 
…