sampler#

Module Contents#

SubsetSampler

Samples elements from a given list of indices, always in the same order once initialized.

RawPartitionSampler

Partition dataset according to num_replicas.

DictFileSampler

Get data sample indices given client id from data file with dict.

class SubsetSampler(indices, shuffle=False)#

Bases: torch.utils.data.Sampler

Samples elements from a given list of indices, always in the same order once initialized.

It is a Sampler used in Dataloader, that each partition will be fixed once initialized.

Parameters
  • indices (list[int]) – Indices in the whole set selected for subset

  • shuffle (bool) – shuffle the indices or not.

__iter__(self)#
__len__(self)#
class RawPartitionSampler(dataset, client_id, num_replicas=None)#

Bases: torch.utils.data.Sampler

Partition dataset according to num_replicas.

Every client get a equal shard of dataset.

Parameters
  • dataset (torch.utils.data.Dataset) –

  • client_id (int) –

  • num_replicas (int, optional) – Number of data replications. Default None means total number of client processes.

__iter__(self)#
__len__(self)#
class DictFileSampler(dict_file, client_id)#

Bases: torch.utils.data.Sampler

Get data sample indices given client id from data file with dict.

__iter__(self)#
__len__(self)#