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(upscale): keep the editor's initial load graph unchanged
Alexander Eichhorn767a8ed0db41
diff --git a/invokeai/frontend/webv2/src/features/upscale/core/__snapshots__/upscaleIndexClippedStarts.json b/invokeai/frontend/webv2/src/features/upscale/core/__snapshots__/upscaleIndexClippedStarts.jsonindex 28c5d5ff3b..bcb7954433 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/__snapshots__/upscaleIndexClippedStarts.json+++ b/invokeai/frontend/webv2/src/features/upscale/core/__snapshots__/upscaleIndexClippedStarts.json@@ -1,5 +1,5 @@{- "_comment": "Generated by src/features/upscale/core/denoisingStart.test.ts; regenerate with `vitest -u`. Consumed by tests/app/invocations/test_upscale_index_clipped_starts.py, which drives the real z_image_denoise and anima_denoise with each denoisingStart and checks the pass enters at the step nearest fluxEntrySigma.",+ "_comment": "Generated by src/features/upscale/core/indexClippedStarts.test.ts; regenerate with `vitest -u`. Consumed by tests/app/invocations/test_upscale_index_clipped_starts.py, which drives the real z_image_denoise and anima_denoise with each denoisingStart and checks the pass enters at the step nearest fluxEntrySigma.","cases": [{"base": "anima",diff --git a/invokeai/frontend/webv2/src/features/upscale/core/denoisingStart.ts b/invokeai/frontend/webv2/src/features/upscale/core/denoisingStart.tsdeleted file mode 100644index ff2690bd9a..0000000000--- a/invokeai/frontend/webv2/src/features/upscale/core/denoisingStart.ts+++ /dev/null@@ -1,56 +0,0 @@-/**- * Where on its schedule the second pass starts, from the Creativity slider.- *- * Creativity is defined by where FLUX enters: `flux_denoise` clips the schedule by *value*, so a- * start of 0.499 enters at sigma 0.501 whatever the shift or step count. Z-Image and Anima clip by- * *index* instead (`start_idx = int(denoising_start * steps)` on a shifted schedule), so the same- * number enters far noisier there -- 0.499 starts Z-Image at sigma 0.78. Handing them the step whose- * sigma is nearest FLUX's keeps one slider meaning one thing. This module goes away when those- * nodes clip by value.- */--/** The legacy formula: creativity -10..10 to a value-clipped start of 0.998..0. */-export const getUpscaleDenoisingStart = (creativity: number): number => ((creativity * -1 + 10) * 4.99) / 100;--/** `z_image_denoise._calculate_shift`, held at the fit's 4096-token end since the clamp (#378). */-const Z_IMAGE_SHIFT_MIN_SEQ_LEN = 256;-const Z_IMAGE_SHIFT_MAX_SEQ_LEN = 4096;-const Z_IMAGE_BASE_SHIFT = 0.5;-const Z_IMAGE_MAX_SHIFT = 1.15;--/** Z-Image's linear shift for a frame: one token per 16x16 pixels, as `z_image_denoise` patches it. */-export const zImageScheduleShift = ({ width, height }: { width: number; height: number }): number => {- const seqLen = Math.min(Math.floor(width / 16) * Math.floor(height / 16), Z_IMAGE_SHIFT_MAX_SEQ_LEN);- const slope = (Z_IMAGE_MAX_SHIFT - Z_IMAGE_BASE_SHIFT) / (Z_IMAGE_SHIFT_MAX_SEQ_LEN - Z_IMAGE_SHIFT_MIN_SEQ_LEN);-- return Math.exp(seqLen * slope + Z_IMAGE_BASE_SHIFT - slope * Z_IMAGE_SHIFT_MIN_SEQ_LEN);-};--/** `ANIMA_SHIFT`: Anima's schedule is shifted by a constant, not by resolution. */-export const ANIMA_SCHEDULE_SHIFT = 3;--/**- * The start an index-clipping node needs to enter where a value-clipping one would.- *- * Both nodes build `sigma = shift * t / (1 + (shift - 1) * t)` at `t = 1 - i / steps` and begin at- * `i = int(start * steps)`. This picks the `i` whose sigma is nearest `1 - valueStart` and aims at- * the middle of that step, so float error in the node's product cannot floor it one step short.- */-export const getIndexClippedDenoisingStart = (valueStart: number, steps: number, shift: number): number => {- const target = 1 - valueStart;- let entryIndex = 0;- let entryDistance = Number.POSITIVE_INFINITY;-- // The last index would leave nothing to denoise, so it is never a candidate.- for (let index = 0; index < steps; index += 1) {- const t = 1 - index / steps;- const distance = Math.abs((shift * t) / (1 + (shift - 1) * t) - target);-- if (distance < entryDistance) {- entryIndex = index;- entryDistance = distance;- }- }-- return entryIndex === 0 ? 0 : (entryIndex + 0.5) / steps;-};diff --git a/invokeai/frontend/webv2/src/features/upscale/core/graph.test.ts b/invokeai/frontend/webv2/src/features/upscale/core/graph.test.tsindex d335d9710b..df8176afe7 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/graph.test.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/graph.test.ts@@ -6,8 +6,12 @@ import { describe, expect, it } from 'vitest';import type { TileControlNetModelConfig, UpscaleWidgetValues } from './types';-import { getUpscaleDenoisingStart } from './denoisingStart';-import { compileUpscaleGraph, getUpscaleControlNetValues, getZImageTileControlValues } from './graph';+import {+ compileUpscaleGraph,+ getUpscaleControlNetValues,+ getUpscaleDenoisingStart,+ getZImageTileControlValues,+} from './graph';import { createDefaultUpscaleWidgetValues } from './settings';const model = (key: string, type: string, base: string, name = key): ModelConfig => ({diff --git a/invokeai/frontend/webv2/src/features/upscale/core/graph.ts b/invokeai/frontend/webv2/src/features/upscale/core/graph.tsindex 174ccf5f4a..86e1f4c9ff 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/graph.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/graph.ts@@ -21,7 +21,6 @@ import { coerceSchedulerForGraph, isBundledMainForBase } from '@features/generatimport type { UpscaleBase } from './settings';import type { CompiledUpscaleGraph, UpscaleWidgetValues } from './types';-import { getIndexClippedDenoisingStart, getUpscaleDenoisingStart } from './denoisingStart';import {activeUpscaleComponents,getUpscaleValidationReasons,@@ -30,6 +29,39 @@ import {wiresUpscaleNegativePrompt,} from './settings';+/** The legacy formula: creativity -10..10 to a value-clipped start of 0.998..0. */+export const getUpscaleDenoisingStart = (creativity: number): number => ((creativity * -1 + 10) * 4.99) / 100;++/**+ * The start an index-clipping node needs to enter where a value-clipping one would.+ *+ * Creativity is defined by where FLUX enters: `flux_denoise` clips the schedule by *value*, so a start+ * of 0.499 enters at sigma 0.501 whatever the shift or step count. Z-Image and Anima clip by *index*+ * instead, so the same number enters far noisier there -- 0.499 starts Z-Image at sigma 0.78. Both+ * build `sigma = shift * t / (1 + (shift - 1) * t)` at `t = 1 - i / steps` and begin at+ * `i = int(start * steps)`. This picks the `i` whose sigma is nearest `1 - valueStart` and aims at the+ * middle of that step, so float error in the node's product cannot floor it one step short. It goes+ * away when those nodes clip by value; `test_upscale_index_clipped_starts.py` fails when they do.+ */+export const getIndexClippedDenoisingStart = (valueStart: number, steps: number, shift: number): number => {+ const target = 1 - valueStart;+ let entryIndex = 0;+ let entryDistance = Number.POSITIVE_INFINITY;++ // The last index would leave nothing to denoise, so it is never a candidate.+ for (let index = 0; index < steps; index += 1) {+ const t = 1 - index / steps;+ const distance = Math.abs((shift * t) / (1 + (shift - 1) * t) - target);++ if (distance < entryDistance) {+ entryIndex = index;+ entryDistance = distance;+ }+ }++ return entryIndex === 0 ? 0 : (entryIndex + 0.5) / steps;+};+export const getUpscaleControlNetValues = (structure: number) => {const splitPoint = (structure + 10) * 0.025 + 0.3;diff --git a/invokeai/frontend/webv2/src/features/upscale/core/denoisingStart.test.ts b/invokeai/frontend/webv2/src/features/upscale/core/indexClippedStarts.test.tssimilarity index 94%rename from invokeai/frontend/webv2/src/features/upscale/core/denoisingStart.test.tsrename to invokeai/frontend/webv2/src/features/upscale/core/indexClippedStarts.test.tsindex 4e559b9d76..f9db4c6298 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/denoisingStart.test.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/indexClippedStarts.test.ts@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest';import type { UpscaleBase } from './settings';-import { getIndexClippedDenoisingStart, getUpscaleDenoisingStart } from './denoisingStart';+import { getIndexClippedDenoisingStart, getUpscaleDenoisingStart } from './graph';import { UPSCALE_ARCHITECTURES } from './settings';const CREATIVITIES = [-10, -5, 0, 5, 8, 10];@@ -43,7 +43,7 @@ describe('index-clipped denoising starts', () => {);const fixture = {_comment:- 'Generated by src/features/upscale/core/denoisingStart.test.ts; regenerate with `vitest -u`. ' ++ 'Generated by src/features/upscale/core/indexClippedStarts.test.ts; regenerate with `vitest -u`. ' +'Consumed by tests/app/invocations/test_upscale_index_clipped_starts.py, which drives the real ' +'z_image_denoise and anima_denoise with each denoisingStart and checks the pass enters at the ' +'step nearest fluxEntrySigma.',diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.tsindex abd8363c2f..29a7ce8699 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts@@ -32,7 +32,26 @@ import { isSeedMode, SEED_MAX } from '@platform/core/seed';import type { SpandrelModelConfig, TileControlNetModelConfig, UpscaleWidgetValues } from './types';-import { ANIMA_SCHEDULE_SHIFT, zImageScheduleShift } from './denoisingStart';+// The schedule shifts of the two denoise nodes that clip `denoising_start` by step index, for the+// table's `indexClippedShift`; `getIndexClippedDenoisingStart` in graph.ts uses them to start those+// nodes where FLUX would. They go away when those nodes clip by value.++/** `z_image_denoise._calculate_shift`, held at the fit's 4096-token end since the clamp (#378). */+const Z_IMAGE_SHIFT_MIN_SEQ_LEN = 256;+const Z_IMAGE_SHIFT_MAX_SEQ_LEN = 4096;+const Z_IMAGE_BASE_SHIFT = 0.5;+const Z_IMAGE_MAX_SHIFT = 1.15;++/** Z-Image's linear shift for a frame: one token per 16x16 pixels, as `z_image_denoise` patches it. */+const zImageScheduleShift = ({ width, height }: { width: number; height: number }): number => {+ const seqLen = Math.min(Math.floor(width / 16) * Math.floor(height / 16), Z_IMAGE_SHIFT_MAX_SEQ_LEN);+ const slope = (Z_IMAGE_MAX_SHIFT - Z_IMAGE_BASE_SHIFT) / (Z_IMAGE_SHIFT_MAX_SEQ_LEN - Z_IMAGE_SHIFT_MIN_SEQ_LEN);++ return Math.exp(seqLen * slope + Z_IMAGE_BASE_SHIFT - slope * Z_IMAGE_SHIFT_MIN_SEQ_LEN);+};++/** `ANIMA_SHIFT`: Anima's schedule is shifted by a constant, not by resolution. */+const ANIMA_SCHEDULE_SHIFT = 3;/** A text encoder the widget can be asked for; each is its own persisted field. */export type UpscaleComponentField = 't5EncoderModel' | 'clipEmbedModel' | 'qwen3EncoderModel' | 'qwen35EncoderModel';diff --git a/tests/app/invocations/test_upscale_index_clipped_starts.py b/tests/app/invocations/test_upscale_index_clipped_starts.pyindex a3fdd10eea..3c4d39ea03 100644--- a/tests/app/invocations/test_upscale_index_clipped_starts.py+++ b/tests/app/invocations/test_upscale_index_clipped_starts.py@@ -2,10 +2,11 @@`flux_denoise` clips `denoising_start` by sigma value; `z_image_denoise` and `anima_denoise` clip it bystep index on a shifted schedule, so the same number enters them far noisier. The widget therefore-does not send them FLUX's start: `features/upscale/core/denoisingStart.ts` picks the step whose sigma-is nearest the one FLUX would enter at, from its own copy of each node's shift and clipping rule.+does not send them FLUX's start: `getIndexClippedDenoisingStart` (`features/upscale/core/graph.ts`)+picks the step whose sigma is nearest the one FLUX would enter at, from its own copy of each node's+shift (`settings.ts`) and clipping rule.-`upscaleIndexClippedStarts.json`, written by `denoisingStart.test.ts` (regenerate with `vitest -u`),+`upscaleIndexClippedStarts.json`, written by `indexClippedStarts.test.ts` (regenerate with `vitest -u`),records what the widget sends. Each case here drives the real `_run_diffusion` -- the real shift, thereal `_get_sigmas`, the real clipping and the real img2img blend -- and reads the entry sigma back outof the blended tensor. It has to be the step nearest FLUX's entry. A change to either node's shift,