def add_const(const_context, builder, name, val):
    """
    const_context (list of set of str): const names added to v1 builder. Const names are
    identical between v2 and v1

    name (str): name of const. Should be the same for v1 and v2.
    val: np.ndarray

    No return values as `name` is the name of const in v1.

    Comment: we don't need to add scalar const as they are just fields in
             layer proto message in NN.
             If we really need a const scalar, we upcast it to rank-1.

    """
    for const_set in const_context:
        if name in const_set:
            logger.warning("Const {} was already added.".format(name))
            return
    if not isinstance(val, (_np.ndarray, _np.generic)):
        val = _np.array([val])
    if val.dtype != float:
        # nn proto only supports float32 activation. (e.g., pred in cond op
        # needs to be converted to float)
        val = val.astype(float)
    rank = len(val.shape)
    if rank == 0:
        builder.add_load_constant_nd(
            name=name, output_name=name, constant_value=val.reshape([1]), shape=[1]
        )
    else:
        builder.add_load_constant_nd(
            name=name, output_name=name, constant_value=val, shape=val.shape
        )
    const_context[-1].add(name)
    logger.info("added const {} for builder {}".format(name, builder))

    const_context (list of set of str): const names added to v1 builder. Const names are
    identical between v2 and v1

    name (str): name of const. Should be the same for v1 and v2.
    val: np.ndarray

    No return values as `name` is the name of const in v1.

    Comment: we don't need to add scalar const as they are just fields in
             layer proto message in NN.
             If we really need a const scalar, we upcast it to rank-1.

    
coremltools/converters/mil/backend/nn/op_mapping.py