Unable to enter debugging with hooks

I’m unable to enter breakpoints (using PyCharm) inside my hook functions, e.g.:

class MyModule(nn.Module):
    def __init__(self, train: bool):
        def hook(module, grad_input, grad_output):
            print('hello there')

I cannot break on the print but it will still execute. Does anyone know why that is and if there is a possible way to circumvent this?

The hooks are called as PyFunction calls from the C++ side. It’s possible that PyCharm cannot handle this yet.

Turning off cuda is a possible workaround. (cpu only)
For that, you could set CUDA_VISIBLE_DEVICES empty.