Solved by albanD in post #4 
              
              
                Hi, 
The error in the second function is that since it has two outputs from the forward, it will get two grad_ inputs in the backward method. Here you expect only one hence the error.