MixingPartitioner#
Mixing dataset partitioning: interpolate between any two partitioners.
- class krum.primitives.data_partitioners.mixing.MixingPartitioner[source]#
Bases:
DataPartitionerMixing partitioner: interpolates between any two partitioners by a ratio.
Shuffles the dataset, splits it into a \((1 - \gamma)\) fraction and a \(\gamma\) fraction, partitions each fraction independently with
p1andp2respectively (both across the same \(n\) workers), then gives worker \(w\) the concatenation of itsp1-slice and itsp2-slice.\(\gamma = 0\) recovers
p1alone; \(\gamma = 1\) recoversp2alone. This generalizes the “gamma-similarity” scheme of Karimireddy, Kale, Mohri, Reddi, Stich & Suresh (ICML 2020, SCAFFOLD, Section 7.1) — there,p1is always an IID split andp2is always a sort-by-label split — to any pair of partitioners.Since the initial split accounts for every sample exactly once, and worker \(w\)’s dataset is the concatenation of its (disjoint) slice of each half, no sample is ever assigned to two workers. Whether a sample can be dropped depends on
p1/p2themselves: mixing inIidPartitioner(which drops a remainder within its own slice) can still drop samples, whileDirichletPartitionernever does.- classmethod partition(dataset: Dataset[Any], /, *, n: int, p1: type[DataPartitioner], p2: type[DataPartitioner], gamma: float, p1_kwargs: dict[str, Any] | None = None, p2_kwargs: dict[str, Any] | None = None, seed: int = 42, **specialized: Any) list[ConcatDataset[Any]][source]#
Split
datasetacrossnworkers by mixingp1andp2.- Parameters:
dataset – Full dataset to partition across workers.
n – Number of workers to split the dataset across.
p1 – Partitioner applied to the \((1 - \gamma)\) fraction of the shuffled dataset.
p2 – Partitioner applied to the \(\gamma\) fraction.
gamma – Mixing ratio in
[0, 1]— the fraction of the dataset routed top2instead ofp1.p1_kwargs – Extra keyword arguments forwarded to
p1.partition(e.g.{"alpha": 0.5}whenp1isDirichletPartitioner).p2_kwargs – Extra keyword arguments forwarded to
p2.partition.seed – Random seed for the initial shuffle, forwarded unchanged to both
p1.partitionandp2.partition.**specialized – Additional keyword arguments (unused).
- Returns:
List of ``n`` datasets, one per worker, each the concatenation
of that worker’s ``p1``-slice and ``p2``-slice.
- Raises:
ValueError – If
n < 1orgammais not in[0, 1].TypeError – If
p1orp2is not aDataPartitionersubclass.
See also
For an equal-size shard strategy, see IidPartitioner. For a shard-granularity label-skew strategy, see PerLabelsPartitioner.