How to Cache Model Weights and Datasets in GitHub Actions
Cache the weights and dataset directory keyed on a manifest hash so a large download only repeats when the content changes.
Point actions/cache at your weights and dataset directories (for example the Hugging Face cache) and key it on a hash of the file that pins their versions. A cache hit skips the download entirely.
Steps
- Choose a stable cache directory (e.g.
~/.cache/huggingface). - Key the cache on a hash of the file that pins model and dataset versions.
- Restore before the download step so a hit skips it.
Workflow
.github/workflows/ci.yml
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.cache/huggingface
key: hf-${{ hashFiles('models.lock') }}
restore-keys: |
hf-
- run: python download_assets.pyGotchas
- GitHub caches have a per-repo size limit; store very large datasets in object storage instead.
- Cache the download directory, not model outputs you want regenerated each run.
Related guides
How to Load Hugging Face Datasets in GitHub ActionsDownload Hugging Face datasets and models in GitHub Actions with an auth token from secrets and a cached HF_H…
How to Pull DVC-Tracked Data in GitHub ActionsFetch DVC-tracked datasets and models in GitHub Actions with dvc pull against a remote, authenticated by a se…