Data partitioners#
Dataset-to-worker partitioning strategies for simulations.
A DataPartitioner turns one
dataset into n per-worker Dataset
instances. Both
CentralisedSimulation and
DecentralisedSimulation consume
this same shape, so partitioning is entirely the caller’s responsibility,
IID or not. Wrapping each worker’s dataset into a
DataLoader (batch size, shuffling) is the
simulation’s job, not the partitioner’s — that separation is what lets
partitioners compose (e.g. mixing two partitioners’ outputs) without
reaching back into a DataLoader to get at the underlying samples.
Like aggregators and attacks,
each strategy is stateless: a @classmethod invoked directly on the
class. The dataset is the sole positional argument; n, seed, and any
partitioner-specific hyperparameters are keyword-only.
Available partitioners#
Base class#
- class krum.primitives.data_partitioners.DataPartitioner[source]#
Bases:
ABCAbstract base class for stateless dataset-to-worker partitioners.
Subclasses implement
partition()as a@classmethod— no instance state is required, and the caller invokes the strategy directly on the class. The dataset is the sole positional argument;n,seed, and any partitioner-specific hyperparameters are keyword-only.- abstract classmethod partition(dataset: Dataset[Any], /, *, n: int, seed: int = 42, **specialized: Any) Sequence[Dataset[Any]][source]#
Split
datasetintonper-worker datasets.- Parameters:
dataset – Full dataset to partition across workers.
n – Number of workers to split the dataset across.
seed – Random seed for reproducibility.
**specialized – Keyword-only arguments specific to each partitioning strategy (e.g. \(\alpha\) for label skew).
- Returns:
Sequence of ``n`` datasets, one per worker.
- Raises:
NotImplementedError – If the subclass does not implement this method.