omniloader.config¶
Configuration and reproducibility helpers.
OmniConfig bundles the knobs a training run needs — seed, batch size,
worker count, the mixing strategy and the normalization/augmentation pipeline —
and loads from a dict, a JSON file or a YAML file so experiments stay
declarative. seed_everything() seeds Python, NumPy and PyTorch in one call.
Attributes¶
Classes¶
Declarative configuration for an OmniLoader training run. |
Functions¶
|
Seed Python, NumPy and PyTorch RNGs for reproducibility. |
Module Contents¶
- omniloader.config.STRATEGIES: dict[str, type[omniloader.sampling.strategies.MixingStrategy]]¶
- omniloader.config.COLLATES: tuple[str, ...] = ('unified', 'dynamic', 'mixup')¶
- omniloader.config.seed_everything(seed: int) int[source]¶
Seed Python, NumPy and PyTorch RNGs for reproducibility.
- Parameters:
seed – The seed value.
- Returns:
The seed, for convenience.
- class omniloader.config.OmniConfig[source]¶
Declarative configuration for an OmniLoader training run.
- Parameters:
seed – Global RNG seed.
batch_size – Batch size for the
DataLoader.num_workers – Number of worker processes for the
DataLoader.pad_features – Whether the unifier pads/crops sequence values.
strategy – Name of the mixing strategy (a key of
STRATEGIES).strategy_kwargs – Extra keyword arguments forwarded to the strategy (e.g.
temperature,weights,samples_per_dataset).transforms – Ordered list of transform config dicts (each with a
namekey) applied during training. Stats-based normalizers may reference a saved stats file viastats_path(orunion_stats_path) instead of inliningstats. Seebuild_transform().eval_transforms – Transforms applied during evaluation. When
None, only the non-augmenting (train-agnostic) transforms intransforms, such asnormalize, take effect.datasets – Declarative dataset entries (adapter + args + schema) built by
build_datasets(). Seeomniloader.data.factory.subsample – Optional per-dataset subsampling entries (one per dataset, or
Noneto skip a dataset), each a dict forSubsampleConfig. Built bybuild_subsample()and fed tobuild_strategy().collate – Collate function name — one of
COLLATES("unified","dynamic"or"mixup"). Seebuild_collate()."dynamic"only reduces padding withpad_featuresset toFalse(under a fixedtime_dimit behaves like"unified").collate_kwargs – Extra keyword arguments for the collator. For
"dynamic"an optionalkeyslist; for"mixup"abasecollate name plusalpha/mode/p.bucketing – Optional length-bucketing entry with a
key(sequence name to bucket by) and optionalbatch_size/bucket_multiplier/drop_last/shuffle. When set,build_dataloader()batches withLengthBucketBatchSampler. Only meaningful withpad_features=False(a no-op under a fixedtime_dim).num_replicas – Distributed replica count for the sampler.
Noneinfers it fromtorch.distributed.rank – This process’s distributed rank.
Noneinfers it.drop_last – Drop the uneven tail when sharding across replicas.
pin_memory – Copy tensors into pinned memory before returning them (faster host-to-GPU transfer). Forwarded to the
DataLoader.persistent_workers – Keep worker processes alive between epochs. Only takes effect when
num_workers> 0.prefetch_factor – Batches prefetched per worker. Only applied when
num_workers> 0;Noneuses the PyTorch default.
- classmethod from_dict(data: dict[str, Any]) OmniConfig[source]¶
Build a config from a plain dict, ignoring unknown keys.
- Parameters:
data – Mapping of field names to values.
- Returns:
The populated config.
- classmethod from_yaml(path: str | pathlib.Path) OmniConfig[source]¶
Load a config from a YAML file.
- classmethod from_json(path: str | pathlib.Path) OmniConfig[source]¶
Load a config from a JSON file.
- classmethod from_file(path: str | pathlib.Path) OmniConfig[source]¶
Load a config from a
.json,.yamlor.ymlfile by extension.- Parameters:
path – Path to a config file.
- Returns:
The populated config.
- Raises:
ValueError – If the file extension is not recognised.
- build_strategy(sizes: collections.abc.Sequence[int], subsample: collections.abc.Sequence[omniloader.sampling.strategies.SubsampleConfig | None] | None = None) omniloader.sampling.strategies.MixingStrategy[source]¶
Instantiate the configured mixing strategy for the given sizes.
- Parameters:
sizes – Per-dataset sample counts.
subsample – Optional per-dataset subsample configs.
- Returns:
The configured
MixingStrategy.- Raises:
ValueError – If
strategyis not a known strategy name.
- build_transform(schema: omniloader.schema.spec.UnifiedSchema, training: bool = True) omniloader.transforms.Compose | None[source]¶
Build the transform pipeline for a split.
- Parameters:
schema – The unified schema, injected into schema-aware transforms.
training – When
True, usestransforms; otherwise useseval_transformsif set, elsetransforms(whose augmentations self-skip in eval mode).
- Returns:
A
Compose, orNoneif empty.
- build_datasets() tuple[list[omniloader.loader.SizedDataset], list[omniloader.schema.spec.DatasetSchema]][source]¶
Construct the datasets/schemas declared in
datasets.- Returns:
A
(datasets, schemas)tuple. Seeomniloader.data.factory.build_datasets().
- build_subsample() list[omniloader.sampling.strategies.SubsampleConfig | None] | None[source]¶
Build the per-dataset
SubsampleConfiglist fromsubsample.- Returns:
One
SubsampleConfig(orNone) per dataset, orNonewhensubsampleis unset.
- build_collate(schema: omniloader.schema.spec.UnifiedSchema, training: bool = True) collections.abc.Callable[[collections.abc.Sequence[dict[str, Any]]], dict[str, Any]][source]¶
Build the collate function named by
collate.- Parameters:
schema – The unified schema, injected into schema-aware collators.
training – When
False, the batch-level"mixup"augmentation is disabled and itsbasecollator is used instead.
- Returns:
A callable turning a list of samples into a batched dict.
- Raises:
ValueError – If
collate(or amixupbase) is unknown.
- build_loader(datasets: collections.abc.Sequence[omniloader.loader.SizedDataset] | None = None, schemas: collections.abc.Sequence[omniloader.schema.spec.DatasetSchema] | None = None, training: bool = True) omniloader.loader.OmniLoader[source]¶
Build a fully configured
OmniLoader.- Parameters:
datasets – Source datasets. When
None, they are built fromdatasetsviabuild_datasets().schemas – Per-dataset schemas. Required when
datasetsis given; ignored (rebuilt) whendatasetsisNone.training – Whether augmentations are active (
Falsefor val/test).
- Returns:
The loader with its transform pipeline wired in.
- Raises:
ValueError – If
datasetsis given withoutschemas.
- build_dataloader(datasets: collections.abc.Sequence[omniloader.loader.SizedDataset] | None = None, schemas: collections.abc.Sequence[omniloader.schema.spec.DatasetSchema] | None = None, training: bool = True, epoch: int = 0) torch.utils.data.DataLoader[source]¶
Assemble a ready-to-iterate
DataLoaderentirely from this config.Wires together the loader, mixing strategy, distributed sampler, collate function and (optionally) length bucketing. Training loaders draw indices through the configured
MixingStrategy; evaluation loaders (training=False) iterate sequentially for a stable, full-coverage pass.- Parameters:
datasets – Source datasets, or
Noneto build them fromdatasets.schemas – Per-dataset schemas (required with
datasets).training – Whether this is the training split.
epoch – Initial epoch for the sampler and per-sample augmentation.
- Returns:
A configured
torch.utils.data.DataLoader.