Just avoiding using forward directly doesn’t really solve the issue that it breaks IDE support. One potential solution could be this Solution to different forward for train and inference + IDE support for forward args . Here I just wrapped nn.Module to allow a forward method with both hooks and IDE support is retained.