invoke-ai/InvokeAI · error · NotAMatchError
model path is not a file
Error message
model path is not a file
What it means
raise_if_not_file asserts that the ModelOnDisk path is a regular file. Config classes that represent single-file model formats (e.g. single checkpoint files) call this during from_model_on_disk probing; if the path is a directory (or a nonexistent/special file), NotAMatchError is raised so the next candidate config can be tried.
Source
Thrown at invokeai/backend/model_manager/configs/identification_utils.py:160
candidate_config_class: The config class that is being tested.
override_fields: The override fields provided by the user.
Raises:
NotAMatch if any override field is invalid for the config class.
"""
for field_name, override_value in override_fields.items():
if field_name not in candidate_config_class.model_fields:
raise NotAMatchError(f"unknown override field: {field_name}")
try:
PydanticFieldValidator.validate_field(candidate_config_class, field_name, override_value)
except ValidationError as e:
raise NotAMatchError(f"invalid override for field '{field_name}': {e}") from e
def raise_if_not_file(mod: ModelOnDisk) -> None:
"""Raise NotAMatch if the model path is not a file."""
if not mod.path.is_file():
raise NotAMatchError("model path is not a file")
def raise_if_not_dir(mod: ModelOnDisk) -> None:
"""Raise NotAMatch if the model path is not a directory."""
if not mod.path.is_dir():
raise NotAMatchError("model path is not a directory")
def state_dict_has_any_keys_exact(state_dict: dict[str | int, Any], keys: str | set[str]) -> bool:
"""Returns true if the state dict has any of the specified keys."""
_keys = {keys} if isinstance(keys, str) else keys
return any(key in state_dict for key in _keys)
def state_dict_has_any_keys_starting_with(state_dict: dict[str | int, Any], prefixes: str | set[str]) -> bool:
"""Returns true if the state dict has any keys starting with any of the specified prefixes."""
_prefixes = {prefixes} if isinstance(prefixes, str) else prefixes
return any(any(key.startswith(prefix) for prefix in _prefixes) for key in state_dict.keys() if isinstance(key, str))View on GitHub (pinned to 0b6a024f2f)
Solutions
- Verify the path with os.path.isfile(); point it at the actual weights file (e.g. model.safetensors).
- If the model is a diffusers directory, use the directory config class instead of the single-file one.
- Fix broken symlinks so the path resolves to a real file.
- Rescan the models directory if InvokeAI's cached path metadata is stale.
Example fix
// before
ModelOnDisk(Path("/models/sd15/")) # directory
// after
ModelOnDisk(Path("/models/sd15/v1-5-pruned-emaonly.safetensors")) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
p = Path(model_path)
assert p.is_file(), f"expected a single-file model, got: {p}" Type guard
def is_model_file(p) -> bool:
from pathlib import Path
return Path(p).is_file() and Path(p).suffix in {".safetensors", ".ckpt", ".bin"} Try / catch
try:
record = from_model_on_disk(mod)
except NotAMatchError as e:
if str(e) == "model path is not a file":
logger.warning("skipping directory path with single-file config: %s", mod.path) Prevention
- Check path kind (file vs dir) before choosing which config class to probe
- Resolve symlinks with Path.resolve() before registration
- Keep single-file checkpoints and diffusers folders in separate scan roots
When it happens
Trigger: from_model_on_disk probing a single-file model config against a directory path (or vice versa), e.g. scanning a diffusers-style folder with a checkpoint-file config class.
Common situations: Registering a folder of weights instead of the .safetensors/.ckpt file itself; path points to a directory containing the model rather than the model; broken symlinks to files.
Related errors
- Not a valid file or directory: {model_path}
- model path is not a directory
- No existing parent found for {path}
- Empty path segments not allowed in subfolder path
- Failed to remove image from board
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/3bafdea496a51f92.
Report an issue: GitHub.