code: def _tensor_field_by_type(tensor_val, builtin_type):
      """
      Pick the field based on the builtin_type.
  
      The field is defined in TensorValue in ``mlmodel/format/MIL.proto``.
      The picked field need to be consistent with how it will be read by MIL.
      For example, int8 is serialized to ``bytes`` field while int16 is serialized to ``ints`` field.
      """
      if builtin_type == types.bool:
          return tensor_val.bools.values
      elif types.is_int(builtin_type):
          if (
              builtin_type == types.int64
              or builtin_type == types.uint64
          ):
              return tensor_val.longInts.values
          if builtin_type in IMMEDIATE_VALUE_TYPES_IN_BYTES:
              return tensor_val.bytes.values
          if (
              builtin_type == types.int16
              or builtin_type == types.uint16
          ):
              # TODO (rdar://111797203): Serialize to byte after MIL changes to read from byte field.
              return tensor_val.ints.values
          return tensor_val.ints.values
      elif types.is_float(builtin_type):
          if builtin_type == types.fp64:
              return tensor_val.doubles.values
          elif builtin_type == types.fp32:
              return tensor_val.floats.values
          elif builtin_type == types.fp16:
              return tensor_val.bytes.values
          else:
              raise TypeError(
                  "Unsupported float dtype for MIL proto serialization: {}".format(
                      builtin_to_string(builtin_type)
                  )
              )
      elif builtin_type == types.str:
          return tensor_val.strings.values
      else:
          raise NotImplementedError(
              "Unimplemented tensor type for: " + str(builtin_type)
          )
  
imports: import os
  import numpy
  import coremltools.proto.FeatureTypes_pb2
  import coremltools.proto.MIL_pb2
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.mil.types import BUILTIN_TO_PROTO_TYPES, builtin_to_string, numpy_type_to_builtin_type, type_to_builtin_type
  from coremltools.converters.mil.mil.types.type_mapping import np_val_to_py_type
  from coremltools.models.utils import _WEIGHTS_DIR_NAME, _WEIGHTS_FILE_NAME
label_desc: Use image node_id 8 for calling a global function with example usage: _tensor_field_by_type(tensor_val, builtin_type) and returns: tensor_val, tensor_val, tensor_val, tensor_val, tensor_val, tensor_val, tensor_val, tensor_val, tensor_val