immich-app/immich · error · FileNotFoundError

Model file not found: {model_path}

Error message

Model file not found: {model_path}

What it means

Raised by InferenceModel._make_session when the resolved model_path does not point to a regular file. _make_session is invoked from _load() (called by load()), which runs after download() is supposed to have fetched the model from HuggingFace. The path is built by model_path_for_format() as cache_dir/<model_type>/model.<format> (plus an rknpu/<soc> prefix for RKNN), so the error means that expected artifact never materialized on disk.

Source

Thrown at machine-learning/immich_ml/models/base.py:109

        if not rmtree.avoids_symlink_attacks:
            raise RuntimeError("Attempted to clear cache, but rmtree is not safe on this platform")

        if self.cache_dir.is_dir():
            log.info(f"Cleared cache directory for model '{self.model_name}'.")
            rmtree(self.cache_dir)
        else:
            log.warning(
                (
                    f"Encountered file instead of directory at cache path "
                    f"for '{self.model_name}'. Removing file and replacing with a directory."
                ),
            )
            self.cache_dir.unlink()
        self.cache_dir.mkdir(parents=True, exist_ok=True)

    def _make_session(self, model_path: Path) -> ModelSession:
        if not model_path.is_file():
            raise FileNotFoundError(f"Model file not found: {model_path}")

        match model_path.suffix:
            case ".armnn":
                session: ModelSession = AnnSession(model_path)
            case ".onnx":
                session = OrtSession(model_path)
            case ".rknn":
                session = rknn.RknnSession(model_path)
            case _:
                raise ValueError(f"Unsupported model file type: {model_path.suffix}")
        return session

    def model_path_for_format(self, model_format: ModelFormat) -> Path:
        model_path_prefix = rknn.model_prefix if model_format == ModelFormat.RKNN else None
        if model_path_prefix:
            return self.model_dir / model_path_prefix / f"model.{model_format}"
        return self.model_dir / f"model.{model_format}"

View on GitHub (pinned to 199723261c)

Solutions

  1. Inspect the value of model_path in the error and list its parent directory to see what (if anything) was actually downloaded.
  2. Call model.clear_cache() then model.download() again to force a clean snapshot_download into the correct cache_dir.
  3. Verify settings.cache_folder and the cache_dir passed to the model resolve to the same writable path used by snapshot_download.
  4. Confirm model_format matches a file the HF repo ships (e.g. the ONNX variant) and that ignore_patterns for that format is not excluding it.
  5. Check HuggingFace connectivity / token and available disk space, then retry load().

Example fix

# before
model = InferenceModel('immich-app/X', model_format=ModelFormat.ARMNN)
model.load()  # FileNotFoundError: cache only has ONNX

# after
model = InferenceModel('immich-app/X', model_format=ModelFormat.ONNX)
model.clear_cache()
model.download()
model.load()
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def ensure_model_file(path: Path) -> None:
    if not path.is_file():
        available = sorted(p.name for p in path.parent.glob('*')) if path.parent.exists() else []
        raise FileNotFoundError(
            f"Expected model file {path} not found. Files in {path.parent}: {available}"
        )

# call before model.load():
ensure_model_file(model.model_path)

Type guard

from pathlib import Path

def is_model_file_present(model) -> bool:
    return isinstance(model.model_path, Path) and model.model_path.is_file()

Try / catch

try:
    model.load()
except FileNotFoundError as e:
    log.error("Model artifact missing at %s; clearing cache and re-downloading", model.model_path)
    model.clear_cache()
    model.download()
    model.load()  # single retry, not a loop

Prevention

When it happens

Trigger: Calling model.load() (or predict(), which auto-loads) when snapshot_download() was skipped, interrupted, filtered out the needed file, or wrote to a different cache_dir than model_path points to. Also triggered when model_format does not match the files the HF repo actually ships, or after clear_cache() removed the directory but it was not re-downloaded.

Common situations: Wrong cache_folder / cache_dir mismatch between download and load; HuggingFace rate-limit or network failure leaving a partial download; setting model_format to ARMNN/RKNN while the repo only has ONNX weights (the ignore_patterns filter then excludes everything); read-only or full volume where the file could not be written; manual deletion of files under the cache directory.

Related errors


AI-assisted analysis of immich-app/immich@199723261c (2026-08-12). Data as JSON: /api/errors/38a8f60effeaa52b. Report an issue: GitHub.