Skip to content

Commit 05f9551

Browse files
fix(mm): normalized multi-file/diffusers model installation no worky
now worky
1 parent 974074b commit 05f9551

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

invokeai/app/services/model_install/model_install_default.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,22 @@ def install_path(
187187

188188
dest_dir = self.app_config.models_path / info.key
189189
try:
190-
dest_dir.mkdir(parents=True)
191-
dest_path = dest_dir / model_path.name if model_path.is_file() else dest_dir
192-
if dest_path.exists():
190+
if dest_dir.exists():
193191
raise FileExistsError(
194-
f"Cannot install model {model_path.name} to {dest_path}: destination already exists"
192+
f"Cannot install model {model_path.name} to {dest_dir}: destination already exists"
195193
)
196-
move(model_path, dest_path)
197-
except FileExistsError as excp:
194+
dest_dir.mkdir(parents=True)
195+
dest_path = dest_dir / model_path.name if model_path.is_file() else dest_dir
196+
if model_path.is_file():
197+
move(model_path, dest_path)
198+
elif model_path.is_dir():
199+
# Move the contents of the directory, not the directory itself
200+
for item in model_path.iterdir():
201+
move(item, dest_dir / item.name)
202+
except FileExistsError as e:
198203
raise DuplicateModelException(
199204
f"A model named {model_path.name} is already installed at {dest_dir.as_posix()}"
200-
) from excp
205+
) from e
201206

202207
return self._register(
203208
dest_path,

tests/app/services/model_install/test_model_install.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_install(
9595
store = mm2_installer.record_store
9696
key = mm2_installer.install_path(embedding_file)
9797
model_record = store.get_model(key)
98-
assert model_record.path.endswith("sd-1/embedding/test_embedding.safetensors")
98+
assert model_record.path.endswith(f"{key}/test_embedding.safetensors")
9999
assert (mm2_app_config.models_path / model_record.path).exists()
100100
assert model_record.source == embedding_file.as_posix()
101101

@@ -106,23 +106,24 @@ def test_rename(
106106
store = mm2_installer.record_store
107107
key = mm2_installer.install_path(embedding_file)
108108
model_record = store.get_model(key)
109-
assert model_record.path.endswith("sd-1/embedding/test_embedding.safetensors")
109+
assert model_record.path.endswith(f"{key}/test_embedding.safetensors")
110110
new_model_record = store.update_model(key, ModelRecordChanges(name="new model name", base=BaseModelType("sd-2")))
111111
# Renaming the model record shouldn't rename the file
112112
assert new_model_record.name == "new model name"
113-
assert new_model_record.path.endswith("sd-2/embedding/test_embedding.safetensors")
113+
assert model_record.path.endswith(f"{key}/test_embedding.safetensors")
114114

115115

116116
@pytest.mark.parametrize(
117-
"fixture_name,size,destination",
117+
"fixture_name,size,key,destination",
118118
[
119-
("embedding_file", 15440, "sd-1/embedding/test_embedding.safetensors"),
120-
("diffusers_dir", 8241 if OS == "Windows" else 7907, "sdxl/main/test-diffusers-main"), # EOL chars
119+
("embedding_file", 15440, "foo", "foo/test_embedding.safetensors"),
120+
("diffusers_dir", 8241 if OS == "Windows" else 7907, "bar", "bar"), # EOL chars
121121
],
122122
)
123123
def test_background_install(
124124
mm2_installer: ModelInstallServiceBase,
125125
fixture_name: str,
126+
key: str,
126127
size: int,
127128
destination: str,
128129
mm2_app_config: InvokeAIAppConfig,
@@ -132,7 +133,7 @@ def test_background_install(
132133
path: Path = request.getfixturevalue(fixture_name)
133134
description = "Test of metadata assignment"
134135
source = LocalModelSource(path=path, inplace=False)
135-
job = mm2_installer.import_model(source, config=ModelRecordChanges(description=description))
136+
job = mm2_installer.import_model(source, config=ModelRecordChanges(key=key,description=description))
136137
assert job is not None
137138
assert isinstance(job, ModelInstallJob)
138139

0 commit comments

Comments
 (0)