class_docstr: This transform does the following, for each valid op and if the "op_selector" return True:
  - For each input of dtype float32, inject a "cast" op to change it to float16 dtype
  - For each output of dtype float16, inject a "cast" op to change it back to float32
class_docstr_tok: ["This","transform","does","the","following",",","for","each","valid","op","and","if","the","``","op_selector","''","return","True",":","-","For","each","input","of","dtype","float32",",","inject","a","``","cast","''","op","to","change","it","to","float16","dtype","-","For","each","output","of","dtype","float16",",","inject","a","``","cast","''","op","to","change","it","back","to","float32"]
docstr: Determines if any of the op's input will overflow when represented by FP16.
  
  This overflow check consists of two parts:
  1. For valid fp32 numbers (abs < 1e38), we want their exact values,
     so we make sure they are within fp16 range [-65504, 65504]
  2. For inifinities (abs >= 1e38), their exact values does not matter,
     so we can always downcast them to fp16 inf. For example, in attention mask
     we just want -inf to make the masked entries have 0 probability after softmax
docstr_tok: ["Determines","if","any","of","the","op","'s","input","will","overflow","when","represented","by","FP16",".","This","overflow","check","consists","of","two","parts",":","1",".","For","valid","fp32","numbers","(","abs","<","1e38",")",",","we","want","their","exact","values",",","so","we","make","sure","they","are","within","fp16","range","[","-65504",",","65504","]","2",".","For","inifinities","(","abs",">","=","1e38",")",",","their","exact","values","does","not","matter",",","so","we","can","always","downcast","them","to","fp16","inf",".","For","example",",","in","attention","mask","we","just","want","-inf","to","make","the","masked","entries","have","0","probability","after","softmax"]
code: def fp16_overflow(op: Operation) -> bool:
      """
      Determines if any of the op's input will overflow when represented by FP16.
  
      This overflow check consists of two parts:
      1. For valid fp32 numbers (abs < 1e38), we want their exact values,
         so we make sure they are within fp16 range [-65504, 65504]
      2. For inifinities (abs >= 1e38), their exact values does not matter,
         so we can always downcast them to fp16 inf. For example, in attention mask
         we just want -inf to make the masked entries have 0 probability after softmax
      """
      for _, inputs in op.inputs.items():
          is_list_input = isinstance(inputs, (list, tuple))
          if not is_list_input:
              inputs = [inputs]
          for var in inputs:
              if (
                  var.op is not None
                  and var.op.op_type == "const"
                  and var.is_tensor_or_scalar_of(dtype="fp32")
              ):
                  value = np.expand_dims(var.op.val.val, 0)
                  abs_value = np.abs(value)
                  if (
                      np.max(
                          abs_value[np.where(abs_value < 1e38)],
                          initial=0.0,
                      )
                      > 65504
                  ):
                      return True
      return False
  
imports: from abc import abstractmethod
  from enum import Enum
  from typing import Set, Text
  import numpy
  from coremltools.converters.mil._deployment_compatibility import AvailableTarget
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Operation, types
  from coremltools.converters.mil.mil.block import is_current_opset_version_compatible_with
  from coremltools.converters.mil.mil.ops.registry import SSAOpRegistry
  from coremltools.converters.mil.mil.passes.graph_pass import AbstractGraphPass
  from coremltools.converters.mil.mil.passes.helper import block_context_manager
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
  from coremltools.converters.mil.mil.program import Program
  from coremltools.converters.mil.mil.types.symbolic import is_symbolic
label_desc: Use image node_id 4 for calling the FP16ComputePrecision obj's underlying member method code with example usage: obj.fp16_overflow(op) and returns: False, True