mudler/LocalAI · error · ValueError

no ONNX files in pack directory: {pack_dir}

Error message

no ONNX files in pack directory: {pack_dir}

What it means

Raised by the insightface engine constructor when the pack directory exists but contains zero *.onnx files after globbing (and after optional manifest scoping). The directory was found but is empty or holds only non-ONNX content, so there is nothing to feed model_zoo.get_model.

Source

Thrown at backend/python/insightface/engines.py:265

        onnx_files = sorted(glob.glob(os.path.join(pack_dir, "*.onnx")))
        # When the pack extracts flat into a shared models directory it
        # mixes with ONNX files from other backends (opencv face engine,
        # MiniFASNet antispoof, WeSpeaker voice embedding, other buffalo
        # packs installed earlier). Feeding those into model_zoo.get_model()
        # blows up inside insightface's router — it assumes a 4-D NCHW
        # input and indexes `input_shape[2]` on tensors that aren't shaped
        # like a face model, raising IndexError. For the upstream packs we
        # know the exact ONNX manifest; scoping to it makes the load
        # deterministic (without it, det_10g.onnx from buffalo_l sorts
        # before det_500m.onnx from buffalo_sc and silently wins).
        manifest = _KNOWN_PACK_MANIFESTS.get(self.model_pack)
        if manifest is not None:
            scoped = [f for f in onnx_files if os.path.basename(f) in manifest]
            if scoped:
                onnx_files = scoped
        if not onnx_files:
            raise ValueError(f"no ONNX files in pack directory: {pack_dir}")

        # CUDAExecutionProvider is picked automatically by onnxruntime-gpu
        # when available; falling back to CPU keeps the CPU-only image
        # working. ctx_id=0 means "first GPU if any, else CPU".
        self._providers = ["CUDAExecutionProvider", "CPUExecutionProvider"]

        self.models = {}
        skipped: list[tuple[str, str]] = []
        for onnx_file in onnx_files:
            try:
                m = model_zoo.get_model(onnx_file, providers=self._providers)
            except Exception as err:
                # Foreign ONNX (wrong rank/shape, non-insightface model) —
                # older insightface versions raise IndexError / ValueError
                # instead of returning None. Keep loading the rest.
                skipped.append((os.path.basename(onnx_file), str(err)))
                continue
            if m is None:

View on GitHub (pinned to 44413a9d06)

Solutions

  1. List the pack directory to confirm whether files are absent, misnamed, or filtered out by the manifest.
  2. Reinstall the pack (local-ai models install insightface-<pack>) to restore a complete extraction.
  3. If files exist but with unexpected names (upstream layout change), update the backend or file an issue so _KNOWN_PACK_MANIFESTS is extended.
  4. Ensure file extensions are lowercase .onnx and files are not hidden inside a nested subfolder the glob misses.
Defensive patterns

Strategy: validation

Validate before calling

import glob, os
onnx = sorted(glob.glob(os.path.join(pack_dir, "*.onnx")))
assert onnx, f"pack dir {pack_dir} has no ONNX files; reinstall the pack"

Type guard

def pack_has_onnx(pack_dir: str) -> bool:
    return bool(glob.glob(os.path.join(pack_dir, "*.onnx")))

Try / catch

try:
    engine = InsightFaceEngine(options)
except ValueError as e:
    if "no ONNX files" in str(e):
        # empty/filtered pack: reinstall is the deterministic fix
        reinstall_pack(options.get("model_pack", "buffalo_l"))
        engine = InsightFaceEngine(options)
    else:
        raise

Prevention

When it happens

Trigger: pack_dir resolves to an existing directory with no .onnx files — an aborted extraction that created the folder but not the files, files with wrong extensions/case, or the manifest scoping step filtering out every file because names don't match the known-pack manifest.

Common situations: Partial download/extraction of a pack archive, a pack layout change upstream renaming ONNX files so the _KNOWN_PACK_MANIFESTS filter excludes them all, or manual cleanup that deleted the ONNX weights.

Related errors


AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15). Data as JSON: /api/errors/ac964f68930d3edd. Report an issue: GitHub.