Sub topic 2
Sharing Data Through a Remote
This chapter assumes you know basic Git (commit, tag, checkout), you work comfortably in the command line, and you have a DVC project with at least one tracked file from the previous chapter.
Sharing data through a remote
A DVC remote is a storage location, such as an S3 bucket, where DVC keeps copies of your cached files. Git stores only the small .dvc pointer files, so teammates need the remote to get the actual data.
dvc remote add -d storage s3://my-bucket/dvc-store
git add .dvc/config
git commit -m "Configure default DVC remote"
dvc push
# On another machine, after git clone:
dvc pulldvc push uploads cached files to the remote. dvc pull downloads the files that the current commit's pointer files refer to.
Moving between data versions
Each Git commit records a version of the pointer files. To return to an older dataset, restore the pointer files with Git, then let DVC update the workspace.
git checkout v1.0
dvc checkoutdvc checkout reads the restored pointers and fills the workspace from the local cache. If the files are not cached locally, run dvc pull first.
Reproducible pipelines with dvc.yaml
A pipeline is a set of stages. Each stage declares a command, its dependencies, its parameters, and its outputs in dvc.yaml. dvc repro reruns only the stages whose inputs changed, and it records exact hashes in dvc.lock.
stages:
prepare:
cmd: python src/prepare.py data/raw.csv data/prepared
deps:
- src/prepare.py
- data/raw.csv
outs:
- data/prepared
train:
cmd: python src/train.py data/prepared models/model.pkl
deps:
- src/train.py
- data/prepared
params:
- train.n_estimators
outs:
- models/model.pklThe train.n_estimators key comes from params.yaml, which must contain train: with n_estimators: 100. Run the pipeline and commit the results:
dvc repro
git add dvc.yaml dvc.lock params.yaml
git commit -m "Add training pipeline"Exercise
If you change only src/train.py, which stages does dvc repro rerun?
Show answer
Only train. The prepare stage does not depend on src/train.py, so DVC reuses its cached output.