# OSError: Unable to load model from cache: file hash mismatch for 'pytorch_model.bin'. Expected sha256: abc123... but got xyz789...

- **ID:** `huggingface/transformers-cache-corruption`
- **Domain:** huggingface
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The cached model file is corrupted (e.g., due to incomplete download, disk errors, or concurrent write) causing a SHA-256 hash mismatch during integrity verification.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| transformers>=4.20.0 | active | — | — |
| huggingface_hub>=0.12.0 | active | — | — |

## Workarounds

1. **Clear the entire cache directory: rm -rf ~/.cache/huggingface/hub/; then reload the model with from_pretrained(). This forces a fresh download.** (95% success)
   ```
   Clear the entire cache directory: rm -rf ~/.cache/huggingface/hub/; then reload the model with from_pretrained(). This forces a fresh download.
   ```
2. **Use huggingface-cli to clear cache selectively: huggingface-cli delete-cache; or set HF_HUB_ENABLE_HF_TRANSFER=1 to use a robust downloader.** (90% success)
   ```
   Use huggingface-cli to clear cache selectively: huggingface-cli delete-cache; or set HF_HUB_ENABLE_HF_TRANSFER=1 to use a robust downloader.
   ```

## Dead Ends

- **Delete only the specific corrupted file and re-run the script** — The cache may still contain partial or corrupted metadata; the download might resume from a broken state. (60% fail)
- **Set `torch.hub.set_dir()` to a different directory and reload** — This changes the download location but does not fix the corruption in the original cache; the error persists if the same cache is used. (75% fail)
- **Ignore the hash check by setting `local_files_only=False`** — This forces a re-download but does not delete the corrupted file; the download may fail again or use the same broken file. (50% fail)
