How to Use Hugging Face Models Offline with HF_HUB_OFFLINE
Even when a model is already downloaded, Hugging Face libraries normally contact the Hub to check for a newer version. On a plane, behind a strict firewall or on a server with no internet, that check fails or waits. Setting HF_HUB_OFFLINE=1 tells them to use only what's in the cache. This guide shows both sides with huggingface_hub 2.5.0: a cached file loads, a missing one fails.
Syntax
HF_HUB_OFFLINE=1 <command>
| Part | What it means |
|---|---|
HF_HUB_OFFLINE=1 | Turns offline mode on: no calls to the Hub |
<command> | The program to run offline, such as uv run hf download … or uv run python train.py |
The environment variable reference says: "If set, no HTTP calls will be made to the Hugging Face Hub. If you try to download files, only the cached files will be accessed. If no cache file is detected, an error is raised". It also speeds things up: normally, "even if the latest version of a file is cached, calling hf_hub_download still triggers a HTTP request to check that a new version is not available. Setting HF_HUB_OFFLINE=1 will skip this call".
The Example
A project downloads one file while online, then asks for the same file and for a second, never-downloaded one with offline mode on.
Prerequisites
- uv. This guide uses uv 0.13.10 with Python 3.15.2.
Step 1: Create a Project and Download a File Online
uv init --python 3.15 offline-demo
cd offline-demo
uv add huggingface_hub
uv run hf download google-bert/bert-base-uncased config.json
Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
config.json: 100%|█████████████████████████████████████████████████| 570/570 [00:00<00:00, 4.25MB/s]
✓ Downloaded
path: /Users/you/.cache/huggingface/hub/models--google-bert--bert-base-uncased/snapshots/86b5e0934494bd15c9632b12f734a8a67f723594/config.json

config.json is now in the cache.
Step 2: Ask for the Same File Offline
In bash and zsh, putting the variable in front of the command sets it for that one command. In PowerShell, set it first; it then stays on for that terminal:
- macOS / Linux (bash, zsh)
- Windows (PowerShell)
HF_HUB_OFFLINE=1 uv run hf download google-bert/bert-base-uncased config.json
$env:HF_HUB_OFFLINE = "1"
uv run hf download google-bert/bert-base-uncased config.json
✓ Downloaded
path: /Users/you/.cache/huggingface/hub/models--google-bert--bert-base-uncased/snapshots/86b5e0934494bd15c9632b12f734a8a67f723594/config.json

The file came straight from the cache. There's no progress bar, and no warning from the Hub either, because the Hub was never contacted. The PowerShell version printed the same.
Step 3: Ask for a File That Isn't Cached
tokenizer.json was never downloaded:
HF_HUB_OFFLINE=1 uv run hf download google-bert/bert-base-uncased tokenizer.json
Error: Local entry not found. Cannot reach https://huggingface.co/google-bert/bert-base-uncased/resolve/main/tokenizer.json: offline mode is enabled. To disable it, please unset the `HF_HUB_OFFLINE` environment variable.
Hint: set HF_DEBUG=1 as environment variable for full traceback.

Offline mode refused to download it and said exactly why. To get it, turn offline mode off and download it once.
Turn Offline Mode Off Again
In bash and zsh, a variable put in front of one command is already gone. If you used export HF_HUB_OFFLINE=1, remove it with unset HF_HUB_OFFLINE. In PowerShell, remove it with:
Remove-Item Env:HF_HUB_OFFLINE
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Going offline before the files are downloaded | Error: Local entry not found. Cannot reach …: offline mode is enabled. | Run the program once online, so everything it needs is cached |
| Leaving offline mode on after a trip | New models and updates never download | unset HF_HUB_OFFLINE or Remove-Item Env:HF_HUB_OFFLINE |
| Setting it inside a Python program after the library is imported | The library has already read the setting | Set it before the program starts |
FAQ
Does this work with Transformers models too?
Yes. Transformers downloads through huggingface_hub, and its installation guide says: "Set the environment variable HF_HUB_OFFLINE=1 to prevent HTTP calls to the Hub when loading a model."
Is there a way to go offline for one model only?
In Transformers, pass local_files_only=True to from_pretrained, which the same guide describes as "Another option for only loading cached files".
Conclusion
With HF_HUB_OFFLINE=1, the cached config.json loaded without contacting the Hub, and the never-downloaded tokenizer.json failed with "offline mode is enabled". Download once online, then run offline as often as you like.
Additional Resources
- HF_HUB_OFFLINE — the environment variable reference.
- Offline mode in Transformers — preparing a model for offline use.
