Skip to content
Latchkey

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.py

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →