class_docstr: Builds the `SavedModel` protocol buffer and saves variables and assets.
  
  The `SavedModelBuilder` class provides the functionality to build a
  `SavedModel` protocol buffer. Specifically, this allows multiple meta
  graphs to be saved as part of a single language-neutral `SavedModel`,
  while sharing variables and assets.
  
  To build a SavedModel, the first meta graph must be saved with variables.
  Subsequent meta graphs will simply be saved with their graph definitions. If
  assets need to be saved and written or copied to disk, they can be provided
  when the meta graph def is added. If multiple meta graph defs are associated
  an asset of the same name, only the first version is retained.
  
  Each meta graph added to the SavedModel must be annotated with tags. The tags
  provide a means to identify the specific meta graph to load and restore, along
  with the shared set of variables and assets.
  
  Typical usage for the `SavedModelBuilder`:
  
  ```python
  ...
  builder = tf.compat.v1.saved_model.Builder(export_dir)
  
  with tf.compat.v1.Session(graph=tf.Graph()) as sess:
    ...
    builder.add_meta_graph_and_variables(sess,
                                    ["foo-tag"],
                                    signature_def_map=foo_signatures,
                                    assets_list=foo_assets)
  ...
  
  with tf.compat.v1.Session(graph=tf.Graph()) as sess:
    ...
    builder.add_meta_graph(["bar-tag", "baz-tag"])
  ...
  
  builder.save()
  ```
  
  Note: This function will only be available through the v1 compatibility
  library as tf.compat.v1.saved_model.builder.SavedModelBuilder or
  tf.compat.v1.saved_model.Builder. Tensorflow 2.0 will introduce a new
  object-based method of creating SavedModels.
class_docstr_tok: ["Builds","the","`","SavedModel","`","protocol","buffer","and","saves","variables","and","assets",".","The","`","SavedModelBuilder","`","class","provides","the","functionality","to","build","a","`","SavedModel","`","protocol","buffer",".","Specifically",",","this","allows","multiple","meta","graphs","to","be","saved","as","part","of","a","single","language-neutral","`","SavedModel","`",",","while","sharing","variables","and","assets",".","To","build","a","SavedModel",",","the","first","meta","graph","must","be","saved","with","variables",".","Subsequent","meta","graphs","will","simply","be","saved","with","their","graph","definitions",".","If","assets","need","to","be","saved","and","written","or","copied","to","disk",",","they","can","be","provided","when","the","meta","graph","def","is","added",".","If","multiple","meta","graph","defs","are","associated","an","asset","of","the","same","name",",","only","the","first","version","is","retained",".","Each","meta","graph","added","to","the","SavedModel","must","be","annotated","with","tags",".","The","tags","provide","a","means","to","identify","the","specific","meta","graph","to","load","and","restore",",","along","with","the","shared","set","of","variables","and","assets",".","Typical","usage","for","the","`","SavedModelBuilder","`",":","``","`","python","...","builder","=","tf.compat.v1.saved_model.Builder","(","export_dir",")","with","tf.compat.v1.Session","(","graph=tf.Graph","(",")",")","as","sess",":","...","builder.add_meta_graph_and_variables","(","sess",",","[","``","foo-tag","''","]",",","signature_def_map=foo_signatures",",","assets_list=foo_assets",")","...","with","tf.compat.v1.Session","(","graph=tf.Graph","(",")",")","as","sess",":","...","builder.add_meta_graph","(","[","``","bar-tag","''",",","``","baz-tag","''","]",")","...","builder.save","(",")","``","`","Note",":","This","function","will","only","be","available","through","the","v1","compatibility","library","as","tf.compat.v1.saved_model.builder.SavedModelBuilder","or","tf.compat.v1.saved_model.Builder",".","Tensorflow","2.0","will","introduce","a","new","object-based","method","of","creating","SavedModels","."]
docstr: Writes a `SavedModel` protocol buffer to disk.
  
  The function writes the SavedModel protocol buffer to the export directory
  in a serialized format.
  
  Args:
    as_text: Writes the SavedModel protocol buffer in text format to disk.
      Protocol buffers in text format are useful for debugging, but parsing
      fails when it encounters an unknown field and so is not forward
      compatible. This means changes to TensorFlow may prevent deployment of
      new text format SavedModels to existing serving binaries. Do not deploy
      `as_text` SavedModels to production.
    experimental_image_format: Writes the SavedModel protobuf in the
      experimental image format. See
    https://www.tensorflow.org/api_docs/python/tf/saved_model/SaveOptions for
      more details. This allows `SavedModelBuilder` to save models larger than
      2 GiB.
  
  Raises:
     RuntimeError: When trying to use `proto_splitter` but `proto_splitter` is
       not imported. This check is here because `proto_splitter` is not 
       available in OSS at the moment. 
  
  Returns:
    The path to which the SavedModel protocol buffer was written.
