{
  "id": "pytorch/tensor-requires-grad-and-optimizer-param-group",
  "signature": "RuntimeError: parameter group's learning rate is not a float or a tensor of scalar type",
  "signature_zh": "RuntimeError: 参数组的学习率不是浮点数或标量张量",
  "regex": "RuntimeError: parameter group's learning rate is not a float or a tensor of scalar type",
  "domain": "pytorch",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Passing a non-float or non-scalar tensor as learning rate in optimizer parameter groups, often due to using a list or array instead of a single value.",
  "root_cause_type": "generic",
  "root_cause_zh": "在优化器参数组中将非浮点数或非标量张量作为学习率传递，通常是因为使用了列表或数组而不是单个值。",
  "versions": [
    {
      "version": "1.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This only changes the data type but doesn't fix the root cause if the value is still a collection.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This may hide the error but leads to unexpected behavior if the list is not reduced.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure each parameter group's 'lr' is a single float or a torch scalar tensor. For example, when creating optimizer with per-parameter options, use a float value directly.",
      "success_rate": 0.85,
      "how": "Ensure each parameter group's 'lr' is a single float or a torch scalar tensor. For example, when creating optimizer with per-parameter options, use a float value directly.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using a learning rate scheduler that returns a tensor, convert it to a float before assigning to param_groups.",
      "success_rate": 0.8,
      "how": "If using a learning rate scheduler that returns a tensor, convert it to a float before assigning to param_groups.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure each parameter group's 'lr' is a single float or a torch scalar tensor. For example, when creating optimizer with per-parameter options, use a float value directly.",
    "If using a learning rate scheduler that returns a tensor, convert it to a float before assigning to param_groups."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/optim.html#per-parameter-options",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.75,
  "resolvable": "true",
  "first_seen": "2023-08-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}