tf.data.experimental.parallel_interleave

A parallel version of the Dataset.interleave() transformation. (deprecated)

parallel_interleave() maps map_func across its input to produce nested datasets, and outputs their elements interleaved. Unlike tf.data.Dataset.interleave, it gets elements from cycle_length nested datasets in parallel, which increases the throughput, especially in the presence of stragglers. Furthermore, the sloppy argument can be used to improve performance, by relaxing the requirement that the outputs are produced in a deterministic order, and allowing the implementation to skip over nested datasets whose elements are not readily available when requested.

Example usage:

# Preprocess 4 files concurrently.
filenames = tf.data.Dataset.list_files("/path/to/data/train*.tfrecords")
dataset = filenames.apply(
    tf.data.experimental.parallel_interleave(
        lambda filename: tf.data.TFRecordDataset(filename),
        cycle_length=4))

map_funcA function mapping a nested structure of tensors to a Dataset.
cycle_lengthThe number of input Datasets to interleave from in parallel.
block_lengthThe number of consecutive elements to pull from an input Dataset before advancing to the next input Dataset.
sloppyA boolean controlling whether determinism should be traded for performance by allowing elements to be produced out of order. If sloppy is None, the tf.data.Options.deterministic dataset option (True by default) is used to decide whether to enforce a deterministic order.
buffer_output_elementsThe number of elements each iterator being interleaved should buffer (similar to the .prefetch() transformation for each interleaved iterator).
prefetch_input_elementsThe number of input elements to transform to iterators before they are needed for interleaving.

A Dataset transformation function, which can be passed to tf.data.Dataset.apply.