rohitg00/ai-engineering-from-scratch · error · ValueError

window must be positive

Error message

window must be positive

What it means

Error "window must be positive" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at phases/19-capstone-projects/45-gradient-clipping-amp/code/main.py:310

            SkipLog(
                step=self.global_step,
                reason=reason,
                pre_clip_norm=pre_clip,
                loss=loss_value,
                scaler_scale=float(self.scaler.get_scale()),
            )
        )
        self.global_step += 1
        if update_scaler:
            self.scaler.update()
        return record


def rolling_skip_rate(log: Iterable[StepLog], window: int = 1000) -> list[float]:
    """Return the rolling skip rate over the last `window` steps for each step."""

    if window <= 0:
        raise ValueError("window must be positive")
    rows = list(log)
    rates: list[float] = []
    skipped: list[int] = []
    for row in rows:
        skipped.append(1 if row.skipped else 0)
        if len(skipped) > window:
            skipped = skipped[-window:]
        rates.append(sum(skipped) / len(skipped))
    return rates


def write_step_log_csv(log: Iterable[StepLog], path: Path) -> None:
    """Write the canonical training-step CSV.

    Columns: step, lr, grad_l2_pre_clip, grad_l2_post_clip, loss, skipped,
    skip_reason, scaler_scale.
    """

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at phases/19-capstone-projects/45-gradient-clipping-amp/code/main.py:310 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/8c391c90d597ffdf. Report an issue: GitHub.