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
fix(ltx2): close the LoRA probe and accelerator-restore gaps found in review
Lincoln Steinda04fa7d83c1
diff --git a/invokeai/backend/model_manager/starter_models/__init__.py b/invokeai/backend/model_manager/starter_models/__init__.pyindex 235900aca1..809b9d13de 100644--- a/invokeai/backend/model_manager/starter_models/__init__.py+++ b/invokeai/backend/model_manager/starter_models/__init__.py@@ -668,7 +668,6 @@ ltx2_bundle: list[StarterModel] = [ltx2_5_text_encoder_int8,ltx2_5_dev_transformer_int8,ltx2_5_distilled_transformer_int8,- ltx2_5_distilled_lora,]STARTER_BUNDLES: dict[str, StarterModelBundle] = {diff --git a/invokeai/backend/patches/lora_conversions/ltx2_lora_constants.py b/invokeai/backend/patches/lora_conversions/ltx2_lora_constants.pyindex 57f5af4e23..a437e5d5b7 100644--- a/invokeai/backend/patches/lora_conversions/ltx2_lora_constants.py+++ b/invokeai/backend/patches/lora_conversions/ltx2_lora_constants.py@@ -29,7 +29,7 @@ LTX2_LORA_TRANSFORMER_PREFIX = "lora_transformer-"# would also match nested prefixes like ``diffusion_model.transformer.blocks...``, which the# probe would then admit but the converter would map onto nonexistent module paths (the LoRA# would silently apply zero layers).-_PEFT_PREFIX_RE = r"^(?:(?:diffusion_model|transformer|base_model\.model\.transformer)\.)?"+_PEFT_PREFIX_RE = r"^(?:(?:model\.diffusion_model|diffusion_model|transformer|base_model\.model\.transformer)\.)?"# Submodules unique to LTX-2 among the supported architectures, in the checkpoint's native# naming. All of them exist only because LTX-2 is a *dual-stream* video+audio transformer:@@ -73,9 +73,19 @@ _NON_LTX2_ANTI_RES = (_UNSUPPORTED_LTX2_VARIANT_SUFFIXES = (".lokr_w1",".lokr_w2",+ ".lokr_w1_a",+ ".lokr_w2_a",".hada_w1_a",".hada_w2_a",+ # Both DoRA spellings. LTX-2 LoRAs are published in the PEFT layout, so the PEFT/ai-toolkit+ # magnitude names are the ones this family will actually meet -- and DoRA is the only variant+ # that reaches this guard at all, because it carries `lora_A`/`lora_B` and so passes the generic+ # "has a LoRA suffix" test that LoKR and LoHA files fail on their own. Checking only the kohya+ # spelling let a DoRA file install and then fail inside the denoise, after the 22B transformer+ # had loaded -- exactly the deferral this guard exists to prevent.".dora_scale",+ ".lora_magnitude_vector.weight",+ ".magnitude",)diff --git a/invokeai/backend/patches/lora_conversions/ltx2_lora_conversion_utils.py b/invokeai/backend/patches/lora_conversions/ltx2_lora_conversion_utils.pyindex b95bb91b01..25916693f0 100644--- a/invokeai/backend/patches/lora_conversions/ltx2_lora_conversion_utils.py+++ b/invokeai/backend/patches/lora_conversions/ltx2_lora_conversion_utils.py@@ -41,6 +41,9 @@ from invokeai.backend.patches.model_patch_raw import ModelPatchRaw# official paths. Ordered longest-first so the nested PEFT prefix is not left with a tail._PEFT_PREFIXES_TO_STRIP = ("base_model.model.transformer.",+ # Comfy packages some releases under this; diffusers' own rename table strips it too, so the+ # probe admits it and this keeps the two in step.+ "model.diffusion_model.","diffusion_model.","transformer.",)diff --git a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.test.ts b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.test.tsindex 7c1f026dd4..8b0d2c9526 100644--- a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.test.ts+++ b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.test.ts@@ -32,6 +32,7 @@ import {snapVideoNumFrames,WAN_LIGHTNING_ACCELERATOR,} from './videoPolicies';+import { syncVideoWidgetValuesWithModels } from './widgetValues';const wanModel = (variant: string, format = 'gguf_quantized', key = `wan-${variant}-${format}`): MainModelConfig => ({base: 'wan',@@ -561,6 +562,26 @@ describe('LTX-2 distilled accelerator', () => {});});+ it('restores the whole recipe when the accelerator LoRA leaves the catalog entirely', () => {+ // A different route than unticking it in Concepts: this one runs when the LoRA is deleted in+ // Model Manager. It goes through `syncVideoWidgetValues`, which copies named fields out of the+ // change result -- so a field the result restores but the copy does not name is silently lost,+ // leaving a guided Dev run with its audio, STG and modality guidance pinned at identity.+ const model = ltx2('ltx2_dev');+ const on = getAcceleratorToggleResult(getDefaultVideoSettings(model, []), model, [DISTILLED], true).settings;+ // The LoRA is gone from the catalog: only the main model remains.+ const synced = syncVideoWidgetValuesWithModels({ ...on, loras: [], model }, [model]);++ expect(synced).toMatchObject({+ acceleratorEnabled: false,+ audioCfgScale: 7,+ cfgScale: 3,+ modalityScale: 3,+ steps: 30,+ stgScale: 1,+ });+ });+it('leaves families whose accelerator keeps guidance alone', () => {// Wan and H3 declare no guidance triple, so their accelerator drops CFG but does not make the// run guidance-free -- their negative prompt stays visible, exactly as before.diff --git a/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts b/invokeai/frontend/webv2/src/features/video/core/widgetValues.tsindex c3a5dee3ea..b8e2a718eb 100644--- a/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts+++ b/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts@@ -148,9 +148,12 @@ export const syncVideoWidgetValuesWithModels = (const unchangedAccelerator = {acceleratorEnabled: base.acceleratorEnabled,acceleratorLoraKeys: base.acceleratorLoraKeys,+ audioCfgScale: base.audioCfgScale,cfgScale: base.cfgScale,cfgScaleLowNoise: base.cfgScaleLowNoise,+ modalityScale: base.modalityScale,steps: base.steps,+ stgScale: base.stgScale,};const acceleratorSync = model ? getAcceleratorLoraChangeResult(base, model, models, loras) : null;let accelerator = unchangedAccelerator;@@ -167,12 +170,19 @@ export const syncVideoWidgetValuesWithModels = (};}} else if (acceleratorSync && acceleratorSync.outcome !== 'unchanged') {+ // Every field the change result rewrites, not a hand-picked five. An accelerator that removes+ // guidance also restores it when it goes away, and naming fields here meant the Concepts-list+ // route honoured that while this one -- the LoRA leaving the catalog entirely -- dropped it,+ // leaving a guided run with its audio, STG and modality guidance silently pinned at identity.accelerator = {acceleratorEnabled: acceleratorSync.settings.acceleratorEnabled,acceleratorLoraKeys: acceleratorSync.settings.acceleratorLoraKeys,+ audioCfgScale: acceleratorSync.settings.audioCfgScale,cfgScale: acceleratorSync.settings.cfgScale,cfgScaleLowNoise: acceleratorSync.settings.cfgScaleLowNoise,+ modalityScale: acceleratorSync.settings.modalityScale,steps: acceleratorSync.settings.steps,+ stgScale: acceleratorSync.settings.stgScale,};}diff --git a/tests/backend/model_manager/configs/test_ltx2_lora_probe_independence.py b/tests/backend/model_manager/configs/test_ltx2_lora_probe_independence.pyindex 7cb87c936b..9f3a9960d9 100644--- a/tests/backend/model_manager/configs/test_ltx2_lora_probe_independence.py+++ b/tests/backend/model_manager/configs/test_ltx2_lora_probe_independence.py@@ -22,10 +22,14 @@ import torchfrom invokeai.backend.model_manager.configs.identification_utils import NotAMatchErrorfrom invokeai.backend.model_manager.configs.lora import (LoRA_LyCORIS_Anima_Config,+ LoRA_LyCORIS_FLUX_Config,+ LoRA_LyCORIS_Flux2_Config,LoRA_LyCORIS_Krea2_Config,LoRA_LyCORIS_LTX2_Config,LoRA_LyCORIS_MiniMaxH3_Config,+ LoRA_LyCORIS_QwenImage_Config,LoRA_LyCORIS_Wan_Config,+ LoRA_LyCORIS_ZImage_Config,)from invokeai.backend.model_manager.taxonomy import BaseModelType@@ -156,7 +160,19 @@ def test_an_ltx2_lora_identifies_as_ltx2(prefix: str) -> None:@pytest.mark.parametrize("other",- [LoRA_LyCORIS_Wan_Config, LoRA_LyCORIS_MiniMaxH3_Config, LoRA_LyCORIS_Anima_Config, LoRA_LyCORIS_Krea2_Config],+ [+ LoRA_LyCORIS_Wan_Config,+ LoRA_LyCORIS_MiniMaxH3_Config,+ LoRA_LyCORIS_Anima_Config,+ LoRA_LyCORIS_Krea2_Config,+ # These four also precede the LTX-2 entry in the union, so they are the ones whose order+ # actually decides which config claims a file. Omitting them left the exclusivity this+ # file's docstring promises resting on the four that happen to come after.+ LoRA_LyCORIS_FLUX_Config,+ LoRA_LyCORIS_Flux2_Config,+ LoRA_LyCORIS_QwenImage_Config,+ LoRA_LyCORIS_ZImage_Config,+ ],ids=lambda cls: cls.__name__,)def test_an_ltx2_lora_is_rejected_by_every_other_probe(other) -> None:@@ -194,11 +210,22 @@ def test_the_ltx2_probe_requires_a_lora_suffix() -> None:assert not matched-def test_the_ltx2_probe_rejects_lycoris_variants() -> None:- """LoKR/LoHA/DoRA are a different patch shape than the conversion emits. Refusing at install- turns a generation-time failure into a clear 'not supported'."""+ "magnitude_key",+ [+ "dora_scale",+ # The PEFT / ai-toolkit spelling. LTX-2 LoRAs ship in the PEFT layout, so this is the one+ # the family will actually meet -- and DoRA is the only variant that reaches this guard,+ # since LoKR and LoHA files carry no lora_A/lora_B and fail the generic suffix test first.+ "lora_magnitude_vector.weight",+ "magnitude",+ ],+)+def test_the_ltx2_probe_rejects_dora_in_either_spelling(magnitude_key: str) -> None:+ """A different patch shape than the conversion emits. Admitting one defers the failure to the+ denoise -- after the 22B transformer has loaded -- which is what this guard exists to prevent."""sd = _ltx2_distilled_keys()- sd["diffusion_model.transformer_blocks.0.attn1.to_q.dora_scale"] = _z(4096)+ sd[f"diffusion_model.transformer_blocks.0.attn1.to_q.{magnitude_key}"] = _z(4096)matched, error = _probe(LoRA_LyCORIS_LTX2_Config, sd)@@ -206,6 +233,15 @@ def test_the_ltx2_probe_rejects_lycoris_variants() -> None:assert "LoKR/LoHA/DoRA" in str(error)+def test_the_ltx2_probe_takes_the_comfy_prefix_the_converter_handles() -> None:+ """The converter strips `model.diffusion_model.` (diffusers' own rename table does), so refusing+ it at install would reject a file that converts perfectly."""+ matched, result = _probe(LoRA_LyCORIS_LTX2_Config, _ltx2_distilled_keys("model.diffusion_model."))++ assert matched, result+ assert result.base is BaseModelType.LTX2++def test_the_ltx2_probe_rejects_nested_prefixes() -> None:"""The converter strips exactly one prefix. Admitting a doubled one would map every layer ontoa nonexistent module path — a LoRA that installs, loads, and applies nothing."""