UPDATE: `register_backward_hook()` has been deprecated in favor of `register_full_backward_hook()`. You can read more about `register_full_backward_hook()` here: https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.register_full_backward_hook In this video, I explain how hooks work in PyTorch. Hooks allow you to inject code into different parts of the computational graphs (in both the forward graph and the backward graph). The four types of hooks that are available in PyTorch are: Tensor.register_hook (https://pytorch.org/docs/stable/generated/torch.Tensor.register_hook.html) Module.register_forward_pre_hook (https://pytorch.org/docs/master/generated/torch.nn.Module.html#torch.nn.Module.register_forward_pre_hook) Module.register_forward_hook (https://pytorch.org/docs/master/generated/torch.nn.Module.html#torch.nn.Module.register_forward_hook) Module.register_backward_hook (https://pytorch.org/docs/master/generated/torch.nn.Module.html#torch.nn.Module.register_backward_hook) My previous video, "PyTorch Autograd Explained - In-depth Tutorial": 📼 https://youtu.be/MswxJw-8PvE GitHub code examples of using hooks: 💻 https://github.com/elliotwaite/pytorch-hooks-tutorial Join our Discord community: 💬 https://discord.gg/cdQhRgw Connect with me: 🐦 Twitter - https://twitter.com/elliotwaite 📷 Instagram - https://www.instagram.com/elliotwaite 👱 Facebook - https://www.facebook.com/elliotwaite 💼 LinkedIn - https://www.linkedin.com/in/elliotwaite 🎵 Kazukii - Return → https://soundcloud.com/ohthatkazuki → https://open.spotify.com/artist/5d07MpiIaNmmEMTq79KAga → https://www.youtube.com/user/OfficialKazuki