# 运行时错误：cuDNN 错误：调用 cudnnRNNForwardTraining 时输入大小不匹配导致 CUDNN_STATUS_BAD_PARAM

- **ID:** `cuda/cudnn-rnn-bad-dims`
- **领域:** cuda
- **类别:** runtime_error
- **错误码:** `CUDNN_STATUS_BAD_PARAM`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

RNN 层的输入张量的特征维度与 cuDNN RNN 描述符中定义的预期输入大小不匹配，或者各层之间的批次大小不一致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| cuDNN 8.9.2 | active | — | — |
| CUDA 12.0 | active | — | — |
| PyTorch 2.1.0 | active | — | — |
| TensorFlow 2.14 | active | — | — |

## 解决方案

1. ```
   import torch; rnn = torch.nn.LSTM(input_size=128, hidden_size=256, num_layers=2); input_tensor = torch.randn(10, 32, 128); output, _ = rnn(input_tensor)
   ```
2. ```
   rnn = torch.nn.LSTM(input_size=128, hidden_size=256, batch_first=True); input_tensor = torch.randn(32, 10, 128)
   ```

## 无效尝试

- **** — Layer count does not affect the input dimension mismatch; the error is about the first layer's input size. (90% 失败率)
- **** — The input dimension requirement is independent of cell type; the mismatch persists. (85% 失败率)
