pytorch runtime_error ai_generated true

RuntimeError: torch.compile cache corrupted: invalid key hash for compiled module

ID: pytorch/compiler-cache-corruption

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2024-03-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
torch>=2.1.0 active
torch>=2.2.0 active

Root Cause

The on-disk cache directory for torch.compile (default ~/.cache/torch/compile) contains stale or corrupted files due to version mismatch or incomplete writes.

generic

中文

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

Official Documentation

https://pytorch.org/docs/stable/compile/caching.html

Workarounds

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

中文步骤

  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

Dead Ends

Common approaches that don't work:

  1. 98% fail

    The cache is stored in user home directory, not in the package installation; reinstalling doesn't clear it.

  2. 85% fail

    Debug mode only prints information but doesn't fix the corruption.