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(webv2): take steps and CFG from the new model when the panel was never shown them
Lincoln Stein737093c149e3
diff --git a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.test.ts b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.test.tsindex 46778b7a2b..0993fcdd58 100644--- a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.test.ts+++ b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.test.ts@@ -1604,6 +1604,99 @@ describe('LTX-2 policy', () => {expect(toDev.settings.negativePrompt).toBe('');});+ it("takes dev's steps and CFG from a panel that was never shown them", () => {+ // The distilled variant pins 8 steps at CFG 1 and hides both controls, and only the scales+ // refill on their own, so dev used to arrive at 8/1 -- dev with no guidance at all, which is+ // the recipe that produces washed-out output.+ const catalog = [ltx2('ltx2_distilled'), ltx2('ltx2_dev'), LTX2_COMPONENTS, LTX2_ENCODER];++ const result = getVideoModelSelectionResult({+ currentSettings: getDefaultVideoSettings(ltx2('ltx2_distilled'), catalog),+ model: ltx2('ltx2_dev'),+ models: catalog,+ });++ expect({ cfgScale: result.settings.cfgScale, steps: result.settings.steps }).toEqual({ cfgScale: 3, steps: 30 });+ });++ it("leaves another family's own numbers alone when its panel was showing them", () => {+ // The deliberate boundary: Wan shows steps and CFG, so 40/5 on screen is the user's to change+ // and LTX-2 dev does not overrule it. Only a control the previous variant never showed is+ // treated as a recommendation the panel was merely holding.+ const catalog = [wanModel('t2v_a14b'), ltx2('ltx2_dev'), LTX2_COMPONENTS, LTX2_ENCODER];+ const onWan = getDefaultVideoSettings(wanModel('t2v_a14b'), catalog);++ const toDev = getVideoModelSelectionResult({ currentSettings: onWan, model: ltx2('ltx2_dev'), models: catalog });++ expect({ cfgScale: toDev.settings.cfgScale, steps: toDev.settings.steps }).toEqual({+ cfgScale: onWan.cfgScale,+ steps: onWan.steps,+ });+ expect(onWan.steps).not.toBe(30);+ });++ it('never rewrites steps or CFG the previous panel put on screen, whatever they hold', () => {+ // Wan shows both controls, so its numbers are the user's whatever they are -- including numbers+ // that happen to match a default. The comparison is against the variant's static recipe for+ // this reason: getDefaultVideoSettings applies an installed accelerator, so with the Lightning+ // pair in the catalog Wan's "default" is the 4-step fast path, and a hand-typed 4 at CFG 1+ // would read as a carried-over default and be rewritten to 40/5.+ const catalog = [wanModel('t2v_a14b'), ltx2('ltx2_dev'), LIGHTNING_T2V_HIGH, LIGHTNING_T2V_LOW, LTX2_COMPONENTS];+ const typed = {+ ...getDefaultVideoSettings(wanModel('t2v_a14b'), catalog),+ acceleratorEnabled: false,+ acceleratorLoraKeys: [],+ cfgScale: 1,+ loras: [],+ steps: 4,+ };++ const toDev = getVideoModelSelectionResult({ currentSettings: typed, model: ltx2('ltx2_dev'), models: catalog });++ expect({ cfgScale: toDev.settings.cfgScale, steps: toDev.settings.steps }).toEqual({ cfgScale: 1, steps: 4 });+ });++ it('keeps a tuned CFG across a detour through the fixed-schedule variant', () => {+ // The mirror of the rule above: a number the user chose is not the previous model's+ // recommendation, so it survives a variant that hides the control. The step count cannot --+ // distilled pins it on the way in and says so -- but it must land on dev's 30, not distilled's 8.+ const catalog = [ltx2('ltx2_distilled'), ltx2('ltx2_dev'), LTX2_COMPONENTS, LTX2_ENCODER];+ const tuned = { ...getDefaultVideoSettings(ltx2('ltx2_dev'), catalog), cfgScale: 6, steps: 45 };++ const toDistilled = getVideoModelSelectionResult({+ currentSettings: tuned,+ model: ltx2('ltx2_distilled'),+ models: catalog,+ });++ expect(toDistilled.settings.cfgScale).toBe(6);+ expect(toDistilled.clearedLabels).toContain('Steps');++ const back = getVideoModelSelectionResult({+ currentSettings: toDistilled.settings,+ model: ltx2('ltx2_dev'),+ models: catalog,+ });++ expect({ cfgScale: back.settings.cfgScale, steps: back.settings.steps }).toEqual({ cfgScale: 6, steps: 30 });+ });++ it('leaves steps and CFG alone when the panel it came from cannot be resolved', () => {+ // Without the previous model there is nothing to compare against, and guessing would clobber+ // tuned values on any panel whose model is missing from the catalog.+ const catalog = [ltx2('ltx2_dev'), LTX2_COMPONENTS, LTX2_ENCODER];+ const orphaned = {+ ...getDefaultVideoSettings(ltx2('ltx2_distilled'), catalog),+ cfgScale: 6,+ modelKey: 'uninstalled-key',+ steps: 45,+ };++ const toDev = getVideoModelSelectionResult({ currentSettings: orphaned, model: ltx2('ltx2_dev'), models: catalog });++ expect({ cfgScale: toDev.settings.cfgScale, steps: toDev.settings.steps }).toEqual({ cfgScale: 6, steps: 45 });+ });+it('seeds the list when the panel it came from can no longer be resolved', () => {// The previous model was uninstalled under the panel, or the panel was never seeded at all. The// automatic re-pick has to reach the same place the manual switch does, or dev runs at CFG 3diff --git a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.tsindex ebf8f77890..66c55f1409 100644--- a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts+++ b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts@@ -1843,11 +1843,11 @@ export const getVideoModelSelectionResult = ({// hides the field, so clearing the box, detouring through distilled and coming back restores the// list; dev quietly running without it is the worse failure. Filling an empty field in is not a// clearing, so it takes no label.+ const previousModel = models.find((entry) => entry.key === currentSettings.modelKey);+ const previousConfig = previousModel && isSupportedVideoModel(previousModel) ? getVideoConfig(previousModel) : null;+if (config.defaultNegativePrompt && next.negativePromptEnabled && !next.negativePrompt.trim()) {- const previous = models.find((entry) => entry.key === currentSettings.modelKey);- const previousCarriesNone = previous- ? isSupportedVideoModel(previous) && getVideoConfig(previous).negativePrompt.usage === 'never'- : true;+ const previousCarriesNone = previousModel ? previousConfig?.negativePrompt.usage === 'never' : true;if (previousCarriesNone) {next.negativePrompt = config.defaultNegativePrompt;@@ -1860,6 +1860,40 @@ export const getVideoModelSelectionResult = ({addClearedLabel(clearedLabels, 'Steps');}+ // Steps and CFG have no "carries none" sentinel like the scales above, so a control the previous+ // variant did not offer stands in for one: the user cannot have chosen a number they were never+ // shown, and if it is still that variant's own recommendation it is not one they carried in+ // either. Both conditions are needed. The fixed-schedule variant pins 8 steps at CFG 1, and+ // without this dev arrives holding them -- dev with no guidance at all, which is the recipe that+ // produces washed-out output.+ //+ // Compared against the variant's static recipe, never `getDefaultVideoSettings`: that applies an+ // installed accelerator's numbers, so on a machine with the Lightning LoRAs a Wan panel's+ // "default" is 4/1, and comparing against it would both miss real carry-overs and rewrite a step+ // count the user typed. A control the previous variant *did* show is the user's and is never+ // touched, whatever it holds.+ //+ // Skipped while the accelerator is on: the fast path owns steps and CFG and restores the model's+ // own when it turns off, so its numbers are not a variant's recommendation to compare. An+ // unresolvable previous model leaves both alone -- unlike the blank negative prompt above, where+ // seeding only adds, guessing here would rewrite tuned values on any panel whose model is missing+ // from the catalog. Placed after the fixed-schedule reset so a step count the user did choose is+ // still reported as taken away; adopting a recommendation they never set is not a clearing, and+ // both numbers are on screen.+ //+ // Known gap: a value the user deliberately set to exactly the hiding variant's own default (CFG 1+ // on dev, say) is indistinguishable from one carried in and is replaced. Telling them apart needs+ // a real sentinel on both fields, which is a change to the persisted settings across every family.+ if (!next.acceleratorEnabled && previousConfig) {+ if (!previousConfig.stepsEditable && next.steps === previousConfig.defaults.steps) {+ next.steps = config.defaults.steps;+ }++ if (!previousConfig.cfg.visible && next.cfgScale === previousConfig.defaults.cfgScale) {+ next.cfgScale = config.defaults.cfgScale;+ }+ }+const compatibleLoras = next.loras.filter((lora) => isLoraCompatibleWithModel(lora.model, model));if (compatibleLoras.length !== next.loras.length) {