Pipeline stages and dependencies
Quick answer
A pipeline stage is a named computation with declared inputs, outputs and a command. A directed acyclic graph (DAG) links a stage that produces a file to stages that consume it. Examples use standard-library Python; native DVC commands are not executed. ByteMind execution is unverified.
Find a ready stage
deps={"train":{"prepare"},"prepare":set(),"eval":{"train"}}done={"prepare"}print(sorted(s for s,d in deps.items() if s not in done and d<=done))Expected output (locally tested): ['train']. Only train has all its prerequisites completed.
How it works
DVC reads stages from dvc.yaml. A prepare stage can depend on raw.csv and prepare.py, output clean.csv, and feed train, which produces model.json. Eval reads the model and evaluation data, and writes metrics.json. Declare the script itself as a dependency; changing only its contents should invalidate the stage. A dependency graph orders computations, not merely the listing order in YAML. Each output needs a clear producer, and cycles are invalid. Review all commands before executing a pipeline because they can run arbitrary code and overwrite declared outputs. The companion native template has fixed local commands and a separate evaluation input; it is unexecuted. The teaching scheduler uses explicit function dispatch instead of executing arbitrary YAML commands. Stage-level invalidation depends on actual input bytes; a downstream stage can remain current when an upstream rerun produces identical output.
Check a stage output dependency
out={"prepare":"clean.csv","train":"model.json"}inputs={"eval":["model.json","test.csv"]}print([s for s,p in out.items() if p in inputs["eval"]])Expected output (locally tested): ['train']. The eval stage consumes the trained artifact.
Common mistakes
Do not omit code dependencies, consume a final test label during training, or rely on YAML ordering to resolve a cycle.
Practice and next steps
Draw a prepare → train → eval graph plus a parallel report stage. Mark what changes when only eval input changes.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Pipeline stages and dependencies — knowledge check
Apply pipeline stages and dependencies to small examples and debugging scenarios.
What determines stage ordering?
Why declare script files?
Can a valid DAG contain a cycle?
What should eval depend on?
Before running unfamiliar dvc.yaml?