{
  "id": "cuda/cudnn-bn-epsilon-negative",
  "signature": "RuntimeError: cuDNN error: CUDNN_STATUS_BAD_PARAM when calling cudnnBatchNormalizationForwardTraining with epsilon < 0",
  "signature_zh": "RuntimeError: 调用 cudnnBatchNormalizationForwardTraining 时出现 cuDNN 错误：CUDNN_STATUS_BAD_PARAM，epsilon < 0",
  "regex": "CUDNN_STATUS_BAD_PARAM.*cudnnBatchNormalization.*epsilon",
  "domain": "cuda",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "cuDNN batch normalization routines require epsilon >= 0 (typically a small positive value, e.g., 1e-5); a negative epsilon violates the mathematical definition of batch normalization and cuDNN rejects it as a bad parameter.",
  "root_cause_type": "generic",
  "root_cause_zh": "cuDNN 批归一化例程要求 epsilon >= 0（通常为小的正值，如 1e-5）；负 epsilon 违反批归一化的数学定义，cuDNN 将其作为错误参数拒绝。",
  "versions": [
    {
      "version": "cuDNN 8.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cuDNN 9.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Setting epsilon to a very large value (e.g., 1.0) causes numerical instability (division by sqrt(var+1.0) ~ 1) and poor training accuracy, but cuDNN does not error out; this masks the real issue.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disabling cuDNN batch normalization (torch.backends.cudnn.enabled=False) forces a fallback to PyTorch's own implementation, which may accept negative epsilon but produces incorrect gradients.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure epsilon is a small positive float, typically 1e-5. Example: if (epsilon < 0) epsilon = 1e-5;",
      "success_rate": 0.95,
      "how": "Ensure epsilon is a small positive float, typically 1e-5. Example: if (epsilon < 0) epsilon = 1e-5;",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a validation check before the cuDNN call to clamp epsilon to a minimum positive value. Example: epsilon = max(epsilon, 1e-7);",
      "success_rate": 0.9,
      "how": "Add a validation check before the cuDNN call to clamp epsilon to a minimum positive value. Example: epsilon = max(epsilon, 1e-7);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure epsilon is a small positive float, typically 1e-5. Example: if (epsilon < 0) epsilon = 1e-5;",
    "Add a validation check before the cuDNN call to clamp epsilon to a minimum positive value. Example: epsilon = max(epsilon, 1e-7);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.nvidia.com/deeplearning/cudnn/api/index.html#cudnnBatchNormalizationForwardTraining",
  "official_doc_section": null,
  "error_code": "CUDNN_STATUS_BAD_PARAM (4)",
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.93,
  "resolvable": "true",
  "first_seen": "2023-05-08",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}