# OSError: Unable to load weights from huggingface checkpoint. Error: file is corrupted or truncated

- **ID:** `llm/huggingface-model-load-cache-corruption`
- **Domain:** llm
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Partial download or disk corruption of Hugging Face model cache files, often due to interrupted downloads or concurrent write access to the cache directory.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| transformers==4.41.0 | active | — | — |
| huggingface_hub==0.23.0 | active | — | — |
| torch==2.3.0 | active | — | — |

## Workarounds

1. **Clear the specific model cache and re-download: `rm -rf ~/.cache/huggingface/hub/models--bert-base-uncased` then reload the model.** (95% success)
   ```
   Clear the specific model cache and re-download: `rm -rf ~/.cache/huggingface/hub/models--bert-base-uncased` then reload the model.
   ```
2. **Use `snapshot_download` with `resume_download=False` to force a fresh download: `from huggingface_hub import snapshot_download; snapshot_download('bert-base-uncased', resume_download=False)`** (90% success)
   ```
   Use `snapshot_download` with `resume_download=False` to force a fresh download: `from huggingface_hub import snapshot_download; snapshot_download('bert-base-uncased', resume_download=False)`
   ```
3. **Set `HF_HUB_ENABLE_HF_TRANSFER=1` to use the faster download library which includes integrity checks by default.** (85% success)
   ```
   Set `HF_HUB_ENABLE_HF_TRANSFER=1` to use the faster download library which includes integrity checks by default.
   ```

## Dead Ends

- **** — The corrupted file remains in the cache; the loader will attempt to read the same broken file and fail again. (100% fail)
- **** — The error is about file integrity, not capacity; more space won't fix a truncated file. (80% fail)
- **** — This changes the model entirely and doesn't address the cache corruption for the original model. (90% fail)
