Sub topic 16
Checking Reproducibility in CI
Assume you know basic Git, shell commands, Python packaging, lock files, and Docker. Continuous integration (CI) is an automated job that runs when code changes. A reproducibility check makes CI rebuild the environment instead of trusting a developer’s local setup.
What CI should prove
A useful CI check answers two separate questions:
- Is the dependency lock file current?
- Can the declared environment actually be rebuilt?
The first check catches a changed pyproject.toml without a matching uv.lock, or a changed requirements.in without a regenerated requirements.lock. The second check catches an invalid Dockerfile, unavailable package, broken native dependency, or incompatible build step.
CI does not prove that every training run produces identical weights. Random seeds, GPU kernels, data order, hardware, and external services can still affect runtime results. It proves that the project’s declared environment can be reconstructed from version-controlled inputs.
| Check | Failure it catches |
|---|---|
| Locked dependency install | The lock file is stale or incomplete |
| Docker image build | The container recipe cannot be rebuilt |
| Optional smoke test | The rebuilt environment cannot import or run the project |
A CI workflow with uv and Docker
The following GitHub Actions workflow assumes that pyproject.toml, uv.lock, and Dockerfile are committed at the repository root. uv sync --locked exits with an error when the lock file does not match the project definition.
name: reproducibility
on:
push:
pull_request:
jobs:
rebuild:
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "latest"
- name: Install exactly from the lock file
run: uv sync --locked
- name: Run a small environment check
run: uv run python -c "import sys; print(sys.version)"
- name: Rebuild the production image
run: docker build --pull --tag ml-train:ci .--pull asks Docker to check for a newer version of the base-image tag. For stronger reproducibility, use a digest-pinned base image in the Dockerfile. A CI build should not silently use a developer’s locally cached image.
How the checks fit together
For a stronger test, run a short CPU smoke test inside the image. Test imports, configuration loading, and one small prediction. Avoid starting a full training job in every pull request unless its cost is acceptable.
Exercise
Why should CI run uv sync --locked instead of only running uv sync?
Show answer
The --locked option refuses to update the lock file. It therefore detects when the committed lock file is stale instead of hiding the mismatch by resolving new dependencies during CI.