rohitg00/ai-engineering-from-scratch · error · ValueError
step must be non-negative, got {step}
Error message
step must be non-negative, got {step} What it means
Error "step must be non-negative, got {step}" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py:70
lr_min: float = 0.0
def __post_init__(self) -> None:
if self.warmup_steps < 0:
raise ValueError("warmup_steps must be non-negative")
if self.total_steps <= 0:
raise ValueError("total_steps must be positive")
if self.warmup_steps >= self.total_steps:
raise ValueError("warmup_steps must be less than total_steps")
if self.lr_max <= 0:
raise ValueError("lr_max must be positive")
if self.lr_min < 0:
raise ValueError("lr_min must be non-negative")
if self.lr_min > self.lr_max:
raise ValueError("lr_min must not exceed lr_max")
def lr(self, step: int) -> float:
if step < 0:
raise ValueError(f"step must be non-negative, got {step}")
if self.warmup_steps > 0 and step <= self.warmup_steps:
return self.lr_max * (step / self.warmup_steps)
if step >= self.total_steps:
return self.lr_min
decay_span = max(1, self.total_steps - self.warmup_steps)
progress = (step - self.warmup_steps) / decay_span
cosine = 0.5 * (1.0 + math.cos(math.pi * progress))
return self.lr_min + (self.lr_max - self.lr_min) * cosine
def points(self, num_steps: int | None = None) -> list[tuple[int, float]]:
upper = self.total_steps if num_steps is None else num_steps
if upper <= 0:
return []
return [(step, self.lr(step)) for step in range(upper + 1)]
@dataclass
class StepLog:View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py:70 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/6e93d6740695a89c.
Report an issue: GitHub.