Hugging Face cheatsheet

Hugging Face: Cache and environment

4 common Hugging Face tasks.

Move the cache

Store downloaded models and datasets on a larger disk.

export HF_HOME=/data/huggingface

Work offline

Use only files already in the cache and make no network requests.

export HF_HUB_OFFLINE=1

Download a repository from Python

Download a full repository snapshot and get its local path.

from huggingface_hub import snapshot_download

path = snapshot_download("Qwen/Qwen2.5-0.5B-Instruct")

Download one file from Python

Download a single file and get its local path.

from huggingface_hub import hf_hub_download

path = hf_hub_download(repo_id="bert-base-uncased", filename="config.json")

Was this page helpful?