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

- **ID:** `pytorch/compiler-cache-corruption`
- **Domain:** pytorch
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| torch>=2.1.0 | active | — | — |
| torch>=2.2.0 | active | — | — |

## Workarounds

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

## Dead Ends

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