It is hard to tell without seeing the function. Are you writing an autograd Function or a loss Module / a python function?
If it is the latter, you could add a backward hook and set a breakpoint in that.
Best regards
Thomas