[trainer] Simplify Trainer dependencies by making TrainerTrainingTricksMixin a utils class
🚀 Feature
Training tricks doesn't need to be inherited from the core Trainer class. These methods could be utility functions that sit completely outside the Trainer class hierarchy.

  
    
      pytorch-lightning/pytorch_lightning/trainer/training_tricks.py
    
    
         Line 28
      in
      bb9ace4
    
  
  
    

        
          
           class TrainerTrainingTricksMixin(ABC): 
        
    
  


Motivation
Simplify the Trainer inheritance hierarchy and create more reusable utilities
Pitch
Deprecate the mixin and move the functions out to a utilities file for NaN detection. All we have to do is accept an nn.Module as input and pass the LightningModule to these functions from within the training loop.



 def print_nan_gradients(model: nn.Module) -> None:




def detect_nan_tensors(model: nn.Module) -> None:

we can separately check for the loss being NaN inside the training loop directly, since thats a specific call here: 
  
    
      pytorch-lightning/pytorch_lightning/trainer/training_tricks.py
    
    
        Lines 43 to 45
      in
      bb9ace4
    
  
  
    

        
          
           # check if loss is nan 
        

        
          
           if not torch.isfinite(loss).all(): 
        

        
          
               raise ValueError('The loss returned in `training_step` is nan or inf.') 
        
    
  


Deprecation path:

Add the new utilities in a standalone file
Make the mixin call the new utilities
Update the training loop to directly call the new utilities
Add a deprecation warning to the methods inside the mixin that mark them as deprecated

Alternatives
Keep as is
Additional context