Shortcuts

Class StreamSampler

Inheritance Relationships

Base Type

Class Documentation

class StreamSampler : public torch::data::samplers::Sampler<BatchSize>

A sampler for (potentially infinite) streams of data.

The major feature of the StreamSampler is that it does not return particular indices, but instead only the number of elements to fetch from the dataset. The dataset has to decide how to produce those elements.

Public Functions

explicit StreamSampler(size_t epoch_size)

Constructs the StreamSampler with the number of individual examples that should be fetched until the sampler is exhausted.

virtual void reset(std::optional<size_t> new_size = std::nullopt) override

Resets the internal state of the sampler.

virtual std::optional<BatchSize> next(size_t batch_size) override

Returns a BatchSize object with the number of elements to fetch in the next batch.

This number is the minimum of the supplied batch_size and the difference between the epoch_size and the current index. If the epoch_size has been reached, returns an empty optional.

virtual void save(serialize::OutputArchive &archive) const override

Serializes the StreamSampler to the archive.

virtual void load(serialize::InputArchive &archive) override

Deserializes the StreamSampler from the archive.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources