def _is_const(var, optional=False):
    """
    Check if a var is a const.
    It could be `const` or `constexpr_` ops.
    """
    if optional and var is None:
        return True
    if isinstance(var, np.ndarray):
        return True
    return (
        var is not None
        and isinstance(var, Var)
        and var.op is not None
        and (
            var.op.op_type.startswith("constexpr_")
            or (var.op.op_type == "dequantize" and var.op.can_materialize_val())
            or var.val is not None
        )
    )

    Check if a var is a const.
    It could be `const` or `constexpr_` ops.
    
coremltools/converters/mil/frontend/torch/ops.py