Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A recipe that remembers
A cook who writes down every ingredient, quantity and step can make the same dish again, and if only the sauce changes, there is no need to bake the bread again. A training pipeline is a recipe of the same kind: load data, clean it, build features, split, train, evaluate. Writing it as a graph of steps with their inputs and settings makes results repeatable and lets the computer re-run only what a change affects. The difficulty is deciding what counts as a change: skip too much and the result is quietly wrong, skip too little and every small edit costs a full run.
Blue: the step ran. Total work 137 units (a full run costs 31: ingest 1, clean 2, featurize 5, split 1, train 20, evaluate 2); results wrong after 0 of 10 edits.
N2-3, seed 0. A content hash of code, parameters and inputs re-runs exactly the steps whose result can change. Keying on name and parameters alone is cheapest because it misses data and code changes; timestamps are safe but re-run too much.
In Exercise 2, caching steps by name and parameters did the least work but reported a wrong result after 6 of 10 edits; hashing code, parameters and input data did 44% of the work of re-running everything and was never wrong.
- 1. A pipeline step's output should depend only on…
- 2. Caching a step means…
- 3. If the training data change, which steps must re-run?
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Pipeline (DAG): steps connected by data dependencies; each step is a function of its inputs and parameters.
- Content addressing: naming an output by a hash of everything that determines it (code version, parameters, input hashes), as Git, Nix, Bazel and DVC do.
- Cache hit and miss: an output whose key is already stored is reused; otherwise the step runs.
- Invalidation: deciding which cached outputs are no longer valid after a change; with content keys it is automatic.
- Make-style timestamps: a target is rebuilt when any dependency file is newer than it.
- Determinism: the same inputs give bit-identical outputs; broken by unseeded randomness, parallel reductions and different library builds.
- Hidden inputs: anything a step reads that is not declared: globals, environment variables, files read directly, the clock.
- Lineage: the record of which data, code and parameters produced an artifact (topics N2-1 and N2-2).
- Tools: DVC, Kedro, Snakemake, Bazel, Nix, Airflow, Kubeflow Pipelines, Metaflow.
- 1. A content-addressed key is a hash of…
- 2. A hidden input is…
- 3. Make rebuilds a target when…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.A content-addressed pipeline
Exercise 1.
- Six steps with costs in work units: ingest 1, clean 2, featurize 5, split 1, train 20, evaluate 2 (31 per full run).
- Each step’s key hashes its name, code version, parameters and the keys of its inputs; raw data join the ingest key through their content hash.
- Data: 3,000 rows, 6 features, label from a logistic model with an interaction, 2% missing values in one feature.
- Train logistic regression with L2 penalty; evaluate test accuracy at a threshold.
Practice.
- Declare every input: data files, parameters, code version, and the environment.
- Key on content, not names or times: hash what a result depends on.
- Make steps deterministic: seed every random generator, and fix reduction order where bit-identical results matter.
- Keep parameters per step, so changing one step’s setting does not invalidate the others.
- Store outputs by key and garbage-collect by use, keeping room for the configurations you return to.
def key(step, input_keys):
return h(step.name, step.code, step.params, [input_keys[i] for i in step.inputs])
def run(pipeline, cache):
keys, out = dict(), dict()
for s in pipeline.order: # topological order
k = key(s, keys); keys[s.name] = k
if k not in cache:
cache[k] = s.fn(*[out[i] for i in s.inputs], **s.params)
out[s.name] = cache[k]
return out- 1. Changing train's L2 penalty should re-run…
- 2. Reverting a parameter to an earlier value with a content cache…
- 3. Putting all parameters in one shared file with timestamps…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Correctness of content keys. If every step is deterministic and its key hashes its code, parameters and its inputs’ keys, then by induction along the graph two runs with the same key at a step computed it from identical raw data, code and parameters along every path into it, so the cached output is exactly what a fresh run would produce (barring hash collisions, about 2 to the power −48 per pair for 12 hex digits). Conversely, a change anywhere changes the keys of that step and all its descendants and of nothing else, so the work after an edit is the cost of the affected subgraph, minus anything already in the cache.
What breaks it. A key that leaves something out returns stale results: keying on name and parameters ignores code and data, so an upstream change leaves downstream keys unchanged. An undeclared input (a global, a file read directly, the clock) has the same effect. Nondeterminism breaks the other direction: equal inputs give different bytes, so downstream keys change and nothing can be reused, and two machines disagree about the “same” result.
Timestamps. Make compares modification times. It never skips a needed run if every change touches a file, but it re-runs when a file is touched without changing (a re-download) and, with a shared parameter file, re-runs every step for any parameter edit. It also cannot return to an earlier configuration without recomputing it, because only the latest output is kept.
- 1. Content keys are correct if steps are…
- 2. Keying on name and parameters fails when…
- 3. Make re-runs a step after a re-download with identical content because…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Which caching strategy keeps a training pipeline both correct and cheap through a realistic series of edits?
History.
- S. Feldman’s Make (1976) rebuilt targets from file timestamps; it is still the model for many build and data tools.
- Content addressing came with version control and functional package management: Git (2005) stores objects by hash, E. Dolstra’s Nix (2004) builds packages from hashed inputs, and Google’s Blaze/Bazel (open-sourced 2015) caches build actions by content.
- In science, the reproducibility movement (for example G. K. Sandve and colleagues, “Ten simple rules for reproducible computational research”, 2013) and workflow tools such as Snakemake (2012) brought the same ideas to data analysis; DVC (2017), Kedro (2019) and Kubeflow Pipelines applied them to machine learning, and D. Sculley and colleagues (2015) listed undeclared dependencies among ML’s hidden technical debt.
Exercise 2.
- Ten edits in order: first run; nothing changed; train L2 0.001 to 0.1; evaluate threshold 0.5 to 0.6; raw data re-downloaded with the same content; featurize code changed (products without squares); 600 new raw rows; split seed 0 to 1; split seed back to 0; nothing changed.
- Four strategies apply the same edits. After each, the result is compared with a fresh run of everything.
- The Make-style pipeline keeps all parameters in one file, as many projects do, and keeps only the latest output of each step.
Seed 0:
| strategy | total work (units) | edits after which the result was wrong |
|---|---|---|
| re-run everything | 310 | 0 |
| content hash | 137 | 0 |
| name + parameters | 54 | 6 |
| timestamps (Make) | 245 | 0 |
Steps run by the content hash: everything on the first run; nothing for “nothing changed”, the identical re-download and the return to seed 0; train and evaluate for L2; evaluate for the threshold; featurize to evaluate for the code change; everything for new rows; split to evaluate for seed 1. Name + parameters ran only the step whose own parameters changed, and was wrong after the L2 edit (evaluate kept the old model’s score), the code change, the new rows, both seed changes and the final run. Final accuracy: 0.8472 correct, 0.845 reported by name + parameters.
Seeds 1 and 2: the work and the wrong-result counts are identical (310, 137, 54 with 6 wrong, 245), since they depend only on which keys change; final accuracy 0.8102 and 0.8238 correct, 0.8052 and 0.8203 reported by name + parameters.
Findings.
- Content hashes were never wrong and did 44% of the work of re-running everything in every seed (137 of 310 units).
- Keying on name and parameters did the least work (54) but gave wrong results after 6 of 10 edits in every seed; the reported accuracy was off by only 0.2 to 0.5 points, which is what makes such errors hard to notice.
- Timestamps were always right but did 245 units, re-running the whole pipeline for each parameter edit, the identical re-download and the return to an earlier seed.
Reproducible pipelines in practice
- DVC stores data and model outputs by content hash next to Git; Kedro, Metaflow and Kubeflow Pipelines describe steps and their inputs explicitly and cache their outputs.
- Bazel and Nix extend content keys to the whole toolchain, so the compiler and library versions are part of every key.
- Deep learning on GPUs is often not bit-reproducible because parallel sums run in varying order; frameworks offer deterministic modes at some cost in speed.
- Space missions and regulated industries archive the exact data, code and environment behind every delivered model, so it can be rebuilt years later for an investigation.
References
- S. I. Feldman (1979). “Make: a program for maintaining computer programs.” Software: Practice and Experience.
- E. Dolstra, M. de Jonge and E. Visser (2004). “Nix: a safe and policy-free system for software deployment.” LISA.
- J. Köster and S. Rahmann (2012). “Snakemake: a scalable bioinformatics workflow engine.” Bioinformatics.
- G. K. Sandve, A. Nekrutenko, J. Taylor and E. Hovig (2013). “Ten simple rules for reproducible computational research.” PLoS Computational Biology.
- D. Sculley and colleagues (2015). “Hidden technical debt in machine learning systems.” NeurIPS.
- Iterative (2017–). “DVC: Data Version Control.” dvc.org documentation.