pytorch
runtime_error
ai_generated
true
RuntimeError:torch.compile缓存损坏:编译模块的键哈希无效
RuntimeError: torch.compile cache corrupted: invalid key hash for compiled module
ID: pytorch/compiler-cache-corruption
90%修复率
85%置信度
1证据数
2024-03-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| torch>=2.1.0 | active | — | — | — |
| torch>=2.2.0 | active | — | — | — |
根因分析
torch.compile的磁盘缓存目录(默认~/.cache/torch/compile)包含因版本不匹配或写入不完整而导致的陈旧或损坏文件。
English
The on-disk cache directory for torch.compile (default ~/.cache/torch/compile) contains stale or corrupted files due to version mismatch or incomplete writes.
官方文档
https://pytorch.org/docs/stable/compile/caching.html解决方案
-
Clear the torch.compile cache: rm -rf ~/.cache/torch/compile/
-
Disable caching entirely: torch._dynamo.config.cache_size_limit = 0
-
Set a different cache directory: export TORCH_COMPILE_CACHE_DIR=/tmp/torch_cache
无效尝试
常见但无效的做法:
-
98% 失败
The cache is stored in user home directory, not in the package installation; reinstalling doesn't clear it.
-
85% 失败
Debug mode only prints information but doesn't fix the corruption.