<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/data/experimental/ops/distributed_save_op.py#L28-L111) |

Initiates the process of saving a dataset to disk using tf.data service.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.data.experimental.distributed_save`](https://www.tensorflow.org/api_docs/python/tf/data/experimental/distributed_save)

<br />

    tf.data.experimental.distributed_save(
        dataset: https://www.tensorflow.org/api_docs/python/tf/data/Dataset,
        path: str,
        data_service_address: str,
        compression: str = 'AUTO'
    ) -> Optional[ops.OperationType]

The op uses tf.data service
(<https://www.tensorflow.org/api_docs/python/tf/data/experimental/service>) to
write a dataset snapshot. Returns immediately after submitting the request.
Does not wait for the snapshot to be finished. Requires that the tf.data
service run a fixed number of worker replicas.

To load the snapshot, users may optionally pass `wait=True` to
[`tf.data.Dataset.load`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#load) so it can read snapshots as they are being written.

#### Example usage:

    import os
    import tempfile

    # Runs tf.data service.
    tempdir = tempfile.gettempdir()
    dispatcher = tf.data.experimental.service.DispatchServer(
        tf.data.experimental.service.DispatcherConfig(
            fault_tolerant_mode=True,
            work_dir=os.path.join(tempdir, "work_dir")))
    dispatcher_address = dispatcher.target.split("://")[1]
    worker = tf.data.experimental.service.WorkerServer(
        tf.data.experimental.service.WorkerConfig(
            dispatcher_address=dispatcher_address))

    # Writes dataset snapshot.
    path = os.path.join(tempdir, "dataset_snapshot")
    dataset = tf.data.Dataset.range(1)
    tf.data.experimental.distributed_save(dataset, path, dispatcher_address)

    # Loads a dataset snapshot.
    loaded_dataset = tf.data.Dataset.load(path, wait=True)
    for elem in loaded_dataset:
      print(elem)
    tf.Tensor(0, shape=(), dtype=int64)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `dataset` | The [`tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) to save. |
| `path` | The directory path to save the dataset. Requires that: <br /> - The directory does not exist and will create the directory. - The file system supports atomic move (rename). |
| `data_service_address` | tf.data service dispatcher address. |
| `compression` | (Optional.) Whether and how to compress the `dataset` snapshot. If `"AUTO"`, the tf.data runtime decides which algorithm to use. If `"GZIP"` or `"SNAPPY"`, that specific algorithm is used. If `None`, the `dataset` snapshot is not compressed. |

<br />

<br />

<br />

| ## Returns ||
|---|---|
| An operation which when executed performs the distributed save. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `dispatcher_address` is invalid. |
| [`tf.errors.AlreadyExistsError`](https://www.tensorflow.org/api_docs/python/tf/errors/AlreadyExistsError) | If the snapshot has already started or has finished. |
| [`tf.errors.FailedPreconditionError`](https://www.tensorflow.org/api_docs/python/tf/errors/FailedPreconditionError) | If the file system does not support atomic move (rename). |
| [`tf.errors.InvalidArgumentError`](https://www.tensorflow.org/api_docs/python/tf/errors/InvalidArgumentError) | If tf.data service is not running in the fault tolerant mode. |

<br />