code: def must_run_on_cpu(node, pin_variables_on_cpu=False):
      """Returns True if the given node_def must run on CPU, otherwise False.
      Args:
        node: The node to be assigned to a device. Could be either an ops.Operation
          or NodeDef.
        pin_variables_on_cpu: If True, this function will return False if node_def
          represents a variable-related op.
      Returns:
        True if the given node must run on CPU, otherwise False.
      """
  
      if isinstance(node, ops.Operation):
          node_def = node.node_def
      else:
          invalidInputError(
              isinstance(node, node_def_pb2.NodeDef),
              f"node is not node_def_pb2.NodeDef type",
          )
          node_def = node
  
      # If the op is a variable-related op, should we pin it on CPU?
      if pin_variables_on_cpu and _is_variable_op(node_def.op):
          return True
  
      # Constant operations producing a string or int32 must run on CPU.
      if node_def.op == "Const":
          # Get the value of the 'dtype' attr
          dtype = node_def.attr["dtype"].type
          if dtype == dtypes.string or dtype == dtypes.int32:
              return True
  
      if node_def.op in ["DynamicStitch", "ParallelDynamicStitch"]:
          dtype = node_def.attr["T"].type
          if dtype == dtypes.int32:
              # DynamicStitch on GPU only works for int32 values.
              return True
  
      if node_def.op in ["Cast"]:
          dtype = node_def.attr["SrcT"].type
          if dtype == dtypes.int32:
              # Cast on GPU does not works for int32 values.
              return True
      return False
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import copy
  import re
  import six
  from tensorflow.core.framework import attr_value_pb2
  from tensorflow.core.framework import graph_pb2
  from tensorflow.core.framework import node_def_pb2
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.util import deprecation
  from tensorflow.python.util.tf_export import tf_export
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 2 for calling a global function with example usage: must_run_on_cpu(node, pin_variables_on_cpu) and returns: False, True, True, True, True