# RuntimeError：torch.compile缓存损坏：编译模块的键哈希无效

- **ID:** `pytorch/compiler-cache-corruption`
- **领域:** pytorch
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

torch.compile的磁盘缓存目录（默认~/.cache/torch/compile）包含因版本不匹配或写入不完整而导致的陈旧或损坏文件。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| torch>=2.1.0 | active | — | — |
| torch>=2.2.0 | active | — | — |

## 解决方案

1. ```
   Clear the torch.compile cache: rm -rf ~/.cache/torch/compile/
   ```
2. ```
   Disable caching entirely: torch._dynamo.config.cache_size_limit = 0
   ```
3. ```
   Set a different cache directory: export TORCH_COMPILE_CACHE_DIR=/tmp/torch_cache
   ```

## 无效尝试

- **** — The cache is stored in user home directory, not in the package installation; reinstalling doesn't clear it. (98% 失败率)
- **** — Debug mode only prints information but doesn't fix the corruption. (85% 失败率)
