code: def has_inf_or_nan(tensor):
      try:
          # if tensor is half, the .float() incurs an additional deep copy, but it's necessary if
          # Pytorch's .sum() creates a one-element tensor of the same type as tensor
          # (which is true for some recent version of pytorch).
          tensor_sum = float(tensor.float().sum())
          # More efficient version that can be used if .sum() returns a Python scalar
          # tensor_sum = float(tensor.sum())
      except RuntimeError as instance:
          # We want to check if inst is actually an overflow exception.
          # RuntimeError could come from a different error.
          # If so, we still want the exception to propagate.
          if "value cannot be converted" not in instance.args[0]:
              raise
          return True
      else:
          if (
              tensor_sum == float("inf")
              or tensor_sum == -float("inf")
              or tensor_sum != tensor_sum
          ):
              return True
          return False
  
file_path: ColossalAI/colossalai/zero/low_level/_utils.py
imports: import math
  from typing import Optional
  import torch
  import torch.distributed
  from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
label_desc: Use image node_id 11 for calling a global function with example usage: has_inf_or_nan(tensor) and returns: False, True, True