{
  "id": "pytorch/cudnn-benchmark-algo-failure",
  "signature": "RuntimeError: cuDNN error: CUDNN_STATUS_BAD_PARAM when calling cudnnSetRNNDescriptor_v8",
  "signature_zh": "RuntimeError: cuDNN 错误：调用 cudnnSetRNNDescriptor_v8 时出现 CUDNN_STATUS_BAD_PARAM",
  "regex": "RuntimeError: cuDNN error: CUDNN_STATUS_BAD_PARAM when calling cudnnSetRNNDescriptor_v8",
  "domain": "pytorch",
  "category": "runtime_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "在启用 torch.backends.cudnn.benchmark 的情况下，RNN 使用了 cuDNN 启发式搜索不支持的隐藏层大小或层数，导致 RNN 描述符初始化参数无效。",
  "versions": [
    {
      "version": "PyTorch 2.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PyTorch 2.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cuDNN 8.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CUDA 11.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Upgrading PyTorch alone does not fix the cuDNN parameter validation; the root cause is the RNN configuration, not the library version.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Setting torch.backends.cudnn.deterministic = True does not prevent the benchmark from running the failing heuristic; it only affects algorithm selection.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing batch size does not affect the RNN descriptor parameters (hidden_size, num_layers), so the error persists.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Disable cuDNN benchmark: torch.backends.cudnn.benchmark = False. Also, set torch.backends.cudnn.enabled = False as a fallback if the error persists.",
      "success_rate": 0.75,
      "how": "Disable cuDNN benchmark: torch.backends.cudnn.benchmark = False. Also, set torch.backends.cudnn.enabled = False as a fallback if the error persists.",
      "condition": "",
      "sources": []
    },
    {
      "action": "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).",
      "success_rate": 0.85,
      "how": "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).",
      "condition": "",
      "sources": []
    },
    {
      "action": "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.",
      "success_rate": 0.7,
      "how": "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.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "禁用 cuDNN 基准测试：torch.backends.cudnn.benchmark = False。如果错误仍然存在，可进一步设置 torch.backends.cudnn.enabled = False。",
    "使用能被 64 整除的隐藏层大小（如 256 而非 250），并确保 num_layers <= 8。示例：model = nn.LSTM(input_size=128, hidden_size=256, num_layers=2, batch_first=True)。",
    "在模型创建前设置 torch.backends.cudnn.enabled = False，强制使用 PyTorch 原生 RNN 实现，避免 cuDNN 内核。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/notes/cuda.html#cudnn-benchmark",
  "official_doc_section": null,
  "error_code": "CUDNN_STATUS_BAD_PARAM",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}