code: def save_spec(spec, filename, auto_set_specification_version=False):
      """
      Save a protobuf model specification to file.
  
      Parameters
      ----------
      spec: Model_pb
          Protobuf representation of the model
  
      filename: str
          File path  where the spec gets saved.
  
      auto_set_specification_version: bool
          If true, will always try to set specification version automatically.
  
      Examples
      --------
      .. sourcecode:: python
  
          >>> coremltools.utils.save_spec(spec, 'HousePricer.mlmodel')
  
      See Also
      --------
      load_spec
      """
      name, ext = _os.path.splitext(filename)
      if not ext:
          filename = "{}.mlmodel".format(filename)
      else:
          if ext != ".mlmodel":
              raise Exception(
                  "Extension must be .mlmodel (not {})".format(ext)
              )
  
      spec = spec.SerializeToString()
      if auto_set_specification_version:
          try:
              # always try to downgrade the specification version to the
              # minimal version that supports everything in this mlmodel
              from ..libcoremlpython import _MLModelProxy
  
              spec = _MLModelProxy.auto_set_specification_version(spec)
          except Exception as e:
              print(e)
              _warnings.warn(
                  "Failed to automatic set specification version for this model.",
                  RuntimeWarning,
              )
  
      with open(filename, "wb") as f:
          f.write(spec)
  
imports: import math
  import numpy
  import os
  import six
  import warnings
  import sys
  from coremltools.proto import Model_pb2
  from coremltools.models._deprecation import deprecated
  from .._deps import _HAS_SKLEARN
label_desc: Use image node_id 2 for calling a global function with example usage: save_spec(spec, filename, auto_set_specification_version) without return types