Skip to content

Commit fc3a9cb

Browse files
feat(mm): just delete the dir w/ rmtree when deleting model
1 parent 93a3374 commit fc3a9cb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

invokeai/app/services/model_install/model_install_default.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,18 @@ def delete(self, key: str) -> None: # noqa D102
369369
def unconditionally_delete(self, key: str) -> None: # noqa D102
370370
model = self.record_store.get_model(key)
371371
model_path = self.app_config.models_path / model.path
372+
# Models are stored in a directory named by their key. To delete the model on disk, we delete the entire
373+
# directory. However, the path we store in the model record may be either a file within the key directory,
374+
# or the directory itself. So we have to handle both cases.
372375
if model_path.is_file() or model_path.is_symlink():
373-
model_path.unlink()
376+
# Sanity check - file models should be in their own directory under the models dir. The parent of the
377+
# file should be the model's directory, not the Invoke models dir!
374378
assert model_path.parent != self.app_config.models_path
375379
rmtree(model_path.parent)
376380
elif model_path.is_dir():
381+
# Sanity check - folder models should be in their own directory under the models dir. The path should
382+
# not be the Invoke models dir itself!
383+
assert model_path != self.app_config.models_path
377384
rmtree(model_path)
378385
self.unregister(key)
379386

0 commit comments

Comments
 (0)