def model_proto_to_olive_model(
    model_proto: onnx.ModelProto,
    output_model_path: Union[str, Path],
    external_data_config: Union[dict[str, Any], type[BasePassConfig]],
    check_model: bool = False,
    external_initializers_file_name: Optional[str] = None,
    constant_inputs_file_name: Optional[str] = None,
    force_model_dir: bool = False,
) -> ONNXModelHandler:
    """Save the ONNX model to the specified path and return the ONNXModelHandler.

    :param model_proto: The ONNX model to save.
    :param output_model_path: The path to save the ONNX model to.
    :param external_data_config: The external data configuration. Must be a dictionary with keys
        "save_as_external_data", "all_tensors_to_one_file", and "external_data_name".
    :param check_model: If True, run onnx.checker.check_model on the model before returning.
    :param external_initializers_file_name: The name of the external initializers file.
    :param constant_inputs_file_name: The name of the constant inputs file.
    :param force_model_dir: If True, use the parent directory of the output model path as the model directory
        regardless of whether external data is used.

    :return: The ONNXModelHandler.
    """
    config_keys = [
        "save_as_external_data",
        "all_tensors_to_one_file",
        "external_data_name",
        "size_threshold",
        "convert_attribute",
    ]
    if not isinstance(external_data_config, dict):
        external_data_config = external_data_config.dict()
    has_external_data = model_proto_to_file(
        model_proto, output_model_path, **{k: external_data_config[k] for k in config_keys if k in external_data_config}
    )
    if has_external_data or external_initializers_file_name or constant_inputs_file_name or force_model_dir:
        model_path = LocalFolder({"path": Path(output_model_path).parent})

        onnx_file_name = Path(output_model_path).name
    else:
        model_path = LocalFile({"path": output_model_path})
        onnx_file_name = None

    olive_model = ONNXModelHandler(
        model_path=model_path,
        onnx_file_name=onnx_file_name,
        external_initializers_file_name=external_initializers_file_name,
        constant_inputs_file_name=constant_inputs_file_name,
    )

    if check_model:
        onnx.checker.check_model(olive_model.model_path)

    return olive_model
Save the ONNX model to the specified path and return the ONNXModelHandler.

    :param model_proto: The ONNX model to save.
    :param output_model_path: The path to save the ONNX model to.
    :param external_data_config: The external data configuration. Must be a dictionary with keys
        "save_as_external_data", "all_tensors_to_one_file", and "external_data_name".
    :param check_model: If True, run onnx.checker.check_model on the model before returning.
    :param external_initializers_file_name: The name of the external initializers file.
    :param constant_inputs_file_name: The name of the constant inputs file.
    :param force_model_dir: If True, use the parent directory of the output model path as the model directory
        regardless of whether external data is used.

    :return: The ONNXModelHandler.
    
olive/passes/onnx/common.py