IidPartitioner#

IID dataset partitioning: shuffle, then split into equal-size shards.

class krum.primitives.data_partitioners.iid.IidPartitioner[source]#

Bases: DataPartitioner

IID partitioner: shuffle the dataset, then split into n equal shards.

The dataset is shuffled and cut into n equal-size, disjoint, uniformly random shards, one per worker. Any remainder (len(dataset) % n samples) is dropped.

classmethod partition(dataset: Dataset[Any], /, *, n: int, seed: int = 42, **specialized: Any) list[Subset[Any]][source]#

Shuffle dataset and split it into n equal-size shards.

Parameters:
  • dataset – Full dataset to partition across workers.

  • n – Number of workers to split the dataset across.

  • seed – Random seed for the shard permutation.

  • **specialized – Additional keyword arguments (unused).

Returns:
  • List of ``n`` datasets, each an equal-size, disjoint, uniformly

  • random shard.

Raises:

ValueError – If n < 1, or dataset is nonempty but has fewer than n samples.

See also

For a per-class label-skew strategy, see DirichletPartitioner. For a shard-granularity interpolation from IID, see PerLabelsPartitioner.