Skip to content

Commit cb8cdef

Browse files
authored
Merge branch 'main' into refactor/model-manager-2
2 parents f1c846b + 1c7ea57 commit cb8cdef

25 files changed

Lines changed: 608 additions & 365 deletions

File tree

installer/lib/installer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ def get_torch_source() -> (Union[str, None], str):
460460
url = "https://download.pytorch.org/whl/cpu"
461461

462462
if device == "cuda":
463-
url = "https://download.pytorch.org/whl/cu121"
463+
url = "https://download.pytorch.org/whl/cu118"
464464
optional_modules = "[xformers,onnx-cuda]"
465465
if device == "cuda_and_dml":
466-
url = "https://download.pytorch.org/whl/cu121"
466+
url = "https://download.pytorch.org/whl/cu118"
467467
optional_modules = "[xformers,onnx-directml]"
468468

469469
# in all other cases, Torch wheels should be coming from PyPi as of Torch 1.13

invokeai/app/invocations/metadata.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,14 @@ class CoreMetadataInvocation(BaseInvocation):
160160
)
161161

162162
# High resolution fix metadata.
163-
hrf_width: Optional[int] = InputField(
163+
hrf_enabled: Optional[float] = InputField(
164164
default=None,
165-
description="The high resolution fix height and width multipler.",
165+
description="Whether or not high resolution fix was enabled.",
166166
)
167-
hrf_height: Optional[int] = InputField(
167+
# TODO: should this be stricter or do we just let the UI handle it?
168+
hrf_method: Optional[str] = InputField(
168169
default=None,
169-
description="The high resolution fix height and width multipler.",
170+
description="The high resolution fix upscale method.",
170171
)
171172
hrf_strength: Optional[float] = InputField(
172173
default=None,

invokeai/backend/install/model_install_backend.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,13 @@ def heuristic_import(
254254
elif path.is_dir() and any(
255255
[
256256
(path / x).exists()
257-
for x in {"config.json", "model_index.json", "learned_embeds.bin", "pytorch_lora_weights.bin"}
257+
for x in {
258+
"config.json",
259+
"model_index.json",
260+
"learned_embeds.bin",
261+
"pytorch_lora_weights.bin",
262+
"pytorch_lora_weights.safetensors",
263+
}
258264
]
259265
):
260266
models_installed.update({str(model_path_id_or_url): self._install_path(path)})
@@ -357,7 +363,7 @@ def _install_repo(self, repo_id: str) -> AddModelResult:
357363
for suffix in ["safetensors", "bin"]:
358364
if f"{prefix}pytorch_lora_weights.{suffix}" in files:
359365
location = self._download_hf_model(
360-
repo_id, ["pytorch_lora_weights.bin"], staging, subfolder=subfolder
366+
repo_id, [f"pytorch_lora_weights.{suffix}"], staging, subfolder=subfolder
361367
) # LoRA
362368
break
363369
elif (

invokeai/backend/model_management/lora.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ def apply_ti(
166166
init_tokens_count = None
167167
new_tokens_added = None
168168

169+
# TODO: This is required since Transformers 4.32 see
170+
# https://github.com/huggingface/transformers/pull/25088
171+
# More information by NVIDIA:
172+
# https://docs.nvidia.com/deeplearning/performance/dl-performance-matrix-multiplication/index.html#requirements-tc
173+
# This value might need to be changed in the future and take the GPUs model into account as there seem
174+
# to be ideal values for different GPUS. This value is temporary!
175+
# For references to the current discussion please see https://github.com/invoke-ai/InvokeAI/pull/4817
176+
pad_to_multiple_of = 8
177+
169178
try:
170179
# HACK: The CLIPTokenizer API does not include a way to remove tokens after calling add_tokens(...). As a
171180
# workaround, we create a full copy of `tokenizer` so that its original behavior can be restored after
@@ -175,7 +184,7 @@ def apply_ti(
175184
# but a pickle roundtrip was found to be much faster (1 sec vs. 0.05 secs).
176185
ti_tokenizer = pickle.loads(pickle.dumps(tokenizer))
177186
ti_manager = TextualInversionManager(ti_tokenizer)
178-
init_tokens_count = text_encoder.resize_token_embeddings(None).num_embeddings
187+
init_tokens_count = text_encoder.resize_token_embeddings(None, pad_to_multiple_of).num_embeddings
179188

180189
def _get_trigger(ti_name, index):
181190
trigger = ti_name
@@ -190,7 +199,7 @@ def _get_trigger(ti_name, index):
190199
new_tokens_added += ti_tokenizer.add_tokens(_get_trigger(ti_name, i))
191200

192201
# modify text_encoder
193-
text_encoder.resize_token_embeddings(init_tokens_count + new_tokens_added)
202+
text_encoder.resize_token_embeddings(init_tokens_count + new_tokens_added, pad_to_multiple_of)
194203
model_embeddings = text_encoder.get_input_embeddings()
195204

196205
for ti_name, ti in ti_list:
@@ -222,7 +231,7 @@ def _get_trigger(ti_name, index):
222231

223232
finally:
224233
if init_tokens_count and new_tokens_added:
225-
text_encoder.resize_token_embeddings(init_tokens_count)
234+
text_encoder.resize_token_embeddings(init_tokens_count, pad_to_multiple_of)
226235

227236
@classmethod
228237
@contextmanager

invokeai/backend/model_management/model_probe.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,13 @@ def get_model_type_from_folder(cls, folder_path: Path, model: ModelMixin) -> Mod
183183
if model:
184184
class_name = model.__class__.__name__
185185
else:
186+
for suffix in ["bin", "safetensors"]:
187+
if (folder_path / f"learned_embeds.{suffix}").exists():
188+
return ModelType.TextualInversion
189+
if (folder_path / f"pytorch_lora_weights.{suffix}").exists():
190+
return ModelType.Lora
186191
if (folder_path / "unet/model.onnx").exists():
187192
return ModelType.ONNX
188-
if (folder_path / "learned_embeds.bin").exists():
189-
return ModelType.TextualInversion
190-
if (folder_path / "pytorch_lora_weights.bin").exists():
191-
return ModelType.Lora
192193
if (folder_path / "image_encoder.txt").exists():
193194
return ModelType.IPAdapter
194195

invokeai/backend/model_management/models/lora.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def detect_format(cls, path: str):
6868
raise ModelNotFoundException()
6969

7070
if os.path.isdir(path):
71-
if os.path.exists(os.path.join(path, "pytorch_lora_weights.bin")):
72-
return LoRAModelFormat.Diffusers
71+
for ext in ["safetensors", "bin"]:
72+
if os.path.exists(os.path.join(path, f"pytorch_lora_weights.{ext}")):
73+
return LoRAModelFormat.Diffusers
7374

7475
if os.path.isfile(path):
7576
if any([path.endswith(f".{ext}") for ext in ["safetensors", "ckpt", "pt"]]):
@@ -86,8 +87,10 @@ def convert_if_required(
8687
base_model: BaseModelType,
8788
) -> str:
8889
if cls.detect_format(model_path) == LoRAModelFormat.Diffusers:
89-
# TODO: add diffusers lora when it stabilizes a bit
90-
raise NotImplementedError("Diffusers lora not supported")
90+
for ext in ["safetensors", "bin"]: # return path to the safetensors file inside the folder
91+
path = Path(model_path, f"pytorch_lora_weights.{ext}")
92+
if path.exists():
93+
return path
9194
else:
9295
return model_path
9396

invokeai/frontend/web/public/locales/en.json

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@
221221
"resetIPAdapterImage": "Reset IP Adapter Image",
222222
"ipAdapterImageFallback": "No IP Adapter Image Selected"
223223
},
224+
"hrf": {
225+
"hrf": "High Resolution Fix",
226+
"enableHrf": "Enable High Resolution Fix",
227+
"enableHrfTooltip": "Generate with a lower initial resolution, upscale to the base resolution, then run Image-to-Image.",
228+
"upscaleMethod": "Upscale Method",
229+
"hrfStrength": "High Resolution Fix Strength",
230+
"strengthTooltip": "Lower values result in fewer details, which may reduce potential artifacts.",
231+
"metadata": {
232+
"enabled": "High Resolution Fix Enabled",
233+
"strength": "High Resolution Fix Strength",
234+
"method": "High Resolution Fix Method"
235+
}
236+
},
224237
"embedding": {
225238
"addEmbedding": "Add Embedding",
226239
"incompatibleModel": "Incompatible base model:",
@@ -1258,15 +1271,11 @@
12581271
},
12591272
"compositingBlur": {
12601273
"heading": "Blur",
1261-
"paragraphs": [
1262-
"The blur radius of the mask."
1263-
]
1274+
"paragraphs": ["The blur radius of the mask."]
12641275
},
12651276
"compositingBlurMethod": {
12661277
"heading": "Blur Method",
1267-
"paragraphs": [
1268-
"The method of blur applied to the masked area."
1269-
]
1278+
"paragraphs": ["The method of blur applied to the masked area."]
12701279
},
12711280
"compositingCoherencePass": {
12721281
"heading": "Coherence Pass",
@@ -1276,9 +1285,7 @@
12761285
},
12771286
"compositingCoherenceMode": {
12781287
"heading": "Mode",
1279-
"paragraphs": [
1280-
"The mode of the Coherence Pass."
1281-
]
1288+
"paragraphs": ["The mode of the Coherence Pass."]
12821289
},
12831290
"compositingCoherenceSteps": {
12841291
"heading": "Steps",
@@ -1296,9 +1303,7 @@
12961303
},
12971304
"compositingMaskAdjustments": {
12981305
"heading": "Mask Adjustments",
1299-
"paragraphs": [
1300-
"Adjust the mask."
1301-
]
1306+
"paragraphs": ["Adjust the mask."]
13021307
},
13031308
"controlNetBeginEnd": {
13041309
"heading": "Begin / End Step Percentage",
@@ -1356,9 +1361,7 @@
13561361
},
13571362
"infillMethod": {
13581363
"heading": "Infill Method",
1359-
"paragraphs": [
1360-
"Method to infill the selected area."
1361-
]
1364+
"paragraphs": ["Method to infill the selected area."]
13621365
},
13631366
"lora": {
13641367
"heading": "LoRA Weight",

invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/ImageMetadataActions.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const ImageMetadataActions = (props: Props) => {
3535
recallWidth,
3636
recallHeight,
3737
recallStrength,
38+
recallHrfEnabled,
39+
recallHrfStrength,
40+
recallHrfMethod,
3841
recallLoRA,
3942
recallControlNet,
4043
recallIPAdapter,
@@ -81,6 +84,18 @@ const ImageMetadataActions = (props: Props) => {
8184
recallStrength(metadata?.strength);
8285
}, [metadata?.strength, recallStrength]);
8386

87+
const handleRecallHrfEnabled = useCallback(() => {
88+
recallHrfEnabled(metadata?.hrf_enabled);
89+
}, [metadata?.hrf_enabled, recallHrfEnabled]);
90+
91+
const handleRecallHrfStrength = useCallback(() => {
92+
recallHrfStrength(metadata?.hrf_strength);
93+
}, [metadata?.hrf_strength, recallHrfStrength]);
94+
95+
const handleRecallHrfMethod = useCallback(() => {
96+
recallHrfMethod(metadata?.hrf_method);
97+
}, [metadata?.hrf_method, recallHrfMethod]);
98+
8499
const handleRecallLoRA = useCallback(
85100
(lora: LoRAMetadataItem) => {
86101
recallLoRA(lora);
@@ -225,6 +240,27 @@ const ImageMetadataActions = (props: Props) => {
225240
onClick={handleRecallStrength}
226241
/>
227242
)}
243+
{metadata.hrf_enabled && (
244+
<ImageMetadataItem
245+
label={t('hrf.metadata.enabled')}
246+
value={metadata.hrf_enabled}
247+
onClick={handleRecallHrfEnabled}
248+
/>
249+
)}
250+
{metadata.hrf_enabled && metadata.hrf_strength && (
251+
<ImageMetadataItem
252+
label={t('hrf.metadata.strength')}
253+
value={metadata.hrf_strength}
254+
onClick={handleRecallHrfStrength}
255+
/>
256+
)}
257+
{metadata.hrf_enabled && metadata.hrf_method && (
258+
<ImageMetadataItem
259+
label={t('hrf.metadata.method')}
260+
value={metadata.hrf_method}
261+
onClick={handleRecallHrfMethod}
262+
/>
263+
)}
228264
{metadata.loras &&
229265
metadata.loras.map((lora, index) => {
230266
if (isValidLoRAModel(lora.lora)) {

invokeai/frontend/web/src/features/nodes/types/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,9 @@ export const zCoreMetadata = z
14241424
loras: z.array(zLoRAMetadataItem).nullish().catch(null),
14251425
vae: zVaeModelField.nullish().catch(null),
14261426
strength: z.number().nullish().catch(null),
1427+
hrf_enabled: z.boolean().nullish().catch(null),
1428+
hrf_strength: z.number().nullish().catch(null),
1429+
hrf_method: z.string().nullish().catch(null),
14271430
init_image: z.string().nullish().catch(null),
14281431
positive_style_prompt: z.string().nullish().catch(null),
14291432
negative_style_prompt: z.string().nullish().catch(null),

0 commit comments

Comments
 (0)