{"record":{"id":"704d583454d69651","repo":"meta-llama/llama","slug":"no-checkpoint-files-found-in-ckpt-dir","errorCode":null,"errorMessage":"no checkpoint files found in {ckpt_dir}","messagePattern":"no checkpoint files found in (.+?)","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"critical","filePath":"llama/generation.py","lineNumber":102,"sourceCode":"        if not torch.distributed.is_initialized():\n            torch.distributed.init_process_group(\"nccl\")\n        if not model_parallel_is_initialized():\n            if model_parallel_size is None:\n                model_parallel_size = int(os.environ.get(\"WORLD_SIZE\", 1))\n            initialize_model_parallel(model_parallel_size)\n\n        local_rank = int(os.environ.get(\"LOCAL_RANK\", 0))\n        torch.cuda.set_device(local_rank)\n\n        # seed must be the same in all processes\n        torch.manual_seed(seed)\n\n        if local_rank > 0:\n            sys.stdout = open(os.devnull, \"w\")\n\n        start_time = time.time()\n        checkpoints = sorted(Path(ckpt_dir).glob(\"*.pth\"))\n        assert len(checkpoints) > 0, f\"no checkpoint files found in {ckpt_dir}\"\n        assert model_parallel_size == len(\n            checkpoints\n        ), f\"Loading a checkpoint for MP={len(checkpoints)} but world size is {model_parallel_size}\"\n        ckpt_path = checkpoints[get_model_parallel_rank()]\n        checkpoint = torch.load(ckpt_path, map_location=\"cpu\")\n        with open(Path(ckpt_dir) / \"params.json\", \"r\") as f:\n            params = json.loads(f.read())\n\n        model_args: ModelArgs = ModelArgs(\n            max_seq_len=max_seq_len,\n            max_batch_size=max_batch_size,\n            **params,\n        )\n        tokenizer = Tokenizer(model_path=tokenizer_path)\n        model_args.vocab_size = tokenizer.n_words\n        torch.set_default_tensor_type(torch.cuda.HalfTensor)\n        model = Transformer(model_args)\n        model.load_state_dict(checkpoint, strict=False)","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/meta-llama/llama/blob/689c7f261b9c5514636ecc3c5fefefcbb3e6eed7/llama/generation.py#L84-L120","documentation":"This assertion in Llama.build (llama/generation.py:102) fires when Path(ckpt_dir).glob('*.pth') returns no files, i.e. the checkpoint directory exists (or the path is simply wrong) but contains zero .pth shards. Llama 2 weights ship as consolidated shard files (consolidated.00.pth, consolidated.01.pth, ...) plus params.json, and build refuses to continue without them.","triggerScenarios":"Calling Llama.build(ckpt_dir=..., tokenizer_path=..., ...) where ckpt_dir contains no *.pth files: a typo'd/nonexistent path, a directory holding only .safetensors weights (newer releases) or only params.json/tokenizer.model, or a download that was interrupted before the shards landed.","commonSituations":"- Downloading Meta's weights via the official download.sh and pointing at the wrong subdirectory (e.g. llama-2-7b/ instead of the dir that actually holds consolidated.00.pth).\n- Mixing generations of the repo: newer llama-models checkpoints use .safetensors, this codebase only globs *.pth.\n- Incomplete download, or files renamed (e.g. still zipped, or extension .pt).\n- Container/HPC jobs where the mount path for the weights differs from the host path.","solutions":["Verify the directory actually contains the shards: ls -la <ckpt_dir> and confirm consolidated.00.pth (etc.) are present","Fix the path — it must be the directory containing the .pth files themselves, not a parent such as the repo's llama-2-7b/ folder","If weights are .safetensors, either re-download the .pth distribution or convert/rename via the appropriate script from the llama-models repo","Re-run download.sh / re-download if the shards are truncated or missing; check file sizes against the published checksums"],"exampleFix":"# before\nllama = Llama.build(ckpt_dir=\"./llama-2-7b\", ...)  # dir without .pth files\n\n# after  (point at the shard directory, e.g. after download.sh)\n# ./llama-2-7b/consolidated.00.pth  -> ckpt_dir must be that folder\nllama = Llama.build(ckpt_dir=\"./llama-2-7b\", ...)\n# shell check first:\n# ls ./llama-2-7b/*.pth   # must list consolidated.00.pth ...","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef checkpoint_dir_is_valid(ckpt_dir: str) -> bool:\n    p = Path(ckpt_dir)\n    return p.is_dir() and len(list(p.glob(\"*.pth\"))) > 0 and (p / \"params.json\").is_file()\n\n# before calling:\nassert checkpoint_dir_is_valid(ckpt_dir), f\"{ckpt_dir} lacks *.pth shards or params.json\"","typeGuard":"from pathlib import Path\n\ndef has_pth_shards(ckpt_dir: str) -> bool:\n    return any(Path(ckpt_dir).glob(\"*.pth\"))","tryCatchPattern":"try:\n    llama = Llama.build(ckpt_dir=ckpt_dir, tokenizer_path=tok, max_seq_len=512, max_batch_size=8)\nexcept AssertionError as e:\n    if \"no checkpoint files found\" in str(e):\n        raise FileNotFoundError(\n            f\"{ckpt_dir} has no .pth shards; run download.sh and point ckpt_dir at the shard folder\"\n        ) from e\n    raise","preventionTips":["Check `ls ckpt_dir/*.pth` and params.json exist before startup; fail fast with a clear message","Automate downloads with the official download.sh and verify shard counts/sizes against the download manifest","Pin one checkpoint format — this code only reads .pth, so don't mix in .safetensors releases"],"tags":["llama","checkpoint","file-not-found","model-loading"],"backgroundTag":null,"analyzedSha":"689c7f261b9c5514636ecc3c5fefefcbb3e6eed7","analyzedAt":"2026-08-15T02:36:29.698Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}