code: def save_model(
      proto: ModelProto | bytes,
      f: IO[bytes] | str | os.PathLike,
      format: _SupportedFormat | None = None,  # noqa: A002
      *,
      save_as_external_data: bool = False,
      all_tensors_to_one_file: bool = True,
      location: str | None = None,
      size_threshold: int = 1024,
      convert_attribute: bool = False,
  ) -> None:
      """Saves the ModelProto to the specified path and optionally, serialize tensors with raw data as external data before saving.
  
      Args:
          proto: should be a in-memory ModelProto
          f: can be a file-like object (has "write" function) or a string containing
          a file name or a pathlike object
          format: The serialization format. When it is not specified, it is inferred
              from the file extension when ``f`` is a path. If not specified _and_
              ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
              be "utf-8" when the format is a text format.
          save_as_external_data: If true, save tensors to external file(s).
          all_tensors_to_one_file: Effective only if save_as_external_data is True.
              If true, save all tensors to one external file specified by location.
              If false, save each tensor to a file named with the tensor name.
          location: Effective only if save_as_external_data is true.
              Specify the external file that all tensors to save to.
              Path is relative to the model path.
              If not specified, will use the model name.
          size_threshold: Effective only if save_as_external_data is True.
              Threshold for size of data. Only when tensor's data is >= the size_threshold it will be converted
              to external data. To convert every tensor with raw data to external data set size_threshold=0.
          convert_attribute: Effective only if save_as_external_data is True.
              If true, convert all tensors to external data
              If false, convert only non-attribute tensors to external data
      """
      if isinstance(proto, bytes):
          proto = _get_serializer(_DEFAULT_FORMAT).deserialize_proto(
              proto, ModelProto()
          )
  
      if save_as_external_data:
          convert_model_to_external_data(
              proto,
              all_tensors_to_one_file,
              location,
              size_threshold,
              convert_attribute,
          )
  
      model_filepath = _get_file_path(f)
      if model_filepath is not None:
          basepath = os.path.dirname(model_filepath)
          proto = write_external_data_tensors(proto, basepath)
  
      serialized = _get_serializer(
          format, model_filepath
      ).serialize_proto(proto)
      _save_bytes(serialized, f)
  
imports: from __future__ import annotations
  import os
  import typing
  from typing import IO, Literal, Union
  from onnx import serialization
  from onnx.onnx_cpp2py_export import ONNX_ML
  from onnx.external_data_helper import load_external_data_for_model, write_external_data_tensors, convert_model_to_external_data
  from onnx.onnx_pb import AttributeProto, EXPERIMENTAL, FunctionProto, GraphProto, IR_VERSION, IR_VERSION_2017_10_10, IR_VERSION_2017_10_30, IR_VERSION_2017_11_3, IR_VERSION_2019_1_22, IR_VERSION_2019_3_18, IR_VERSION_2019_9_19, IR_VERSION_2020_5_8, IR_VERSION_2021_7_30, ModelProto, NodeProto, OperatorSetIdProto, OperatorStatus, STABLE, SparseTensorProto, StringStringEntryProto, TensorAnnotation, TensorProto, TensorShapeProto, TrainingInfoProto, TypeProto, ValueInfoProto, Version
  from onnx.onnx_operators_pb import OperatorProto, OperatorSetProto
  from onnx.onnx_data_pb import MapProto, OptionalProto, SequenceProto
  from onnx.version import version
  from onnx import checker, compose, defs, gen_proto, helper, hub, mapping, numpy_helper, parser, printer, shape_inference, utils, version_converter
label_desc: Use image node_id 9 for calling a global function with example usage: save_model(proto, f, format) without return types