# 运行时错误：cuDNN 错误：CUDNN_STATUS_NOT_INITIALIZED

- **ID:** `pytorch/cudnn-deterministic-error`
- **领域:** pytorch
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

cuDNN 未正确初始化，通常是由于 CUDA 上下文不一致，或者在 CUDA 设备重置后使用了 cuDNN 句柄。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| torch>=1.10.0 | active | — | — |
| cuDNN>=8.0 | active | — | — |

## 解决方案

1. ```
   Ensure a single CUDA context is used. Avoid creating multiple contexts by calling torch.cuda.init() once at the beginning.
   ```
2. ```
   Set torch.backends.cudnn.deterministic = True and torch.backends.cudnn.benchmark = False to avoid handle conflicts.
   ```

## 无效尝试

- **** — Calling torch.cuda.empty_cache() does not reinitialize cuDNN and may cause further issues. (90% 失败率)
- **** — Reinstalling PyTorch or cuDNN without addressing the CUDA context issue will not fix the problem. (85% 失败率)
