<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/saved_model/save_options.py#L93-L223) |

Options for saving to SavedModel.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.saved_model.SaveOptions`](https://www.tensorflow.org/api_docs/python/tf/saved_model/SaveOptions)

<br />

    tf.saved_model.SaveOptions(
        namespace_whitelist=None,
        save_debug_info=False,
        function_aliases=None,
        experimental_debug_stripper=False,
        experimental_io_device=None,
        experimental_variable_policy=None,
        experimental_custom_gradients=True,
        experimental_image_format=False,
        experimental_skip_saver=False,
        experimental_sharding_callback=None,
        extra_tags=None
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Advanced automatic differentiation](https://www.tensorflow.org/guide/advanced_autodiff) | - [Save and load a model using a distribution strategy](https://www.tensorflow.org/tutorials/distribute/save_and_load) - [Recommending movies: retrieval](https://www.tensorflow.org/recommenders/examples/basic_retrieval) - [Efficient serving](https://www.tensorflow.org/recommenders/examples/efficient_serving) - [Tutorial: Exporting StableHLO from JAX](https://www.tensorflow.org/stablehlo/tutorials/jax-export) - [Setup](https://www.tensorflow.org/lite/examples/jax_conversion/jax_to_tflite_resnet50) |

This function may be used in the `options` argument in functions that
save a SavedModel ([`tf.saved_model.save`](https://www.tensorflow.org/api_docs/python/tf/saved_model/save), [`tf.keras.models.save_model`](https://www.tensorflow.org/api_docs/python/tf/keras/models/save_model)).

<br />

<br />

<br />

| ## Args ||
|---|---|
| `namespace_whitelist` | List of strings containing op namespaces to whitelist when saving a model. Saving an object that uses namespaced ops must explicitly add all namespaces to the whitelist. The namespaced ops must be registered into the framework when loading the SavedModel. If no whitelist is provided, all namespaced ops will be allowed. |
| `save_debug_info` | Boolean indicating whether debug information is saved. If True, then a debug/saved_model_debug_info.pb file will be written with the contents of a GraphDebugInfo binary protocol buffer containing stack trace information for all ops and functions that are saved. |
| `function_aliases` | Python dict. Mapping from string to object returned by @tf.function. A single tf.function can generate many ConcreteFunctions. If a downstream tool wants to refer to all concrete functions generated by a single tf.function you can use the `function_aliases` argument to store a map from the alias name to all concrete function names. E.g. \>\>\> class Adder(tf.Module): ... @tf.function ... def double(self, x): ... return x + x \>\>\> model = Adder() \>\>\> model.double.get_concrete_function( ... tf.TensorSpec(shape=\[\], dtype=tf.float32, name="float_input")) \>\>\> model.double.get_concrete_function( ... tf.TensorSpec(shape=\[\], dtype=tf.string, name="string_input")) \>\>\> options = tf.saved_model.SaveOptions( ... function_aliases={'double': model.double}) \>\>\> tf.saved_model.save(model, '/tmp/adder', options=options) |
| `experimental_debug_stripper` | bool. If set to True, this strips the debug nodes from the graph, from both the nodes and the function defs. Note that this currently only strips the `Assert` nodes from the graph and converts them into `NoOp`s instead. |
| `experimental_io_device` | string. Applies in a distributed setting. Tensorflow device to use to access the filesystem. If `None` (default) then for each variable the filesystem is accessed from the CPU:0 device of the host where that variable is assigned. If specified, the filesystem is instead accessed from that device for all variables. This is for example useful if you want to save to a local directory, such as "/tmp" when running in a distributed setting. In that case pass a device for the host where the "/tmp" directory is accessible. |
| `experimental_variable_policy` | The policy to apply to variables when saving. This is either a [`saved_model.experimental.VariablePolicy`](https://www.tensorflow.org/api_docs/python/tf/saved_model/experimental/VariablePolicy) enum instance or one of its value strings (case is not important). See that enum documentation for details. A value of `None` corresponds to the default policy. |
| `experimental_custom_gradients` | Boolean. When True, will save traced gradient functions for the functions decorated by [`tf.custom_gradient`](https://www.tensorflow.org/api_docs/python/tf/custom_gradient). Defaults to `True`. |
| `experimental_image_format` | New (highly) experimental format that is capable of saving models larger than the 2GB protobuf limit. Enabling this option will likely break compatibility with downstream consumers. This option is currently disabled in OSS. |
| `experimental_skip_saver` | If True, will prevent SavedModel from creating its native checkpointing ops - this is for models that do not use SavedModel's native checkpointing functionality to avoid the costs associated with creating and serializing those ops. |
| `experimental_sharding_callback` | [`tf.train.experimental.ShardingCallback`](https://www.tensorflow.org/api_docs/python/tf/train/experimental/ShardingCallback). A pre-made or custom callback that determines how checkpoints are sharded on disk. Pre-made callback options are `tf.train.experimental.ShardByDevicePolicy` and [`tf.train.experimental.MaxShardSizePolicy`](https://www.tensorflow.org/api_docs/python/tf/train/experimental/MaxShardSizePolicy). You may also write a custom callback, see [`tf.train.experimental.ShardingCallback`](https://www.tensorflow.org/api_docs/python/tf/train/experimental/ShardingCallback). |
| `extra_tags` | Extra tags to be saved with the MetaGraph in the SavedModel. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `experimental_custom_gradients` | <br /> <br /> |
| `experimental_debug_stripper` | <br /> <br /> |
| `experimental_image_format` | <br /> <br /> |
| `experimental_io_device` | <br /> <br /> |
| `experimental_sharding_callback` | <br /> <br /> |
| `experimental_skip_saver` | <br /> <br /> |
| `experimental_variable_policy` | <br /> <br /> |
| `extra_tags` | <br /> <br /> |
| `function_aliases` | <br /> <br /> |
| `namespace_whitelist` | <br /> <br /> |
| `save_debug_info` | <br /> <br /> |

<br />