rohitg00/ai-engineering-from-scratch · error · SystemExit
torch is required for this lesson. Install with: pip install
Error message
torch is required for this lesson. Install with: pip install torch
What it means
Error "torch is required for this lesson. Install with: pip install torch" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/19-capstone-projects/45-gradient-clipping-amp/code/main.py:29
The demo at the bottom trains a small torch.nn.Linear model for 20 steps and
injects a non-finite gradient on a specific step to exercise the skip path.
Run: python3 code/main.py
"""
from __future__ import annotations
import csv
import math
import sys
from dataclasses import asdict, dataclass, field
from pathlib import Path
from typing import Callable, Iterable
try:
import torch
from torch import nn
except ImportError as exc:
raise SystemExit(
"torch is required for this lesson. Install with: pip install torch"
) from exc
DEFAULT_MAX_NORM = 1.0
DEFAULT_DEVICE = "cpu"
NORM_TYPE = 2.0
@dataclass
class StepLog:
"""One row of the per-step training log."""
step: int
lr: float
grad_l2_pre_clip: float
grad_l2_post_clip: float
loss: floatView on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/19-capstone-projects/45-gradient-clipping-amp/code/main.py:29 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/2ff98c66d0430601.
Report an issue: GitHub.