class_docstr: Detects the first NaN or Inf in forward and/or backward pass and logs, together with the module name
class_docstr_tok: ["Detects","the","first","NaN","or","Inf","in","forward","and\/or","backward","pass","and","logs",",","together","with","the","module","name"]
code: def _detect(self, tensor, name, backward):
      err = None
      if (
          torch.is_floating_point(tensor)
          # single value tensors (like the loss) will not provide much info
          and tensor.numel() >= 2
      ):
          with torch.no_grad():
              if torch.isnan(tensor).any():
                  err = "NaN"
              elif torch.isinf(tensor).any():
                  err = "Inf"
      if err is not None:
          err = f"{err} detected in output of {name}, shape: {tensor.shape}, {'backward' if backward else 'forward'}"
      return err
  
file_path: fairseq/fairseq/nan_detector.py
imports: import logging
  import torch
label_desc: Use image node_id 6 for calling the NanDetector obj's underlying member method code with example usage: obj._detect(tensor, name, backward) and returns: err