# RuntimeError: cuDNN error: CUDNN_STATUS_BAD_PARAM when calling cudnnSetRNNDescriptor_v8

- **ID:** `pytorch/cudnn-benchmark-algo-failure`
- **Domain:** pytorch
- **Category:** runtime_error
- **Error Code:** `CUDNN_STATUS_BAD_PARAM`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

torch.backends.cudnn.benchmark enabled with an RNN that uses a non-default hidden size or num_layers that cuDNN does not support in its heuristic search, causing invalid parameters in RNN descriptor initialization.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PyTorch 2.0.0 | active | — | — |
| PyTorch 2.1.0 | active | — | — |
| cuDNN 8.9.0 | active | — | — |
| CUDA 11.8 | active | — | — |

## Workarounds

1. **Disable cuDNN benchmark: torch.backends.cudnn.benchmark = False. Also, set torch.backends.cudnn.enabled = False as a fallback if the error persists.** (75% success)
   ```
   Disable cuDNN benchmark: torch.backends.cudnn.benchmark = False. Also, set torch.backends.cudnn.enabled = False as a fallback if the error persists.
   ```
2. **Use a hidden size divisible by 64 (e.g., 256 instead of 250) and ensure num_layers <= 8. Example: model = nn.LSTM(input_size=128, hidden_size=256, num_layers=2, batch_first=True).** (85% success)
   ```
   Use a hidden size divisible by 64 (e.g., 256 instead of 250) and ensure num_layers <= 8. Example: model = nn.LSTM(input_size=128, hidden_size=256, num_layers=2, batch_first=True).
   ```
3. **Switch to PyTorch's native RNN implementation by setting torch.backends.cudnn.enabled = False before model creation. This forces the use of non-cuDNN kernels.** (70% success)
   ```
   Switch to PyTorch's native RNN implementation by setting torch.backends.cudnn.enabled = False before model creation. This forces the use of non-cuDNN kernels.
   ```

## Dead Ends

- **** — Upgrading PyTorch alone does not fix the cuDNN parameter validation; the root cause is the RNN configuration, not the library version. (60% fail)
- **** — Setting torch.backends.cudnn.deterministic = True does not prevent the benchmark from running the failing heuristic; it only affects algorithm selection. (70% fail)
- **** — Changing batch size does not affect the RNN descriptor parameters (hidden_size, num_layers), so the error persists. (50% fail)
