fedlib.datasets.ShardPartitioner

class fedlib.datasets.ShardPartitioner(num_clients, random_seed=123, client_id_generator=None, num_shards=4)[source]

Bases: DatasetPartitioner

Partitioner that splits a dataset into shards and assigns shards to clients.

split_dataset(dataset)[source]

Split a single dataset into multiple subsets, each keyed by a unique client_id.

Parameters:

dataset (Dataset) – The dataset to be split.

Returns:

A dictionary where the key is a string client_id and the

value is a Subset.

Return type:

Dict[str, Subset]

Return type:

List[Subset]

split_datasets(train_dataset, test_dataset)[source]

Split two keyconcepts (e.g., training and testing keyconcepts) into multiple pairs of subsets, each keyed by a unique client_id.

Parameters:
  • train_dataset (Dataset) – The training dataset to be split.

  • test_dataset (Dataset) – The testing dataset to be split.

Returns:

A dictionary where the key is a string

client_id and the value is a tuple of two Subsets (training and testing).

Return type:

Dict[str, Tuple[Subset, Subset]]

Return type:

tuple[list[Subset], list[Subset]]