DefaultSampler — mmengine 0.10.7 documentation (original) (raw)

class mmengine.dataset.DefaultSampler(dataset, shuffle=True, seed=None, round_up=True)[source]

The default data sampler for both distributed and non-distributed environment.

It has several differences from the PyTorch DistributedSampler as below:

  1. This sampler supports non-distributed environment.
  2. The round up behaviors are a little different.
    • If round_up=True, this sampler will add extra samples to make the number of samples is evenly divisible by the world size. And this behavior is the same as the DistributedSampler withdrop_last=False.
    • If round_up=False, this sampler won’t remove or add any samples while the DistributedSampler with drop_last=True will remove tail samples.

Parameters:

set_epoch(epoch)[source]

Sets the epoch for this sampler.

When shuffle=True, this ensures all replicas use a different random ordering for each epoch. Otherwise, the next iteration of this sampler will yield the same ordering.

Parameters:

epoch (int) – Epoch number.

Return type:

None