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 types.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(
                    types.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))

    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.
    
coremltools/converters/mil/backend/mil/helper.py