class_docstr: A base class for training hooks in PyTorch.
  
  This class provides a template for implementing custom training hooks
  that can be activated, deactivated, and maintain a handle to the hook.
  
  Attributes:
      _hook_handle (Optional[torch.utils.hooks.RemovableHandle]): A handle to the
          registered forward hook, initially set to None.
docstr: Abstract method to be implemented by subclasses. This is the method that defines the custom behavior of
  the training hook during a forward pass for the specified module.
  
  Args:
      module (nn.Module): The PyTorch module for which the hook is activated.
      inputs (torch.Tensor): The input to the module during the forward pass.
      outputs (torch.Tensor): The output from the module during the forward pass.
  
  Returns:
      torch.Tensor: The output tensor from the module.
  
  Raises:
      NotImplementedError: If the method is not implemented in a subclass.
docstr_tok: ["Abstract","method","to","be","implemented","by","subclasses",".","This","is","the","method","that","defines","the","custom","behavior","of","the","training","hook","during","a","forward","pass","for","the","specified","module",".","Args",":","module","(","nn.Module",")",":","The","PyTorch","module","for","which","the","hook","is","activated",".","inputs","(","torch.Tensor",")",":","The","input","to","the","module","during","the","forward","pass",".","outputs","(","torch.Tensor",")",":","The","output","from","the","module","during","the","forward","pass",".","Returns",":","torch.Tensor",":","The","output","tensor","from","the","module",".","Raises",":","NotImplementedError",":","If","the","method","is","not","implemented","in","a","subclass","."]
code: def hook_fn(
      self,
      module: torch.nn.Module,
      inputs: torch.tensor,
      outputs: torch.Tensor,
  ) -> torch.Tensor:
      """Abstract method to be implemented by subclasses. This is the method that defines the custom behavior of
      the training hook during a forward pass for the specified module.
  
      Args:
          module (nn.Module): The PyTorch module for which the hook is activated.
          inputs (torch.Tensor): The input to the module during the forward pass.
          outputs (torch.Tensor): The output from the module during the forward pass.
  
      Returns:
          torch.Tensor: The output tensor from the module.
  
      Raises:
          NotImplementedError: If the method is not implemented in a subclass.
      """
      pass
  
file_path: ludwig/ludwig/modules/training_hooks.py
imports: import logging
  from abc import ABC, abstractmethod
  import torch
label_desc: Use image node_id 2 for calling the TrainingHook obj's underlying member method code with example usage: obj.hook_fn(module, inputs, outputs) without return types