{"record":{"id":"05ea57f479a730af","repo":"karpathy/nanochat","slug":"no-checkpoints-found-in-checkpoints-dir","errorCode":null,"errorMessage":"No checkpoints found in {checkpoints_dir}","messagePattern":"No checkpoints found in (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"nanochat/checkpoint_manager.py","lineNumber":121,"sourceCode":"    model.init_weights() # note: this is dumb, but we need to init the rotary embeddings. TODO: fix model re-init\n    model.load_state_dict(model_data, strict=True, assign=True)\n    # Put the model in the right training phase / mode\n    if phase == \"eval\":\n        model.eval()\n    else:\n        model.train()\n    # Load the Tokenizer\n    tokenizer = get_tokenizer()\n    # Sanity check: compatibility between model and tokenizer\n    assert tokenizer.get_vocab_size() == model_config_kwargs[\"vocab_size\"], f\"Tokenizer vocab size {tokenizer.get_vocab_size()} does not match model config vocab size {model_config_kwargs['vocab_size']}\"\n    return model, tokenizer, meta_data\n\n\ndef find_largest_model(checkpoints_dir):\n    # attempt to guess the model tag: take the biggest model available\n    model_tags = [f for f in os.listdir(checkpoints_dir) if os.path.isdir(os.path.join(checkpoints_dir, f))]\n    if not model_tags:\n        raise FileNotFoundError(f\"No checkpoints found in {checkpoints_dir}\")\n    # 1) normally all model tags are of the form d<number>, try that first:\n    candidates = []\n    for model_tag in model_tags:\n        match = re.match(r\"d(\\d+)\", model_tag)\n        if match:\n            model_depth = int(match.group(1))\n            candidates.append((model_depth, model_tag))\n    if candidates:\n        candidates.sort(key=lambda x: x[0], reverse=True)\n        return candidates[0][1]\n    # 2) if that failed, take the most recently updated model:\n    model_tags.sort(key=lambda x: os.path.getmtime(os.path.join(checkpoints_dir, x)), reverse=True)\n    return model_tags[0]\n\n\ndef find_last_step(checkpoint_dir):\n    # Look into checkpoint_dir and find model_<step>.pt with the highest step\n    checkpoint_files = [f for f in os.listdir(checkpoint_dir) if re.search(r'model_(\\d+)\\.pt$', f)]","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/karpathy/nanochat/blob/92d63d4e8bb4df75c3b71618f31ddde2378b2bcd/nanochat/checkpoint_manager.py#L103-L139","documentation":"`find_largest_model(checkpoints_dir)` lists the subdirectories of the checkpoints directory (each expected to be a model tag like 'd12', 'd24'). If the directory exists but contains no subdirectories, `model_tags` is empty and FileNotFoundError is raised. This function auto-guesses which model to load when no explicit model_tag is given.","triggerScenarios":"Calling `load_model_fromdir(...)` (or `find_largest_model` directly) with a checkpoints_dir that is empty, contains only files (no subdirectories), or pointing at the wrong path (e.g. the log dir instead of the checkpoints dir).","commonSituations":"Running an eval/inference script before any training checkpoints were written; wrong --source or checkpoints path; checkpoints deleted or moved after training; a fresh clone where 'assets/' checkpoints were never downloaded/synced.","solutions":["Verify the checkpoints directory actually contains model tag subdirectories (e.g. assets/checkpoints/d24/) — list it with `ls <checkpoints_dir>`.","Pass an explicit `model_tag=` to load_model_fromdir if auto-discovery is not wanted.","If checkpoints are missing, retrain or copy/sync the checkpoint assets to the expected location.","Check the script's CLI argument for the checkpoints path (e.g. -i sft|rl selects which subdir is used) and correct it."],"exampleFix":"# before\nmodel, tokenizer, meta = load_model_from_dir(\"assets/checkpoints\", device, \"sft\")  # dir empty\n\n# after\n# ensure a model tag dir exists, or name one explicitly\nmodel, tokenizer, meta = load_model_from_dir(\"assets/checkpoints\", device, \"sft\", model_tag=\"d24\")","handlingStrategy":"validation","validationCode":"import os\nmodel_tags = [f for f in os.listdir(checkpoints_dir) if os.path.isdir(os.path.join(checkpoints_dir, f))]\nif not model_tags:\n    raise SystemExit(f\"{checkpoints_dir} has no model tag subdirectories; train first or sync assets.\")","typeGuard":null,"tryCatchPattern":"try:\n    model_tag = find_largest_model(checkpoints_dir)\nexcept FileNotFoundError:\n    print(f\"No checkpoints under {checkpoints_dir}; falling back to prompting for an explicit path\")\n    raise","preventionTips":["Verify the checkpoints dir contains model-tag subdirectories (ls) before launching eval scripts.","Pass model_tag explicitly in automation instead of relying on auto-discovery.","Standardize on the d<number> tag naming so depth-based selection works."],"tags":["nanochat","checkpoints","filesystem","model-loading"],"backgroundTag":null,"analyzedSha":"92d63d4e8bb4df75c3b71618f31ddde2378b2bcd","analyzedAt":"2026-08-15T03:11:54.371Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}