karpathy/nanochat · error · FileNotFoundError

No checkpoints found in {checkpoint_dir}

Error message

No checkpoints found in {checkpoint_dir}

What it means

`find_last_step(checkpoint_dir)` scans a single model-tag directory for files matching `model_<step>.pt` and returns the highest step. If none match — the directory is empty or contains only optimizer/meta files — FileNotFoundError is raised. This value is used to resume/load the latest checkpoint of a chosen model.

Source

Thrown at nanochat/checkpoint_manager.py:141

    candidates = []
    for model_tag in model_tags:
        match = re.match(r"d(\d+)", model_tag)
        if match:
            model_depth = int(match.group(1))
            candidates.append((model_depth, model_tag))
    if candidates:
        candidates.sort(key=lambda x: x[0], reverse=True)
        return candidates[0][1]
    # 2) if that failed, take the most recently updated model:
    model_tags.sort(key=lambda x: os.path.getmtime(os.path.join(checkpoints_dir, x)), reverse=True)
    return model_tags[0]


def find_last_step(checkpoint_dir):
    # Look into checkpoint_dir and find model_<step>.pt with the highest step
    checkpoint_files = [f for f in os.listdir(checkpoint_dir) if re.search(r'model_(\d+)\.pt$', f)]
    if not checkpoint_files:
        raise FileNotFoundError(f"No checkpoints found in {checkpoint_dir}")
    last_step = max(int(f.split("_")[-1].split(".")[0]) for f in checkpoint_files)
    return last_step

# -----------------------------------------------------------------------------
# convenience functions that take into account nanochat's directory structure

def load_model_from_dir(checkpoints_dir, device, phase, model_tag=None, step=None):
    if model_tag is None:
        # guess the model tag by defaulting to the largest model
        model_tag = find_largest_model(checkpoints_dir)
        log0(f"No model tag provided, guessing model tag: {model_tag}")
    checkpoint_dir = os.path.join(checkpoints_dir, model_tag)
    if step is None:
        # guess the step by defaulting to the last step
        step = find_last_step(checkpoint_dir)
    assert step is not None, f"No checkpoints found in {checkpoint_dir}"
    # build the model
    log0(f"Loading model from {checkpoint_dir} with step {step}")

View on GitHub (pinned to 92d63d4e8b)

Solutions

  1. List the model-tag directory and confirm at least one file named like `model_0001234.pt` exists.
  2. If only optimizer/meta files remain, restore the matching model_*.pt from backup or restart training.
  3. Make sure you pass the model-tag subdirectory (e.g. assets/checkpoints/d24), not the parent checkpoints dir (which contains no model files and would also trip this error).

Example fix

# before
step = find_last_step("assets/checkpoints")  # wrong level: no model_*.pt here

# after
step = find_last_step("assets/checkpoints/d24")  # dir containing model_0001234.pt
Defensive patterns

Strategy: validation

Validate before calling

import os, re
ckpts = [f for f in os.listdir(checkpoint_dir) if re.search(r'model_(\d+)\.pt$', f)]
if not ckpts:
    raise SystemExit(f"No model_<step>.pt files in {checkpoint_dir}; cannot resume.")
last_step = max(int(f.split('_')[-1].split('.')[0]) for f in ckpts)

Try / catch

try:
    step = find_last_step(checkpoint_dir)
except FileNotFoundError:
    print("No model checkpoints; starting from scratch or aborting")
    raise

Prevention

When it happens

Trigger: Calling `find_last_step` on a model-tag directory with no `model_*.pt` files: training crashed before the first checkpoint save, checkpoints were partially cleaned, or the path points to a directory holding only `optimizer_<step>.pt`/meta files.

Common situations: A training run interrupted before its first periodic save; someone deleted the .pt model files but left other artifacts; passing the parent checkpoints dir instead of the model-tag subdir.

Related errors


AI-assisted analysis of karpathy/nanochat@92d63d4e8b (2026-08-15). Data as JSON: /api/errors/6598cefba52da822. Report an issue: GitHub.