class
SequentialSampler
extends
SamplerSequentialSampler(data_source: Dataset)Yield indices in fixed order 0, 1, ..., len(data_source) - 1.
The default sampler used when shuffle=False and no explicit
sampler is supplied to DataLoader.
Parameters
data_sourceDatasetDataset whose
__len__ determines the index range.Notes
Order is fully deterministic — no RNG is consulted — so two passes over the sampler always yield the same index sequence. This is the right choice for evaluation / inference loops where ordering must line up with external bookkeeping (e.g. per-row metric arrays).
Examples
>>> sampler = SequentialSampler(my_dataset)
>>> list(sampler)[:5]
[0, 1, 2, 3, 4]Methods (3)
dunder
__init__
→None__init__(data_source: Dataset)Store data_source for length introspection.
Parameters
data_sourceDatasetDataset to be iterated sequentially.
dunder
__iter__
→Iterator[int]__iter__()Yield 0, 1, ..., len(data_source) - 1 in order.
dunder
__len__
→int__len__()Return len(data_source).