code: def contains_nan_or_inf_tensors(module: torch.nn.Module) -> bool:
      """Check for NaN or infinity (inf) values in the tensors (parameters and buffers) of a PyTorch module. This
      function recursively inspects the module's parameters and buffers to identify NaN or inf values. It is designed
      to ensure the numerical stability of the model by detecting any irregularities in the tensor values.
  
      Parameters:
          module (torch.nn.Module): The PyTorch module to check for NaN or inf values.
  
      Returns:
          bool: Returns True if any NaN or inf values are found in the module's tensors. Otherwise, returns False.
      """
      for name, param in module.named_parameters():
          if param.requires_grad and (
              torch.isnan(param).any() or torch.isinf(param).any()
          ):
              logger.info(
                  f"Found NaN or inf values in parameter '{name}' of module '{module.__class__.__name__}'"
              )
              return True
  
      for name, buffer in module.named_buffers():
          if torch.isnan(buffer).any() or torch.isinf(buffer).any():
              logger.info(
                  f"Found NaN or inf values in buffer '{name}' of module '{module.__class__.__name__}'"
              )
              return True
  
      for name, submodule in module.named_children():
          if contains_nan_or_inf_tensors(submodule):
              logger.info(
                  f"Found NaN or inf values in submodule '{name}' of module '{module.__class__.__name__}'"
              )
              return True
  
      return False
  
file_path: ludwig/ludwig/utils/model_utils.py
imports: import logging
  from collections import OrderedDict
  from typing import Dict, List, Tuple
  import numpy
  import torch
label_desc: Use image node_id 4 for calling a global function with example usage: contains_nan_or_inf_tensors(module) and returns: False, True, True, True