meta-llama/llama · critical · AssertionError

no checkpoint files found in {ckpt_dir}

Error message

no checkpoint files found in {ckpt_dir}

What it means

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.

Source

Thrown at llama/generation.py:102

        if not torch.distributed.is_initialized():
            torch.distributed.init_process_group("nccl")
        if not model_parallel_is_initialized():
            if model_parallel_size is None:
                model_parallel_size = int(os.environ.get("WORLD_SIZE", 1))
            initialize_model_parallel(model_parallel_size)

        local_rank = int(os.environ.get("LOCAL_RANK", 0))
        torch.cuda.set_device(local_rank)

        # seed must be the same in all processes
        torch.manual_seed(seed)

        if local_rank > 0:
            sys.stdout = open(os.devnull, "w")

        start_time = time.time()
        checkpoints = sorted(Path(ckpt_dir).glob("*.pth"))
        assert len(checkpoints) > 0, f"no checkpoint files found in {ckpt_dir}"
        assert model_parallel_size == len(
            checkpoints
        ), f"Loading a checkpoint for MP={len(checkpoints)} but world size is {model_parallel_size}"
        ckpt_path = checkpoints[get_model_parallel_rank()]
        checkpoint = torch.load(ckpt_path, map_location="cpu")
        with open(Path(ckpt_dir) / "params.json", "r") as f:
            params = json.loads(f.read())

        model_args: ModelArgs = ModelArgs(
            max_seq_len=max_seq_len,
            max_batch_size=max_batch_size,
            **params,
        )
        tokenizer = Tokenizer(model_path=tokenizer_path)
        model_args.vocab_size = tokenizer.n_words
        torch.set_default_tensor_type(torch.cuda.HalfTensor)
        model = Transformer(model_args)
        model.load_state_dict(checkpoint, strict=False)

View on GitHub (pinned to 689c7f261b)

Solutions

  1. Verify the directory actually contains the shards: ls -la <ckpt_dir> and confirm consolidated.00.pth (etc.) are present
  2. 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
  3. If weights are .safetensors, either re-download the .pth distribution or convert/rename via the appropriate script from the llama-models repo
  4. Re-run download.sh / re-download if the shards are truncated or missing; check file sizes against the published checksums

Example fix

# before
llama = Llama.build(ckpt_dir="./llama-2-7b", ...)  # dir without .pth files

# after  (point at the shard directory, e.g. after download.sh)
# ./llama-2-7b/consolidated.00.pth  -> ckpt_dir must be that folder
llama = Llama.build(ckpt_dir="./llama-2-7b", ...)
# shell check first:
# ls ./llama-2-7b/*.pth   # must list consolidated.00.pth ...
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def checkpoint_dir_is_valid(ckpt_dir: str) -> bool:
    p = Path(ckpt_dir)
    return p.is_dir() and len(list(p.glob("*.pth"))) > 0 and (p / "params.json").is_file()

# before calling:
assert checkpoint_dir_is_valid(ckpt_dir), f"{ckpt_dir} lacks *.pth shards or params.json"

Type guard

from pathlib import Path

def has_pth_shards(ckpt_dir: str) -> bool:
    return any(Path(ckpt_dir).glob("*.pth"))

Try / catch

try:
    llama = Llama.build(ckpt_dir=ckpt_dir, tokenizer_path=tok, max_seq_len=512, max_batch_size=8)
except AssertionError as e:
    if "no checkpoint files found" in str(e):
        raise FileNotFoundError(
            f"{ckpt_dir} has no .pth shards; run download.sh and point ckpt_dir at the shard folder"
        ) from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: - 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). - Mixing generations of the repo: newer llama-models checkpoints use .safetensors, this codebase only globs *.pth. - Incomplete download, or files renamed (e.g. still zipped, or extension .pt). - Container/HPC jobs where the mount path for the weights differs from the host path.

Related errors


AI-assisted analysis of meta-llama/llama@689c7f261b (2026-08-15). Data as JSON: /api/errors/704d583454d69651. Report an issue: GitHub.