Hugging Face Transformers: OSError: Can't load model from cache
Traceback (most recent call last):
File "inference.py", line 5, in <module>
model = AutoModel.from_pretrained("bert-base-uncased")
OSError: Can't load model 'bert-base-uncased' from cache, no such file or directory
Immediate Remediation
bash
huggingface-cli download bert-base-uncased
Root Cause Analysis
The model is not cached locally and the environment is offline or the cache directory is missing, so Transformers cannot find the model files and raises OSError.
Verification & Guardrails
- Ensure network access or pre-download model
- Set HF_HOME or TRANSFORMERS_CACHE to a writable directory
- Use local_files_only=True to force cache-only mode
Have a custom or uncategorized crash?
Run your trace through our in-memory client privacy sandbox for instant SRE remediation.