From notebook to reproducible run
A reproducible result is a result whose complete input identity can be replayed.
A churn notebook cannot be reproduced by the teammate expected to ship it.
This chapter moves from name every input to prove replay parity. We will make the idea concrete in a small code example before placing it back inside a production system with a declared latency, cost, and operator-capacity budget.
Rebuild from the manifest and compare a serialized model checksum plus predictions on fixed golden requests.
Verify the behavior illustrated in run_identity.py, then measure decision utility, slice reliability, and system latency.
A mutable data/latest path and unpinned dependencies create a different model from the same command. An unsafe release must degrade to a named baseline or the last known-good version.
Build the idea one layer at a time.
A notebook proves that an idea worked once. A reproducible run proves which exact ingredients made it work and lets another machine reconstruct the result.
Reproducibility is an identity problem before it is a randomness problem. Code revision, immutable data, runtime image, configuration, and seed are independent inputs; recording only the seed leaves every other source of change invisible.
Treat those inputs as a small manifest and derive the run identifier from its canonical bytes. The identifier then connects metrics, logs, and model artifacts to evidence instead of to a mutable folder named latest.
- immutable data snapshots
- dependency locks
- run manifests
- schema contracts
Follow the reasoning before touching the code.
- 01
Name every input
List the source commit, dataset digest, container digest, resolved configuration, and random seed before training starts.
- 02
Canonicalize and hash
Serialize the manifest with stable key ordering, then hash those bytes so equivalent inputs receive the same identity.
- 03
Prove replay parity
Rebuild from the manifest and compare a serialized model checksum plus predictions on fixed golden requests.
import hashlib
import json
inputs = {"code": "8c21af", "data": "sha256:91ee", "image": "sha256:7bd0",
"config": {"alpha": 0.1, "epochs": 8}, "seed": 17}
canonical = json.dumps(inputs, sort_keys=True, separators=(",", ":")).encode()
run_id = hashlib.sha256(canonical).hexdigest()[:12]
manifest = {"run_id": run_id, "inputs": inputs}
print(json.dumps(manifest, indent=2, sort_keys=True))Derive a stable run ID from all declared inputs.
What to notice
- Changing only epochs changes the canonical bytes and therefore the run ID.
- Reordering keys does not change the ID because serialization sorts them first.
YOUR TURN Pause and predict before revealing the answer.
Run the example twice, then change only the data digest. Which identity should remain stable and which should change?
Need a hint?
The manifest describes a different input set even when code and seed are unchanged.
Check your reasoning
The original invocation keeps its run ID across replays; the changed data digest produces a new run ID.
Tested Python, basic probability, vectors, and supervised ML.
Connect the chapter to the course’s quantitative spine.
A reproducible result is a result whose complete input identity can be replayed. The content-addressed run identity below is the shared course-level lens that helps quantify the surrounding system. Name each symbol, check its units or shape, and use only values that were available at the production cutoff.
Content-addressed run identity
| Symbol | Meaning / shape / unit |
|---|---|
code | source revision digest |
data | immutable dataset digest |
image | OCI image digest |
seed | declared random seed |
Open derivation and numerical substitution
Start from the production quantity being optimized, substitute the observed values with their declared units, then isolate the model-controlled term. Preserve shape annotations at each step so broadcasting or aggregation cannot silently change the result.
- Write the named inputs: code, data, image, seed.
- Substitute one small, hand-checkable batch before vectorizing.
- Calculate an independent reference value and compare within a declared tolerance.
# equation → code contract
inputs = validate_shapes_and_units(batch)
value = compute_c01(inputs)
assert is_finite(value)Change one assumption and make the tradeoff visible.
Use the worked chapter as your prediction, then change one input in the lab and explain why the output moves. The lab runs predefined TypeScript and never executes learner code, so the focus stays on the concept rather than setup.
Reproducibility fault injector
Change how many declared inputs remain mutable and observe replay parity.
Assumption: Each mutable input independently creates a 14-point replay risk.
Open nonvisual data table
| Item | Computed state | Interpretation |
|---|---|---|
| input 1 | mutable | replay risk |
| input 2 | mutable | replay risk |
| input 3 | content-addressed | verified |
| input 4 | content-addressed | verified |
| input 5 | content-addressed | verified |
Trace the complete operating path.
Carry the chapter’s central idea into the system: A reproducible result is a result whose complete input identity can be replayed. The path below shows where that reasoning needs an artifact, a test, an owner, or a fallback.
- 01
Turn “Name every input” into a written invariant and a failing test.
- 02
Promote run_identity.py from illustration to a versioned implementation with representative fixtures.
- 03
Use “Prove replay parity” as the release checkpoint: Rebuild from the manifest and compare a serialized model checksum plus predictions on fixed golden requests.
- 04
Serve or materialize behind explicit a declared latency, cost, and operator-capacity budget.
- 05
Join telemetry to mature outcomes and retain a rollback path.
Observability
Join service health, input quality, prediction distributions, slice behavior, and mature outcomes by exact version.
Cost
Measure storage, preprocessing, compute, queueing, and human review under a representative arrival pattern.
Failure modes
A mutable data/latest path and unpinned dependencies create a different model from the same command. Add a detector, owner, mitigation, and stop condition for this class of failure.
Alternatives
Compare a rule, a simpler statistical baseline, and a different system boundary before adding model complexity.
Explain the contract, not just the vocabulary.
Reproducible baseline package
Design a Docker-only workflow that validates data, trains, evaluates, serializes, performs golden inference, and emits complete lineage.
- Run manifest and data contract
- Raw-input golden parity test
- Failure and retry runbook
- Model card with residual nondeterminism
Read primary material with a purpose.
Return to the opening failure.
Reject promotion when any artifact lacks lineage, golden raw-request parity, or a failure-safe recovery path.
For this lesson, the release evidence is the worked code example, a hand-checked formal result, deterministic simulation output, a ≥80% checkpoint, the production rubric, and a named fallback. The course resolves when the system can produce a seeded, tested, packaged, versioned training workflow with a model card.