{
  "id": "cuda/cudnn-bn-epsilon-too-small",
  "signature": "RuntimeError: cuDNN error: CUDNN_STATUS_BAD_PARAM when calling cudnnBatchNormalizationForwardTraining with epsilon=1e-06",
  "signature_zh": "运行时错误：cuDNN 错误：调用 cudnnBatchNormalizationForwardTraining 时返回 CUDNN_STATUS_BAD_PARAM，epsilon=1e-06",
  "regex": "CUDNN_STATUS_BAD_PARAM when calling cudnnBatchNormalizationForwardTraining",
  "domain": "cuda",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "cuDNN batch normalization requires epsilon to be at least 1e-5 (or higher for certain data types like float16) to avoid numerical instability; a value of 1e-6 is too small and triggers a BAD_PARAM error.",
  "root_cause_type": "generic",
  "root_cause_zh": "cuDNN 批量归一化要求 epsilon 至少为 1e-5（对于 float16 等某些数据类型要求更高），以避免数值不稳定；1e-6 的值太小，会触发 BAD_PARAM 错误。",
  "versions": [
    {
      "version": "cuDNN 8.9.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cuDNN 9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PyTorch 2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PyTorch 2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "While it avoids the BAD_PARAM error, a large epsilon reduces the effectiveness of batch normalization, potentially degrading model accuracy.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This works but disables all cuDNN optimizations, significantly slowing down training. It's an overreaction if only the epsilon is wrong.",
      "fail_rate": 0.1,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error halts execution immediately; ignoring it is not possible without modifying the source code to catch the exception.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set epsilon to a value >= 1e-5. In PyTorch: nn.BatchNorm2d(num_features, eps=1e-5). For float16 models, use eps=1e-4 or higher. This is the recommended fix.",
      "success_rate": 0.95,
      "how": "Set epsilon to a value >= 1e-5. In PyTorch: nn.BatchNorm2d(num_features, eps=1e-5). For float16 models, use eps=1e-4 or higher. This is the recommended fix.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using a pre-trained model with a hardcoded epsilon, override it after loading: model.bn_layer.eps = 1e-5. Then reinitialize the batch norm statistics if needed.",
      "success_rate": 0.9,
      "how": "If using a pre-trained model with a hardcoded epsilon, override it after loading: model.bn_layer.eps = 1e-5. Then reinitialize the batch norm statistics if needed.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Convert the model to use float32 for batch normalization layers only: model.bn_layer = model.bn_layer.float(). This allows smaller epsilon values but may increase memory usage.",
      "success_rate": 0.7,
      "how": "Convert the model to use float32 for batch normalization layers only: model.bn_layer = model.bn_layer.float(). This allows smaller epsilon values but may increase memory usage.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "将 epsilon 设置为 >= 1e-5 的值。在 PyTorch 中：nn.BatchNorm2d(num_features, eps=1e-5)。对于 float16 模型，使用 eps=1e-4 或更高。这是推荐的修复方法。",
    "如果使用硬编码 epsilon 的预训练模型，请在加载后覆盖它：model.bn_layer.eps = 1e-5。然后根据需要重新初始化批量归一化统计信息。",
    "仅将批量归一化层转换为 float32：model.bn_layer = model.bn_layer.float()。这允许使用较小的 epsilon 值，但可能会增加内存使用量。"
  ],
  "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",
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.92,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}