{"record":{"id":"03b9ee9e7220afcf","repo":"mudler/LocalAI","slug":"model-not-found-model-ref","errorCode":null,"errorMessage":"Model not found: {model_ref}","messagePattern":"Model not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"backend/python/tinygrad/backend.py","lineNumber":103,"sourceCode":"    if p.exists():\n        return p\n    if \"/\" in model_ref and not model_ref.startswith((\"/\", \".\")):\n        from huggingface_hub import snapshot_download\n        local = snapshot_download(\n            repo_id=model_ref,\n            allow_patterns=[\n                \"config.json\",\n                \"tokenizer.json\",\n                \"tokenizer_config.json\",\n                \"special_tokens_map.json\",\n                \"generation_config.json\",\n                \"*.safetensors\",\n                \"*.safetensors.index.json\",\n                \"*.gguf\",\n            ],\n        )\n        return Path(local)\n    raise FileNotFoundError(f\"Model not found: {model_ref}\")\n\n\ndef _gguf_path(model_ref: Path) -> Optional[Path]:\n    \"\"\"Return the GGUF file to load from a path that may be a file or dir.\"\"\"\n    if model_ref.is_file() and str(model_ref).endswith(\".gguf\"):\n        return model_ref\n    if model_ref.is_dir():\n        ggufs = sorted(model_ref.glob(\"*.gguf\"))\n        if ggufs:\n            return ggufs[0]\n    return None\n\n\ndef _load_hf_safetensors(model_dir: Path) -> dict[str, Any]:\n    \"\"\"Load sharded or single-file HF safetensors from a directory.\"\"\"\n    from tinygrad.nn.state import safe_load\n\n    index = model_dir / \"model.safetensors.index.json\"","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/python/tinygrad/backend.py#L85-L121","documentation":"_resolve_model_assets accepts either a local path or a HuggingFace repo id. It first checks Path(model_ref).exists(); if not, and the ref contains '/' (looks like an HF id), it snapshot-downloads it; anything else (nonexistent path, or a ref without '/' that is not on disk) falls through to FileNotFoundError.","triggerScenarios":"Loading a tinygrad LLM with a model ref that is a typo'd local path, a path that does not exist yet, a bare HF repo name without namespace (no '/'), or a relative path starting with './' or '/' which is treated as filesystem-only and fails when absent.","commonSituations":"Model name typo ('Qwen3-0.6B' instead of 'Qwen/Qwen3-0.6B'); pointing at a directory that was never downloaded or was removed; relative path resolved against a different working directory.","solutions":["If you meant a HuggingFace repo, use the fully-qualified id with namespace, e.g. 'Qwen/Qwen3-0.6B'.","If you meant a local file, verify the path exists from the backend's working directory (use an absolute path).","For private repos, make sure HF_TOKEN is set so snapshot_download does not fail (a failed download of an existing repo id surfaces as this or a related error)."],"exampleFix":"# before\nmodel_ref = \"Qwen3-0.6B\"          # no namespace, not a local file\n# after\nmodel_ref = \"Qwen/Qwen3-0.6B\"      # HF repo id, snapshot_download path","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef resolve_model_ref(ref: str) -> Path:\n    p = Path(ref)\n    if p.exists():\n        return p\n    if \"/\" in ref and not ref.startswith((\"/\", \".\")):\n        return None  # will be snapshot-downloaded\n    raise FileNotFoundError(f\"local path missing and not an HF id: {ref}\")","typeGuard":null,"tryCatchPattern":"try:\n    model_dir = _resolve_model_assets(ref)\nexcept FileNotFoundError:\n    if \"/\" not in ref:\n        ref = f\"org/{ref}\"  # only if you know the org\n    model_dir = _resolve_model_assets(ref)","preventionTips":["Validate model refs against ^[\\w.-]+/[\\w.-]+$ or an existing filesystem path before starting the backend.","Fail model-list loads at startup, not at first inference.","Keep a curated allowlist of repo ids in config to catch typos early."],"tags":["tinygrad","huggingface","model-resolution","file-not-found","localai"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}