So it seems that you want to override/define your own gradient function.
Have a look at this discussion