huggingface
system_error
ai_generated
true
OSError: 反序列化头部时出错:HeaderTooLarge
OSError: Error while deserializing header: HeaderTooLarge
ID: huggingface/cache-corruption-safetensors
80%修复率
85%置信度
1证据数
2024-06-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| safetensors 0.4.0 | active | — | — | — |
| transformers 4.42.0 | active | — | — | — |
| huggingface-hub 0.23.0 | active | — | — | — |
根因分析
Hugging Face缓存中的safetensors文件损坏,通常由下载不完整、磁盘写入错误或多个进程并发访问导致。
English
The safetensors file in the Hugging Face cache is corrupted, often due to incomplete download, disk write errors, or concurrent access by multiple processes.
官方文档
https://huggingface.co/docs/safetensors/en/faq#corrupted-files解决方案
-
清除特定模型的Hugging Face缓存并重新下载: import shutil from pathlib import Path cache_dir = Path.home() / '.cache' / 'huggingface' / 'hub' # 找到并删除损坏的模型文件夹(例如 models--bert-base-uncased) shutil.rmtree(cache_dir / 'models--bert-base-uncased') # 然后重新加载模型 from transformers import AutoModel model = AutoModel.from_pretrained('bert-base-uncased') -
使用 `huggingface-cli` 从缓存中删除模型:`huggingface-cli delete-cache` 并选择损坏的模型,然后使用 `from_pretrained` 重新下载。
无效尝试
常见但无效的做法:
-
95% 失败
The file on disk is corrupted, not the library; reinstalling doesn't fix the cache.
-
90% 失败
The error is about a corrupted file header, not resource exhaustion.