Skip to content

Hub and Caches

Qubitium edited this page Dec 3, 2026 · 2 revisions

Hugging Face Hub and caches

Full signatures and usage: Hub files and Xet uploads.

Use load(..., type="model") for a snapshot path, file= for an individual artifact, or type="dataset", split="train" for named rows. download=True permits filling cache misses. A cached branch ref can continue to point at an older commit; pin the commit for reproducibility or request DownloadConfig(force=True) for a refresh.

What counts as a cache hit?

Request Required local data
One file A completed snapshot file at the resolved commit. With a tree inventory, its name and size must match. A named file can also be reused from an older cache without an inventory.
Whole snapshot A version-1 trees/<commit>.json file inventory and a snapshot containing every inventoried file at the recorded size.
Named split A complete, unambiguous sequence of conventionally named shards at the pinned revision, or cached Dataset Viewer pages for that config and split.

For source split discovery, names include train.parquet, train.jsonl.gz and train-00000-of-00002.parquet. DataShoal checks the config directory, its data directory, or data/<config>; for the default config it also checks the root and data. Explicit file= avoids guessing when a repository has multiple possible sources.

Viewer rows are fetched in pages of up to 100 on iteration. Missing later pages can therefore raise an offline error after a successful prefix. Partial responses or truncated cells raise an error. For a complete offline run, finish the intended scan online once or fetch the source shards by name.

Paths and credentials

Setting Purpose
HF_HOME Cache base; defaults to $XDG_CACHE_HOME/huggingface or ~/.cache/huggingface.
HF_HUB_CACHE Hub file-cache root; defaults to $HF_HOME/hub.
HF_DATASETS_CACHE Dataset-cache root; defaults to $HF_HOME/datasets.
HF_DATASETS_DOWNLOADED_DATASETS_PATH Overrides the Viewer response directory, normally $HF_DATASETS_CACHE/downloads.
HF_TOKEN or token= Credential for private or gated HF repositories. An explicit token takes precedence.
HF_HUB_OFFLINE=1 Enforces offline reads, including when download permission was supplied, and blocks uploads.

Hub files use models--ORG--REPO or datasets--ORG--REPO directories containing refs/, blobs/, and snapshots/<commit>/. Newly fetched content is checked against the advertised size and digest before publication. Viewer JSON responses use URL-hashed filenames and metadata sidecars in the downloads cache. Materialized HF Datasets Arrow caches have a different layout.

Loading reference · Transfer protocol · Troubleshooting

Clone this wiki locally