spdl.source.DistributedDeterministicSampler

class DistributedDeterministicSampler(n: int, /, *, rank: int, world_size: int)[source]

Bases: object

Sampler for distributed training that splits indices across multiple ranks.

This sampler ensures that each rank in a distributed training setup gets a disjoint subset of the data indices. When distributed training is not initialized, it returns all indices.

Parameters:
__iter__() Iterator[int][source]

Iterate over the indices assigned to the current rank.

Yields:

Individual indices assigned to the current rank.

__len__() int[source]

The number of indices returned by this sampler.