docstr_tok: ["Writes","a","`","SavedModel","`","protocol","buffer","to","disk",".","The","function","writes","the","SavedModel","protocol","buffer","to","the","export","directory","in","a","serialized","format",".","Args",":","as_text",":","Writes","the","SavedModel","protocol","buffer","in","text","format","to","disk",".","Protocol","buffers","in","text","format","are","useful","for","debugging",",","but","parsing","fails","when","it","encounters","an","unknown","field","and","so","is","not","forward","compatible",".","This","means","changes","to","TensorFlow","may","prevent","deployment","of","new","text","format","SavedModels","to","existing","serving","binaries",".","Do","not","deploy","`","as_text","`","SavedModels","to","production",".","experimental_image_format",":","Writes","the","SavedModel","protobuf","in","the","experimental","image","format",".","See","https",":","\/\/www.tensorflow.org\/api_docs\/python\/tf\/saved_model\/SaveOptions","for","more","details",".","This","allows","`","SavedModelBuilder","`","to","save","models","larger","than","2","GiB",".","Raises",":","RuntimeError",":","When","trying","to","use","`","proto_splitter","`","but","`","proto_splitter","`","is","not","imported",".","This","check","is","here","because","`","proto_splitter","`","is","not","available","in","OSS","at","the","moment",".","Returns",":","The","path","to","which","the","SavedModel","protocol","buffer","was","written","."]
code: def save(self, as_text=False, experimental_image_format=False):
      """Writes a `SavedModel` protocol buffer to disk.
  
      The function writes the SavedModel protocol buffer to the export directory
      in a serialized format.
  
      Args:
        as_text: Writes the SavedModel protocol buffer in text format to disk.
          Protocol buffers in text format are useful for debugging, but parsing
          fails when it encounters an unknown field and so is not forward
          compatible. This means changes to TensorFlow may prevent deployment of
          new text format SavedModels to existing serving binaries. Do not deploy
          `as_text` SavedModels to production.
        experimental_image_format: Writes the SavedModel protobuf in the
          experimental image format. See
        https://www.tensorflow.org/api_docs/python/tf/saved_model/SaveOptions for
          more details. This allows `SavedModelBuilder` to save models larger than
          2 GiB.
  
      Raises:
         RuntimeError: When trying to use `proto_splitter` but `proto_splitter` is
           not imported. This check is here because `proto_splitter` is not
           available in OSS at the moment.
  
      Returns:
        The path to which the SavedModel protocol buffer was written.
      """
      metrics.IncrementWriteApi(_SAVE_BUILDER_LABEL)
      if not file_io.file_exists(self._export_dir):
          file_io.recursive_create_dir(self._export_dir)
  
      if as_text:
          path = file_io.join(
              compat.as_bytes(self._export_dir),
              compat.as_bytes(constants.SAVED_MODEL_FILENAME_PBTXT),
          )
          file_io.write_string_to_file(path, str(self._saved_model))
      else:
          if experimental_image_format:
              path = file_io.join(
                  self._export_dir,
                  constants.SAVED_MODEL_FILENAME_PREFIX,
              )
              if (
                  locals().get(
                      "proto_splitter", globals().get("proto_splitter")
                  )
                  is None
              ):
                  raise RuntimeError(
                      "No proto_splitter is provided, cannot use"
                      " experimental_image_format."
                  )
              # Overwrites path to record whether the saved_model is split, i.e.,
              # whether the suffix is `.pb` or `.cpb`.
              path = proto_splitter.SavedModelSplitter(
                  self._saved_model
              ).write(path)
          else:
              path = file_io.join(
                  compat.as_bytes(self._export_dir),
                  compat.as_bytes(constants.SAVED_MODEL_FILENAME_PB),
              )
              file_io.write_string_to_file(
                  path,
                  self._saved_model.SerializeToString(
                      deterministic=True
                  ),
              )
          # Placeholder for internal TF1 model fingerprint write
      tf_logging.info("SavedModel written to: %s", compat.as_text(path))
      metrics.IncrementWrite(write_version="1")
  
      return path
  
imports: import functools
  import os
  from google.protobuf.any_pb2 import Any
  from tensorflow.core.framework import types_pb2
  from tensorflow.core.protobuf import meta_graph_pb2
  from tensorflow.core.protobuf import saved_model_pb2
  from tensorflow.core.protobuf import saver_pb2
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.lib.io import file_io
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.saved_model import fingerprinting_utils
  from tensorflow.python.saved_model import path_helpers
  from tensorflow.python.saved_model import signature_def_utils
  from tensorflow.python.saved_model.pywrap_saved_model import constants
  from tensorflow.python.saved_model.pywrap_saved_model import metrics
  from tensorflow.python.training import saver
  from tensorflow.python.util import compat
  from tensorflow.python.util.deprecation import deprecated_args
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 9 for calling the _SavedModelBuilder obj's underlying member method code with example usage: obj.save(as_text, experimental_image_format) and returns: path