omniloader.sampling.subsamplers¶
Per-dataset index draws with configurable reuse and exhaustion policies.
An IndexPool produces the local indices to visit within a single
dataset for a given epoch. It captures three orthogonal choices:
replacement — whether a draw may repeat an index within one epoch;
exhaustion policy — for without-replacement draws, whether each epoch is a fresh random subsample (
"fresh") or whether the pool shuffles through the entire dataset before any index is reused across epochs ("exhaust");weights — optional per-index weights for skewed sampling (e.g. class balancing within a dataset).
Draws are fully determined by a base seed and the epoch number, so runs are
reproducible.
Classes¶
How without-replacement draws relate across epochs. |
|
Draw local indices for one dataset, honouring reuse and exhaustion policy. |
Module Contents¶
- class omniloader.sampling.subsamplers.ExhaustionPolicy(*args, **kwds)[source]¶
Bases:
enum.EnumHow without-replacement draws relate across epochs.
- FRESH¶
Every epoch independently samples without replacement from the full dataset; nothing is remembered between epochs.
- EXHAUST¶
Maintain a running shuffled ordering of the whole dataset and consume it across epochs, reshuffling only once every index has been used. This guarantees uniform coverage before any reuse.
- class omniloader.sampling.subsamplers.IndexPool(size: int, replacement: bool = False, policy: ExhaustionPolicy = ExhaustionPolicy.FRESH, seed: int = 0, weights: collections.abc.Sequence[float] | None = None)[source]¶
Draw local indices for one dataset, honouring reuse and exhaustion policy.
- Parameters:
size – Number of samples in the dataset.
replacement – When
True, indices may repeat within an epoch and the exhaustion policy is ignored. Defaults toFalse.policy – The
ExhaustionPolicyfor without-replacement draws.seed – Base seed; combined with the epoch to make draws reproducible.
weights – Optional per-index sampling weights of length
size(e.g. class-balancing weights). When set, draws are weighted viatorch.multinomialand the exhaustion policy is bypassed.
- Raises:
ValueError – If
sizeis not positive orweightshas a bad length.
- draw(count: int, epoch: int) list[int][source]¶
Return
countlocal indices to visit this epoch.- Parameters:
count – Number of indices requested. May exceed
sizewhenreplacementisTrueor under theEXHAUSTpolicy (which wraps across reshuffles).epoch – The epoch number, used to seed the draw.
- Returns:
A list of
countindices in[0, size).