pytorch runtime_error ai_generated true

运行时错误:cuDNN 错误:CUDNN_STATUS_NOT_INITIALIZED

RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED

ID: pytorch/cudnn-deterministic-error

其他格式: JSON · Markdown 中文 · English
75%修复率
83%置信度
1证据数
2023-04-02首次发现

版本兼容性

版本状态引入弃用备注
torch>=1.10.0 active
cuDNN>=8.0 active

根因分析

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

English

cuDNN was not properly initialized, often because of an inconsistent CUDA context or because a cuDNN handle was used after the CUDA device was reset.

generic

官方文档

https://docs.nvidia.com/deeplearning/cudnn/api/index.html

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 90% 失败

    Calling torch.cuda.empty_cache() does not reinitialize cuDNN and may cause further issues.

  2. 85% 失败

    Reinstalling PyTorch or cuDNN without addressing the CUDA context issue will not fix the problem.