{"record":{"id":"9a1d451e8a761ee6","repo":"rohitg00/ai-engineering-from-scratch","slug":"lr-max-must-be-positive","errorCode":null,"errorMessage":"lr_max must be positive","messagePattern":"lr_max must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py","lineNumber":62,"sourceCode":"    step zero the rate is exactly zero (the warmup ramp starts there). At\n    step warmup_steps the rate is exactly lr_max. At step total_steps the\n    rate is exactly lr_min. Past total_steps the rate stays at lr_min.\n    \"\"\"\n\n    warmup_steps: int\n    total_steps: int\n    lr_max: float\n    lr_min: float = 0.0\n\n    def __post_init__(self) -> None:\n        if self.warmup_steps < 0:\n            raise ValueError(\"warmup_steps must be non-negative\")\n        if self.total_steps <= 0:\n            raise ValueError(\"total_steps must be positive\")\n        if self.warmup_steps >= self.total_steps:\n            raise ValueError(\"warmup_steps must be less than total_steps\")\n        if self.lr_max <= 0:\n            raise ValueError(\"lr_max must be positive\")\n        if self.lr_min < 0:\n            raise ValueError(\"lr_min must be non-negative\")\n        if self.lr_min > self.lr_max:\n            raise ValueError(\"lr_min must not exceed lr_max\")\n\n    def lr(self, step: int) -> float:\n        if step < 0:\n            raise ValueError(f\"step must be non-negative, got {step}\")\n        if self.warmup_steps > 0 and step <= self.warmup_steps:\n            return self.lr_max * (step / self.warmup_steps)\n        if step >= self.total_steps:\n            return self.lr_min\n        decay_span = max(1, self.total_steps - self.warmup_steps)\n        progress = (step - self.warmup_steps) / decay_span\n        cosine = 0.5 * (1.0 + math.cos(math.pi * progress))\n        return self.lr_min + (self.lr_max - self.lr_min) * cosine\n\n    def points(self, num_steps: int | None = None) -> list[tuple[int, float]]:","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py#L44-L80","documentation":"Error \"lr_max must be positive\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py:62 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}