class_docstr: Tests for distributed save/load with the new load algorithm.
class_docstr_tok: ["Tests","for","distributed","save\/load","with","the","new","load","algorithm","."]
code: def test_save_before_sample(self, num_workers: int):
      num_elements = 10
      num_datasets = 3
      cluster = data_service_test_base.TestCluster(
          num_workers=num_workers
      )
      snapshot_dir = data_service_test_base.TempDir()
      datasets = [
          dataset_ops.Dataset.range(num_elements)
          for i in range(num_datasets)
      ]
      for i, dataset in enumerate(datasets):
          self.evaluate(
              distributed_save_op.distributed_save(
                  dataset,
                  os.path.join(snapshot_dir.full_path, f"dataset_{i}"),
                  cluster.dispatcher_address(),
              )
          )
  
      loaded_datasets = []
      for i in range(len(datasets)):
          snapshot_path = os.path.join(
              snapshot_dir.full_path, f"dataset_{i}"
          )
          loaded_datasets.append(
              load_op._load_with_retry(snapshot_path)
          )
      dataset = dataset_ops.Dataset.sample_from_datasets(
          loaded_datasets,
          weights=[1.0] * num_datasets,
          stop_on_empty_dataset=False,
      )
      self.assertDatasetProduces(
          dataset,
          list(range(num_elements)) * num_datasets,
          assert_items_equal=True,
      )
  
imports: import multiprocessing
  import os
  import threading
  import time
  from typing import Callable, Optional
  from absl.testing import parameterized
  import numpy
  from tensorflow.python.data.experimental.kernel_tests.service import test_base
  from tensorflow.python.data.experimental.ops import data_service_ops
  from tensorflow.python.data.experimental.ops import distributed_save_op
  from tensorflow.python.data.kernel_tests import checkpoint_test_base
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.ops import load_op
  from tensorflow.python.framework import combinations
  from tensorflow.python.framework import errors
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import math_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 6 for calling the DistributedSaveLoadTest obj's underlying member method code with example usage: obj.test_save_before_sample(num_workers) without return types