def create_scalar_value(py_scalar):
    """
    Return TensorValue (since there's no ScalarValue)
    """
    # Create the "scalar" (rank 0) tensor
    builtin_type = types.type_to_builtin_type(type(py_scalar))
    value_type = create_valuetype_scalar(types_to_proto_primitive(builtin_type))
    val = proto.MIL_pb2.Value(type=value_type)
    t_val = val.immediateValue.tensor

    # Set the tensor value
    t_field = _tensor_field_by_type(t_val, builtin_type)
    if builtin_type in types.IMMEDIATE_VALUE_TYPES_IN_BYTES:
        # Serialize to bytes because MIL read them from the "bytes" field in TensorValue.
        val.immediateValue.tensor.bytes.values = types.type_mapping.np_val_to_py_type(py_scalar)
    else:
        if builtin_type == types.str:
            py_scalar = py_scalar.encode("utf-8")
        t_field.append(types.type_mapping.np_val_to_py_type(py_scalar))

    return val

    Return TensorValue (since there's no ScalarValue)
    
coremltools/converters/mil/backend/mil/helper.py