{
  "id": "huggingface/trainer-callback-hook-failure",
  "signature": "RuntimeError: Trainer callback hook 'on_log' failed with AttributeError: 'NoneType' object has no attribute 'step'",
  "signature_zh": "运行时错误：训练器回调钩子'on_log'失败，属性错误：'NoneType'对象没有属性'step'",
  "regex": "RuntimeError: Trainer callback hook 'on_log' failed with AttributeError: 'NoneType' object has no attribute 'step'",
  "domain": "huggingface",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A custom callback's on_log method attempts to access trainer.state.global_step before the trainer state is fully initialized, typically when logging occurs during the first step.",
  "root_cause_type": "generic",
  "root_cause_zh": "自定义回调的on_log方法在训练器状态完全初始化之前尝试访问trainer.state.global_step，通常发生在第一步记录日志时。",
  "versions": [
    {
      "version": "transformers>=4.35.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The root cause is accessing state before initialization; moving to another callback may still encounter the same issue if state is not ready.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This only postpones the error; it will still occur at the first log event regardless of step count.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is raised by the Trainer's callback execution wrapper; catching it inside the callback does not prevent the Trainer from propagating it.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add a guard in the callback to check if trainer.state is initialized: `if trainer.state.global_step is not None:` before accessing step.",
      "success_rate": 0.95,
      "how": "Add a guard in the callback to check if trainer.state is initialized: `if trainer.state.global_step is not None:` before accessing step.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Override the on_step_begin callback instead of on_log, as state is guaranteed to be initialized at step start.",
      "success_rate": 0.85,
      "how": "Override the on_step_begin callback instead of on_log, as state is guaranteed to be initialized at step start.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Initialize the callback with a default step value: `self.step = 0` in __init__, then use self.step instead of trainer.state.global_step.",
      "success_rate": 0.9,
      "how": "Initialize the callback with a default step value: `self.step = 0` in __init__, then use self.step instead of trainer.state.global_step.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Add a guard in the callback to check if trainer.state is initialized: `if trainer.state.global_step is not None:` before accessing step.",
    "Override the on_step_begin callback instead of on_log, as state is guaranteed to be initialized at step start.",
    "Initialize the callback with a default step value: `self.step = 0` in __init__, then use self.step instead of trainer.state.global_step."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/main/en/main_classes/callback",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}