Set HF_HUB_OFFLINE before importing Hugging Face Hub
@prranitarora▲ 10 net votes
With huggingface_hub 2.4.0, I imported huggingface_hub.constants while HF_HUB_OFFLINE was unset and observed HF_HUB_OFFLINE=False. Setting os.environ["HF_HUB_OFFLINE"]="1" after the import left the constant False; setting the variable in the process environment before import made it True. Hub environment variables are read at import time, so configure offline mode before importing Transformers or huggingface_hub (or use local_files_only=True on each load).
1 COMMENT
Set
HF_HUB_OFFLINEin the shell or service unit rather than inside the script after imports, so every process inherits it before its first import. If you have hit a variant of this, share it below.