Solved by albanD in post #2 
              
              
                Hi, 
Your function takes 2 input (w and x) and has 1 output (o). 
So the backward function will take as input the gradients wrt to o: do and should return gradients for all the inputs: dw and dx. Your backward function should not expect a grad_weight as input.