sgl-project/sglang · error · ValueError

Found {len(safetensors_files)} safetensors files in {model_p

Error message

Found {len(safetensors_files)} safetensors files in {model_path} and no index to disambiguate them.

What it means

Multiple .safetensors files exist in the directory but there is no index file (model.safetensors.index.json) saying how tensors map to shards, so the loader cannot decide which file to load. It refuses to guess because picking arbitrarily would yield wrong or partial weights.

Source

Thrown at python/sglang/multimodal_gen/runtime/loader/utils.py:351

    index_path = os.path.join(
        str(model_path), "diffusion_pytorch_model.safetensors.index.json"
    )
    safetensors_files = _list_safetensors_files(model_path)
    if os.path.exists(index_path):
        with open(index_path) as f:
            index = json.load(f)
        shard_names = sorted(set(index.get("weight_map", {}).values()))
        state_dict: dict[str, torch.Tensor] = {}
        for shard_name in shard_names:
            state_dict.update(
                safetensors_load_file(os.path.join(str(model_path), shard_name))
            )
        return state_dict

    if not safetensors_files:
        raise ValueError(f"No safetensors files found in {model_path}")
    if len(safetensors_files) != 1:
        raise ValueError(
            f"Found {len(safetensors_files)} safetensors files in {model_path} "
            "and no index to disambiguate them."
        )
    return safetensors_load_file(safetensors_files[0])


BYTES_PER_GB = 1024**3


def get_memory_usage_of_component(module) -> float | None:
    """
    returned value is in GB, rounded to 2 decimal digits
    """
    if not isinstance(module, nn.Module):
        return None
    if hasattr(module, "get_memory_footprint"):
        usage = module.get_memory_footprint() / BYTES_PER_GB
    else:

View on GitHub (pinned to 0132848349)

Solutions

  1. Point --model at a directory containing exactly one .safetensors file plus its index
  2. Remove/move the stray safetensors file that does not belong
  3. Re-download the full checkpoint so model.safetensors.index.json is restored

Example fix

# before
models/llama/ (model-00001-of-02.safetensors, model-00002-of-02.safetensors, stray.safetensors, no index)
# after
models/llama/ (model-00001-of-02.safetensors, model-00002-of-02.safetensors, model.safetensors.index.json)
Defensive patterns

Strategy: validation

Validate before calling

import glob, os

def unambiguous_checkpoint(model_path) -> bool:
    files = glob.glob(f"{model_path}/*.safetensors")
    return len(files) == 1 or os.path.exists(
        os.path.join(model_path, "model.safetensors.index.json")
    )

Prevention

When it happens

Trigger: load_safetensors_state_dict finds len(safetensors_files) > 1 and no disambiguating index.

Common situations: User drops an extra safetensors file (e.g. an fp8 variant or an adapter) into a single-shard model dir; downloaded a sharded model whose index file was skipped; consolidated + sharded files mixed.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/ab47482cf3060c4e. Report an issue: GitHub.