{"record":{"id":"768ded0855269aa3","repo":"rohitg00/ai-engineering-from-scratch","slug":"warmup-steps-must-be-non-negative","errorCode":null,"errorMessage":"warmup_steps must be non-negative","messagePattern":"warmup_steps must be non-negative","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py","lineNumber":56,"sourceCode":"\n@dataclass\nclass CosineWithWarmup:\n    \"\"\"Stateless cosine-with-warmup learning-rate schedule.\n\n    Step indexing convention: step zero is the very first training update. At\n    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","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py#L38-L74","documentation":"CosineWithWarmup post-init guard: warmup_steps was negative, which is meaningless for a ramp that starts at zero and reaches lr_max after that many steps.","triggerScenarios":"Thrown at phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a non-negative warmup_steps (0 for no warmup)","Validate schedule hyperparameters from config before constructing the dataclass"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}