# 运行时错误：cuDNN 错误：将批量归一化 epsilon 设置为 0 时 CUDNN_STATUS_BAD_PARAM

- **ID:** `cuda/cudnn-bn-epsilon-nan`
- **领域:** cuda
- **类别:** type_error
- **错误码:** `CUDNN_STATUS_BAD_PARAM`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

cuDNN 批量归一化需要正 epsilon 值以避免除以零；将 epsilon 设置为 0 会触发参数验证错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| cuDNN 8.6 | active | — | — |
| cuDNN 8.9 | active | — | — |
| PyTorch 2.0 | active | — | — |
| PyTorch 2.2 | active | — | — |

## 解决方案

1. ```
   Set epsilon to a positive value >= 1e-5 in the batch normalization layer definition. For PyTorch, use `nn.BatchNorm2d(num_features, eps=1e-5)`.
   ```
2. ```
   If epsilon is loaded from a config file, add validation to clamp it to a minimum of 1e-5 before passing to the layer.
   ```

## 无效尝试

- **** — While this avoids the error, it may cause numerical instability in batch normalization; recommended minimum is 1e-5. (50% 失败率)
- **** — This changes the model architecture and may degrade accuracy; overkill for a parameter fix. (80% 失败率)
