There’s another way, without hooks. You can directly adjust forward() method of your model’s class and return intermediate outputs with the actual output as a dict, for example.
As for hooks, take a look here: Debugging and Visualisation in PyTorch using Hooks 2