rohitg00/ai-engineering-from-scratch · error · ValueError
beta must be in (0, 1)
Error message
beta must be in (0, 1)
What it means
Error "beta must be in (0, 1)" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py:304
def lr(self, step: int) -> float:
if step < 0:
raise ValueError(f"step must be non-negative, got {step}")
if step <= self.warmup_steps:
return self.lr_max * (step / self.warmup_steps)
return self.lr_max * math.sqrt(self.warmup_steps / step)
@dataclass
class EWMA:
"""Exponentially weighted moving average of a scalar, useful for grad-norm smoothing."""
beta: float
value: float = 0.0
initialized: bool = False
def __post_init__(self) -> None:
if not 0 < self.beta < 1:
raise ValueError("beta must be in (0, 1)")
def update(self, sample: float) -> float:
if not self.initialized:
self.value = float(sample)
self.initialized = True
return self.value
self.value = self.beta * self.value + (1.0 - self.beta) * float(sample)
return self.value
@dataclass
class StepLogSummary:
"""Reduction of a per-step log to the numbers a reviewer scans first."""
steps: int
lr_peak: float
lr_final: float
grad_l2_peak: floatView on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/19-capstone-projects/44-cosine-lr-warmup/code/main.py:304 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/0b9a26dea57e03fb.
Report an issue: GitHub.