code: def assert_all_finite(
      X, allow_nan=False, msg_dtype=None, check_only=True
  ):
      if not isinstance(X, ENTITY_TYPE):
          X = mt.asarray(X)
  
      if (
          isinstance(X.op, AssertAllFinite)
          and X.op.allow_nan == allow_nan
          and X.op.msg_dtype == msg_dtype
          and X.op.check_only == check_only
      ):
          return X
  
      if check_only:
          output_types = [OutputType.tensor]
          sparse = False
      else:
          output_types = get_output_types(X)
          sparse = X.issparse()
  
      op = AssertAllFinite(
          x=X,
          allow_nan=allow_nan,
          msg_dtype=msg_dtype,
          check_only=check_only,
          sparse=sparse,
          output_types=output_types,
      )
      return op(X)
  
imports: import numpy
  from ...None import opcodes
  from ...None import tensor
  from ...core import ENTITY_TYPE, get_output_types, recursive_tile
  from ...core.operand import OperandStage
  from ...config import options
  from ...serialization.serializables import KeyField, StringField, BoolField, DataTypeField
  from ...tensor.core import TensorOrder, TENSOR_CHUNK_TYPE
  from ...tensor.array_utils import as_same_device, device, issparse, get_array_module
  from ...utils import ceildiv
  from ..operands import LearnOperand, LearnOperandMixin, OutputType
label_desc: Use image node_id 2 for calling a global function with example usage: assert_all_finite(X, allow_nan, msg_dtype, check_only) and returns: op, X