{"record":{"id":"2d2d0ec086ce050b","repo":"invoke-ai/InvokeAI","slug":"directory-contains-more-than-max-files-in-model","errorCode":null,"errorMessage":"Directory contains more than {_MAX_FILES_IN_MODEL_DIR} files. This looks like a general-purpose directory rather than a model. Please provide a path to a specific model file or model directory.","messagePattern":"Directory contains more than (.+?) files\\. This looks like a general-purpose directory rather than a model\\. Please provide a path to a specific model file or model directory\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/factory.py","lineNumber":601,"sourceCode":"                recognized_root_config = _is_known_model_marker(config_name, config)\n                if recognized_root_config:\n                    break\n            if recognized_root_config:\n                return\n\n            # For directories, do a quick file count check with early exit\n            total_files = 0\n            # Ignore hidden files and directories\n            paths_to_check = (\n                p\n                for p in path.rglob(\"*\")\n                if not p.name.startswith(\".\") and not any(part.startswith(\".\") for part in p.parts)\n            )\n            for item in paths_to_check:\n                if item.is_file():\n                    total_files += 1\n                    if total_files > _MAX_FILES_IN_MODEL_DIR:\n                        raise ValueError(\n                            f\"Directory contains more than {_MAX_FILES_IN_MODEL_DIR} files. \"\n                            \"This looks like a general-purpose directory rather than a model. \"\n                            \"Please provide a path to a specific model file or model directory.\"\n                        )\n\n            # Otherwise, search for model files within depth limit\n            def find_model_files(current_path: Path, depth: int) -> bool:\n                if depth > _MAX_SEARCH_DEPTH:\n                    return False\n                try:\n                    for item in current_path.iterdir():\n                        if item.is_file() and item.suffix.lower() in _MODEL_EXTENSIONS:\n                            return True\n                        elif item.is_dir() and find_model_files(item, depth + 1):\n                            return True\n                except PermissionError:\n                    pass\n                return False","sourceCodeStart":583,"sourceCodeEnd":619,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/factory.py#L583-L619","documentation":"To avoid misreading large application directories as models, _validate_path_looks_like_model counts non-hidden files; if the directory contains more than _MAX_FILES_IN_MODEL_DIR files it refuses with this ValueError. Model dirs (diffusers etc.) contain a handful of files, so a huge directory is treated as a general-purpose directory, not a model.","triggerScenarios":"Invoking model probe/install with a path like a project folder, home directory, or site-packages that contains hundreds/thousands of non-hidden files; pointing at the repo root of an application instead of a specific model.","commonSituations":"Accidentally passing CWD, an uploads folder, or a dataset directory; installing a model from a monorepo root; a directory that legitimately has many shard files exceeding the cap.","solutions":["Pass the specific model file or its dedicated directory instead of the broad parent directory","Move the model into its own folder and point there","For huge multi-file models, reference the single top-level weights file directly","Check for accidental inclusion of hidden-metadata-heavy trees; hidden files are ignored, visible clutter is not"],"exampleFix":"// before\ninstall_model(\"/home/user/projects/myapp\")  # thousands of files\n// after\ninstall_model(\"/home/user/projects/myapp/models/sdxl-unet\")  # dedicated model dir","handlingStrategy":"validation","validationCode":"import pathlib\n\ndef looks_like_model_dir(path: str, max_files: int = 50) -> bool:\n    p = pathlib.Path(path)\n    visible = [f for f in p.rglob(\"*\") if not f.name.startswith(\".\") and not any(part.startswith(\".\") for part in f.parts)]\n    return len(visible) <= max_files","typeGuard":null,"tryCatchPattern":"try:\n    install_model(path)\nexcept ValueError as e:\n    if \"more than\" in str(e) and \"files\" in str(e):\n        logger.error(\"Pass the specific model file or a dedicated model directory\")\n    else:\n        raise","preventionTips":["Never pass application/home directories to model install","Give each model its own folder","Reference the top-level weights file for very large models","Sanitize user-supplied paths before invoking the installer"],"tags":["python","directory","validation","model-probing"],"backgroundTag":"invalid-model-path","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}