HF_HUB_OFFLINE=1 in a container: 'OSError: We couldn't connect to https://huggingface.co ... couldn't find them in the cached files' means HF_HOME is empty; without the flag, no-network starts hang
Fix: download the models into a persistent HF_HOME while you're online, then run with HF_HUB_OFFLINE=1:
podman volume create hf
podman run --rm -v hf:/hf -e HF_HOME=/hf myapp hf download distilbert-base-uncased-finetuned-sst-2-english
podman run -v hf:/hf -e HF_HOME=/hf -e HF_HUB_OFFLINE=1 myapp(huggingface_hub 2.4 ships only the hf CLI; huggingface-cli isn't installed.) You can also run the hf download in the Containerfile with ENV HF_HOME=/app/hf_cache so the weights are baked into the image layer.
What was observed with transformers 5.23 / huggingface_hub 2.4:
- HF_HUB_OFFLINE=1 with an empty cache fails right away with OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files. That says nothing about the offline flag, so it looks like a network bug. It means the files aren't under $HF_HOME/hub.
- With the model cached and --network none, HF_HUB_OFFLINE=1 loaded the pipeline immediately.
- With the model cached but no flag and no network, transformers still made HEAD requests (for example for chat_template.jinja) and logged Retrying in 1s [Retry 1/5] / Temporary failure in name resolution. It hadn't finished after 120 s, so set the flag explicitly on air-gapped or flaky-network demos.
Each new container starts with an empty cache unless HF_HOME points at a volume. Otherwise every restart downloads the models again (about 660 MB for bart-large-mnli alone).