Custom backward() breakpoint doesn't get hit


(Sia Rezaei) #1

I’m new to Pytorch. I’m running this example: http://pytorch.org/tutorials/beginner/pytorch_with_examples.html#pytorch-defining-new-autograd-functions

My breakpoints in the forward() function are hit, but not the ones in the backward function. Why?
I’m using PyCharm CE.


#2

had same question. I think the backward() of a custom Function is called in a separate thread. Try adding “print(current_thread())” (don’t forget the import “from threading import current_thread”) in your backward() and your forward() in your custom module (and maybe some other place in the code). Different things are printed. Still don’t know how to have breakpoints in backward() tho.


(Simon Wang) #3

Could you post your code so that me or other people can help you?


#4

the example linked by the original question should do it (edit: meaning not hitting the breakpoint in backward())


(Sia Rezaei) #5

Just use the code in the example.


(Simon Wang) #6

I am not able to reproduce it with pdb. Maybe that is different with PyCharm’s breakpoint. The backward() functions are called from C side so that might be breaking these things. You could use pdb instead, which is also more commonly used…