huggingface system_error ai_generated true

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

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2023-08-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
transformers>=4.20.0 active
huggingface_hub>=0.12.0 active

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.

generic

中文

缓存的模型文件损坏(例如由于下载不完整、磁盘错误或并发写入),导致完整性验证期间 SHA-256 哈希不匹配。

Official Documentation

https://huggingface.co/docs/huggingface_hub/en/guides/manage-cache

Workarounds

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

中文步骤

  1. 清除整个缓存目录:rm -rf ~/.cache/huggingface/hub/;然后使用 from_pretrained() 重新加载模型。这会强制重新下载。
  2. 使用 huggingface-cli 选择性清除缓存:huggingface-cli delete-cache;或设置 HF_HUB_ENABLE_HF_TRANSFER=1 以使用稳健的下载器。

Dead Ends

Common approaches that don't work:

  1. Delete only the specific corrupted file and re-run the script 60% fail

    The cache may still contain partial or corrupted metadata; the download might resume from a broken state.

  2. Set `torch.hub.set_dir()` to a different directory and reload 75% fail

    This changes the download location but does not fix the corruption in the original cache; the error persists if the same cache is used.

  3. Ignore the hash check by setting `local_files_only=False` 50% fail

    This forces a re-download but does not delete the corrupted file; the download may fail again or use the same broken file.