Shortcuts

Template Struct OrderedSequencer

Inheritance Relationships

Base Type

Struct Documentation

template<typename Result>
struct torch::data::detail::sequencers::OrderedSequencer : public torch::data::detail::sequencers::Sequencer<Result>

A Sequencer that buffers results and returns them in order of their sequence number.

The OrderedSequencer maintains an internal, monotonically incrementing counter for the next sequence number it expects. If it receives a result with a higher sequence number, it will buffer it for later (when the sequence number reaches that of this result). Otherwise, if the sequence numbers match, the result is returned.

Implementation note: The OrderedSequencer is implemented with a fixed-size buffer. Let m be the maximum number of jobs in the data loader’s queue and s be the current sequence number. Assume m jobs are scheduled in the DataLoader. Any new result is stored at index job.sqn mod m in the OrderedSequencer. Why are we sure sequence numbers of new jobs will not collide with sequence numbers of buffered jobs? The OrderedSequencer will not return from next() until it receives the result with sqn s. This means no new jobs can be scheduled in the DataLoader in the meantime, which enforces that as long as sqn s has not been received, s + m (which would cause a collision in the fixed-size buffer) will not yet be scheduled.

Public Functions

OrderedSequencer(size_t max_jobs)

Constructs the OrderedSequencer with the maximum number of results it will ever hold at one point in time.

optional<Result> next(ResultProducer next_result) override

Buffers results until the next one in the expected order is received.

optional<Result> &buffer(size_t index)

Accesses the buffer at the index modulo the buffer size.

Public Members

size_t next_sequence_number_ = 0

The monotonically increasing sequence number we expect.

std::vector<optional<Result>> buffer_

A fixed-size buffer (after construction).

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