Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
Merge branch 'main' into feat/krea2-lokr-lora-support
Balrog9944a1fd9b082c8
diff --cc invokeai/backend/model_manager/configs/lora.pyindex 7fccf20184,28c3ca01e8..6aed6728eb--- a/invokeai/backend/model_manager/configs/lora.py+++ b/invokeai/backend/model_manager/configs/lora.py@@@ -940,35 -946,9 +946,37 @@@ def _has_complete_lora_pair(state_dictreturn False+# LyCORIS LoKr layers carry their Kronecker factors instead of a lora_A/B (or lora_down/up) pair: either the+# full `lokr_w1`/`lokr_w2`, or the further-factored `lokr_w1_a`/`lokr_w1_b` / `lokr_w2_a`/`lokr_w2_b` (+ the+# optional `lokr_t2` tucker core). Each such layer is self-contained, so there is no "orphaned half" notion to+# check — presence of any factor is enough to call the layer complete.+_LOKR_WEIGHT_SUFFIXES = (+ ".lokr_w1",+ ".lokr_w2",+ ".lokr_w1_a",+ ".lokr_w1_b",+ ".lokr_w2_a",+ ".lokr_w2_b",+ ".lokr_t2",+)++- def _has_lokr_layer(state_dict: dict[str | int, Any], prefixes: tuple[str, ...] | None = None) -> bool:- """True if the state dict contains at least one LoKr layer, optionally restricted to `prefixes`."""++def _has_lokr_layer(state_dict: dict[str | int, Any], key_filter: Callable[[str], bool] | None = None) -> bool:++ """True if the state dict contains at least one LoKr layer, optionally restricted to the keys++ `key_filter` accepts."""+ for key in state_dict:+ if not isinstance(key, str):+ continue- if prefixes is not None and not key.startswith(prefixes):++ if key_filter is not None and not key_filter(key):+ continue+ if key.endswith(_LOKR_WEIGHT_SUFFIXES):+ return True+ return False++- # Layouts the converter understands for an explicit Krea-2 override (a transformer-only or text-encoder-only- # LoRA that lacks the auto-detection text_fusion/time_mod_proj keys still installs under an explicit base).+ # Dotted layouts the converter understands for an explicit Krea-2 override (a transformer-only or+ # text-encoder-only LoRA that lacks the auto-detection text_fusion/time_mod_proj keys still installs under+ # an explicit base). The kohya/LyCORIS layout is deliberately absent - see `_key_is_supported_krea2_layout`._KREA2_SUPPORTED_LORA_PREFIXES = ("transformer.transformer_blocks.","transformer_blocks.",@@@ -1010,9 -994,7 +1022,9 @@@ class LoRA_LyCORIS_Krea2_Config(LoRA_Lystate_dict = mod.load_state_dict()explicit_krea2_override = override_fields.get("base") is BaseModelType.Krea2- has_supported_explicit_pair = _has_complete_lora_pair(state_dict, _key_is_supported_krea2_layout)+ has_supported_explicit_pair = _has_complete_lora_pair(- state_dict, _KREA2_SUPPORTED_LORA_PREFIXES- ) or _has_lokr_layer(state_dict, _KREA2_SUPPORTED_LORA_PREFIXES)++ state_dict, _key_is_supported_krea2_layout++ ) or _has_lokr_layer(state_dict, _key_is_supported_krea2_layout)# Reject an orphaned half *anywhere* in the state dict (e.g. a dangling text_fusion half not under# the approved prefixes) — it would install here but fail during LoRA conversion at generation time.if explicit_krea2_override and has_supported_explicit_pair and _lora_weight_keys_are_all_paired(state_dict):diff --cc invokeai/backend/patches/lora_conversions/krea2_lora_conversion_utils.pyindex d5d3e678ea,2b5f66a809..0267bcdbfc--- a/invokeai/backend/patches/lora_conversions/krea2_lora_conversion_utils.py+++ b/invokeai/backend/patches/lora_conversions/krea2_lora_conversion_utils.py@@@ -350,28 -259,23 +274,33 @@@ def _get_lora_layer_valuesreturn layer_dict- # Maps each recognized weight-key suffix to the canonical value-key used downstream. The PEFT/diffusers DoRA- # magnitude is published as ``<layer>.lora_magnitude_vector.weight``; it is the same thing InvokeAI stores as- # ``dora_scale``, so mapping it here lets a standard Diffusers DoRA adapter (A/B + magnitude) load as a- # DoRALayer instead of being split into a bogus, unrecognized layer.+ # Maps each recognized weight-key suffix to the canonical value-key used downstream.+ #+ # DoRA magnitudes come in two orientations that must not be mixed up (see ``DoRALayer``):+ # - ``.dora_scale`` (LyCORIS/kohya) indexes the *input* dim -> value key ``dora_scale``+ # - ``.lora_magnitude_vector.weight`` (PEFT/diffusers) and ``.magnitude`` (ai-toolkit) index the *output*+ # dim -> value key ``dora_magnitude``+ # Mapping them here lets a DoRA adapter (A/B + magnitude) load as a DoRALayer instead of being split into a+ # bogus, unrecognized layer.+#+# LyCORIS LoKr factors are passed through untouched: `any_lora_layer_from_state_dict` routes a values dict+# containing `lokr_w1` / `lokr_w1_a` to LoKRLayer, so they only need to survive _group_by_layer intact._SUFFIX_TO_VALUE_KEY = {".lora_A.weight": "lora_A.weight",".lora_B.weight": "lora_B.weight",".lora_down.weight": "lora_down.weight",".lora_up.weight": "lora_up.weight",".dora_scale": "dora_scale",- ".lora_magnitude_vector.weight": "dora_scale",+ ".lora_magnitude_vector.weight": "dora_magnitude",+ ".magnitude": "dora_magnitude",".alpha": "alpha",+ ".lokr_w1": "lokr_w1",+ ".lokr_w2": "lokr_w2",+ ".lokr_w1_a": "lokr_w1_a",+ ".lokr_w1_b": "lokr_w1_b",+ ".lokr_w2_a": "lokr_w2_a",+ ".lokr_w2_b": "lokr_w2_b",+ ".lokr_t2": "lokr_t2",}