spdl.dataloader.CacheDataLoader

class CacheDataLoader(dl: Iterable[T], num_caches: int, return_caches_after: int, stop_after: int | None = None)[source]

Caches values from the given data loader and returns caches after the given iteration.

The class is a simple wrapper around generic data loader instance. It is intended for estimating the maximum performance gain achieved by optimizing the data loader.

You can wrap your data loader with this class, and run it in the training pipeline, and compare the performance to see if the training pipeline is bottlenecked with data loading.

Parameters:
Returns:

The new iterator.

See also

__iter__() Iterator[T][source]

See spdl.pipeline.cache_iterator() for the detail.

__len__() int[source]

Returns the length of the original data loader if defined.