{"record":{"id":"af74bb24785010c1","repo":"unslothai/unsloth","slug":"path-must-be-a-folder-or-model-weight-file","errorCode":null,"errorMessage":"Path must be a folder or model weight file","messagePattern":"Path must be a folder or model weight file","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"warning","filePath":"studio/backend/hub/services/models/local_inventory.py","lineNumber":623,"sourceCode":"        except (OSError, ValueError) as e:\n            raise ValueError(f\"Path is not readable: {e}\") from e\n        if slash_exists:\n            normalized = slash_normalized\n            try:\n                is_dir = normalized.is_dir()\n                is_file = normalized.is_file()\n            except (OSError, ValueError) as e:\n                raise ValueError(f\"Path is not readable: {e}\") from e\n            exists = True\n\n    if not exists:\n        return str(normalized)\n    if is_dir:\n        return str(normalized)\n    if is_file:\n        suffix = normalized.suffix.lower()\n        if suffix not in {\".gguf\", \".safetensors\", \".bin\"}:\n            raise ValueError(\"Path must be a folder or model weight file\")\n        return str(normalized.parent)\n    return str(normalized)\n\n\nasync def _scan_source(label: str, scanner, path: Path) -> List[LocalModelInfo]:\n    try:\n        return await asyncio.to_thread(scanner, path)\n    except Exception as e:\n        logger.warning(\"Skipping %s scan for %s: %s\", label, path, e)\n        return []\n\n\nasync def _collect_models_from_default_sources(\n    models_root: Path,\n    hf_cache_dir: Path,\n    legacy_hf: Path,\n    hf_default: Path,\n    lm_dirs: tuple[Path, ...],","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/hub/services/models/local_inventory.py#L605-L641","documentation":"Raised when the resolved path exists and is a regular file, but its lowercase suffix is not one of the recognized model-weight extensions {.gguf, .safetensors, .bin}. The inventory layer derives the model root from a weight file by returning its parent directory, so it must first confirm the file actually looks like model weights by extension.","triggerScenarios":"Pointing models_dir or a custom scan folder at a file such as model.ckpt, model.pt, model.onnx, config.json, or README.md — anything that stats as a file without a .gguf/.safetensors/.bin suffix.","commonSituations":"Users selecting a checkpoint in PyTorch format (.ckpt/.pt) or an ONNX export, which this inventory does not index; accidentally selecting a config/readme inside a model folder instead of the folder itself; downloading a model whose weights ship under a non-standard extension.","solutions":["Select the model's folder instead of the file — folders are accepted regardless of contents (the scanner walks them for weights).","If the weights genuinely are model weights, rename/use a file with a .safetensors, .gguf, or .bin extension.","Convert the artifact: .ckpt/.pt → safetensors via convert_hf_to_gguf.py style tooling or safetensors conversion scripts."],"exampleFix":"# before\nmodels_dir = \"/models/llama2/config.json\"\n# after\nmodels_dir = \"/models/llama2\"   # the folder containing the weights","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nWEIGHT_SUFFIXES = {\".gguf\", \".safetensors\", \".bin\"}\n\ndef is_acceptable_model_path(p: str) -> bool:\n    path = Path(p)\n    if path.is_dir():\n        return True\n    return path.is_file() and path.suffix.lower() in WEIGHT_SUFFIXES","typeGuard":null,"tryCatchPattern":"try:\n    root = resolve_model_root(path)\nexcept ValueError as e:\n    if \"folder or model weight\" in str(e):\n        # user picked a file; suggest the containing directory\n        suggest = str(Path(path).parent)","preventionTips":["In file pickers for model paths, filter to directories or *.gguf/*.safetensors/*.bin.","Default the picker to the model's folder rather than a file inside it.","Convert .ckpt/.pt weights to safetensors before adding them to local inventories."],"tags":["validation","local-models","file-format"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}