Providing training pipeline guidance
The user is looking for guidance on making training pipelines reproducible. I think I should structure my recommendations into steps and mention tools like MLflow, DVC, Docker, Conda, and pip-tools. Best practices should include deterministic operations, seed management, tracking code and data versions, and the environment. Including a checklist and sample code snippets for frameworks like PyTorch and TensorFlow is essential. I also need to address data snapshots, seed configuration, environment pinning, and artifact tracking to ensure comprehensive guidance.Creating metadata schema example
I need to provide an example of a metadata schema without being too verbose. It seems crucial to define "reproducible" and distinguish between exact bitwise and statistical levels.
For data, I'll mention snapshotting both raw and processed data, dataset versioning, and checksums, suggesting tools like DVC or lakeFS. I'll include details about seeds, environment pinning, code versioning, and artifact tracking.
The final answer will be concise and may include a bullet list along with sample code to illustrate these concepts.Enhancing reproducibility with logging
I need to add logging for requirements.txt and conda.yaml files to ensure that dependencies are tracked. I'll orchestrate the training process by treating steps as pure functions and running everything in a CI environment. A "repro check" to rerun training and compare metrics is essential.
I’ll also provide an example with the directory structure and a run.json manifest. For PyTorch, I can include a minimal sample demonstrating the seed_everything function, dataloader generator, and set deterministic configurations. I’ll make sure to note that complete determinism might not always be achievable.
Reproducible training pipelines: what to lock down
Reproducibility is a metadata + determinism + storage problem. Aim for at least: “same code + same data snapshot + same environment + same config ⇒ same metrics (within tolerance)”, and optionally bitwise-identical results.
1) Data snapshots (raw + derived) — make inputs immutable
Goals
- You can always re-materialize the exact training/val/test inputs used for a run.
- Data changes are explicit and versioned.
Practices
- Immutable raw data snapshots: store raw datasets in versioned storage (e.g., S3 versioning, GCS object versioning) or a data versioning tool:
- DVC, lakeFS, Pachyderm, or “date-stamped snapshot folders” with checksums.
- Snapshot derived data too (cleaned tables, features, tokenized corpora, resized images). Don’t rely on recomputing unless the preprocessing is fully deterministic and versioned.
- Record a manifest for each snapshot:
- dataset version ID (S3 object version / lakeFS commit / DVC hash)
- file list + checksums (SHA256)
- schema/contract version (and validation results)
- Freeze splits: store the exact row IDs / file IDs used for train/val/test (or store the RNG seed + sorted IDs + split algorithm version, but storing indices is safer).
- Avoid “latest” references in training (e.g.,
s3://bucket/data/latest/…).
Minimum to log per run
data_snapshot_id (and for each input: path + version + checksum)
split_ids_artifact (train/val/test IDs)
2) Seeds & determinism — control randomness end-to-end
Practices
- Put a single
seed in your run config and propagate it everywhere:
- Python
random, NumPy, framework RNG (PyTorch/TF/JAX), dataloader workers, augmentation libs.
- Make dataloading deterministic:
- fixed shuffle seed
- stable ordering of filenames/IDs (sort!)
- deterministic
worker_init_fn for multiprocessing
- Enable deterministic kernels where possible (note: can slow training).
PyTorch seed template
def seed_everything(seed: int):
import os, random
import numpy as np
import torch
os.environ["PYTHONHASHSEED"] = str(seed)
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
# Determinism knobs (may reduce performance)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
torch.use_deterministic_algorithms(True)
# For some CUDA GEMMs (required for determinism in some cases)
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
Also do
- Log the seed(s) used for:
- model init, data split, augmentation, sampler, dropout, etc.
- For distributed training, ensure each rank’s seed derivation is logged (e.g.,
seed + rank).
Reality check
- Some ops remain nondeterministic on some GPU/CUDA combos. In that case, record “determinism level” and accept metric-tolerance reproducibility.
3) Environment pinning — make “works on my machine” impossible
Practices
- Pin dependencies with a lockfile, not just loose ranges:
- Python:
poetry.lock, uv.lock, pip-tools compiled requirements.txt, or conda-lock.
- Capture the full runtime stack:
- OS image, Python version
- CUDA toolkit version, cuDNN, GPU driver
- framework version (torch/tf/jax), compiler toolchain if relevant
- Use containers for training:
- Docker image digest (not just tag):
image@sha256:...
- Record hardware:
- GPU model, number of GPUs, CPU type (some numerical differences can arise)
Minimum to log per run
git_commit, dirty_repo flag
python_version
lockfile content or hash
container_image_digest (if applicable)
cuda_version, driver_version, gpu_type
4) Artifact tracking — treat each run as a fully reconstructable bundle
Use a tracker (MLflow, Weights & Biases, Neptune, ClearML, etc.) or a strict filesystem layout in object storage.
Log for every run
- Config: full resolved config (YAML/JSON), including defaults after merges
- Code identity: git commit + diff (or “dirty” indicator)
- Data identity: snapshot IDs + checksums + split IDs
- Environment: lockfile/conda env + container digest
- Training outputs:
- model weights
- metrics (and the exact evaluation dataset snapshot)
- training curves, confusion matrices, sample predictions
- tokenizer/vocab, label mapping, feature stats, normalization params
- Run metadata:
- start/end time, hostname, command line, random seeds
- any resume-from-checkpoint lineage
Tip: create a single run_manifest.json that points to all of the above; store it alongside artifacts.
A practical “definition of done” checklist
- One command can rerun a previous experiment using only:
- The rerun automatically pulls:
- exact data snapshot
- exact code commit
- exact environment/container
- The rerun produces:
- same metrics within agreed tolerance (or bitwise-identical if required)
- Every run stores:
run_manifest.json + model + metrics + logs in durable storage
If you tell me your stack, I can tailor this
Reply with:
- framework (PyTorch/TF/JAX), orchestration (Airflow/Prefect/Kubeflow/etc.), and where data lives (S3/GCS/DB),
and I’ll propose a concrete setup (e.g., DVC+MLflow+Docker, or lakeFS+W&B+K8s) including a recommended manifest schema and folder layout.