odysseus-dev/odysseus · error · HTTPException

Failed to load SAM model

Error message

Failed to load SAM model {model_id}: {exc}

What it means

Wrapper error in _load_sam_backend: loading the SAM processor/model weights via from_pretrained raised an exception (exc) — bad or missing checkpoint, OOM, or device error. The underlying exception is chained ('from exc') and the 500 tells the user the SAM backend could not be initialized on the chosen device.

Solutions

  1. Check that the SAM model weights downloaded correctly and retry.
  2. Review server logs for the load error; reinstall the SAM mask tools if needed.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Triggered when the corresponding server-side validation or runtime check at the recorded location rejects the request or operation and returns this error message to the caller.

Common situations: See trigger scenarios.


AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14). Data as JSON: /api/errors/50d25f9f6e78965b. Report an issue: GitHub.

Appendix: source

Thrown at routes/gallery/gallery_routes.py:87

            "SAM mask tools are not installed. Install Cookbook Dependencies -> SAM mask tools.",
        ) from exc

    device = "cpu"
    try:
        if torch.cuda.is_available():
            device = "cuda"
        elif getattr(torch.backends, "mps", None) and torch.backends.mps.is_available():
            device = "mps"
    except Exception:
        device = "cpu"

    try:
        processor = SamProcessor.from_pretrained(model_id)
        model = SamModel.from_pretrained(model_id)
        model.to(device)
        model.eval()
    except Exception as exc:
        raise HTTPException(500, f"Failed to load SAM model {model_id}: {exc}") from exc

    cached = {"torch": torch, "processor": processor, "model": model, "device": device, "model_id": model_id}
    _SAM_STATE[model_id] = cached
    return cached


def _load_grounding_backend():
    model_id = os.getenv("ODYSSEUS_GROUNDING_MODEL", "google/owlvit-base-patch32")
    cached = _GROUNDING_STATE.get(model_id)
    if cached:
        return cached
    try:
        import torch
        from transformers import OwlViTForObjectDetection, OwlViTProcessor
    except Exception as exc:
        raise HTTPException(
            501,
            "Object mask tools are not installed. Install Cookbook Dependencies -> SAM mask tools.",

View on GitHub (pinned to f9235ebbf1)