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): keep the upscale capability table out of the editor's initial bundle
Alexander Eichhornd3968ea03c7c
diff --git a/invokeai/frontend/webv2/src/features/upscale/core/architectures.ts b/invokeai/frontend/webv2/src/features/upscale/core/architectures.tsdeleted file mode 100644index 9ad75d6bfd..0000000000--- a/invokeai/frontend/webv2/src/features/upscale/core/architectures.ts+++ /dev/null@@ -1,95 +0,0 @@-import type { MainModelConfig } from '@features/generation/contracts';--/**- * Which main-model architectures the Upscale widget can drive, and what each one needs.- *- * This is the single source of truth: the graph compiler keys its builders off the same record- * (`UPSCALE_PATH_BUILDERS`, enforced by `satisfies`), validation reads the requirements from here,- * and the widget shows a control only where the architecture has something for it to steer. Adding- * an architecture should mean adding one entry and one builder, not hunting for a base string.- */-export interface UpscaleArchitecture {- /**- * A tile ControlNet anchors the second pass to the upscaled frame. Where one exists the widget- * requires it and the Structure slider drives its weights; where it does not, Structure has- * nothing to scale and is hidden rather than left inert.- */- readonly usesTileControlNet: boolean;- /**- * Whether the pipeline's parts must be picked separately. FLUX transformers ship as bare- * checkpoints far more often than not, and `flux_model_loader` refuses those without an explicit- * T5 encoder, CLIP Embed *and* VAE -- only a complete SDNQ pipeline install can supply its own.- */- readonly needsExplicitComponents: boolean;- /**- * The size granularity the architecture's denoise node demands. Spandrel's autoscale rounds to a- * multiple of 8, which `flux_denoise` (multiple_of=16) rejects outright — after the upscale has- * already run. Where this is coarser than 8 the compiler resizes the frame down to it and passes- * the size as a literal, so the graph cannot be built with a size the backend will refuse.- */- readonly denoiseGrid: number;- /** Guidance-distilled architectures ignore a negative prompt; showing one invites a silent no-op. */- readonly usesNegativePrompt: boolean;- /** Shown in validation messages, so a user reads "FLUX.1" rather than "flux". */- readonly label: string;-}--export const UPSCALE_ARCHITECTURES = {- 'sd-1': {- denoiseGrid: 8,- label: 'SD1.5',- needsExplicitComponents: false,- usesNegativePrompt: true,- usesTileControlNet: true,- },- sdxl: {- denoiseGrid: 8,- label: 'SDXL',- needsExplicitComponents: false,- usesNegativePrompt: true,- usesTileControlNet: true,- },- flux: {- denoiseGrid: 16,- label: 'FLUX.1',- needsExplicitComponents: true,- usesNegativePrompt: false,- usesTileControlNet: false,- },-} as const satisfies Record<string, UpscaleArchitecture>;--export type UpscaleBase = keyof typeof UPSCALE_ARCHITECTURES;--export const isUpscaleBase = (base: unknown): base is UpscaleBase =>- typeof base === 'string' && base in UPSCALE_ARCHITECTURES;--export const upscaleArchitectureFor = (model: MainModelConfig | null): UpscaleArchitecture | null =>- model && isUpscaleBase(model.base) ? UPSCALE_ARCHITECTURES[model.base] : null;--/** "SD1.5, SDXL or FLUX.1" — built from the table so the copy cannot go stale. */-export const supportedUpscaleArchitectureLabels = (): string => {- const labels = Object.values(UPSCALE_ARCHITECTURES).map((architecture) => architecture.label);- const last = labels[labels.length - 1];-- return labels.length > 1 ? `${labels.slice(0, -1).join(', ')} or ${last}` : (last ?? '');-};--/**- * A self-contained SDNQ pipeline carries its own transformer, CLIP, T5 and VAE, so asking the user- * to pick them would be busywork. Every other FLUX format must have them chosen explicitly.- *- * The backend is stricter still -- it also checks the pipeline actually contains those submodels- * (`is_self_contained_sdnq_flux1_pipeline`), which the model list does not expose. An SDNQ install- * missing a submodel therefore passes here and is refused by the loader with a precise message,- * which is the right way round.- */-export const needsExplicitComponents = (model: MainModelConfig | null): boolean =>- (upscaleArchitectureFor(model)?.needsExplicitComponents ?? false) && model?.format !== 'sdnq_quantized';--/** What Spandrel's autoscale produces: the scaled dimension floored to a multiple of 8. */-export const spandrelAutoscaleDimension = (dimension: number, scale: number): number =>- Math.floor(Math.trunc(dimension * scale) / 8) * 8;--/** The same dimension floored to what the architecture's denoise node will accept. */-export const upscaleDenoiseDimension = (dimension: number, scale: number, grid: number): number =>- Math.max(grid, Math.floor(spandrelAutoscaleDimension(dimension, scale) / grid) * grid);diff --git a/invokeai/frontend/webv2/src/features/upscale/core/graph.ts b/invokeai/frontend/webv2/src/features/upscale/core/graph.tsindex bfb2cac48f..0b41d230c2 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/graph.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/graph.ts@@ -17,11 +17,10 @@ import {} from '@features/generation/graph';import { coerceSchedulerForGraph } from '@features/generation/settings';-import type { UpscaleBase } from './architectures';+import type { UpscaleBase } from './settings';import type { CompiledUpscaleGraph, UpscaleWidgetValues } from './types';-import { upscaleArchitectureFor, upscaleDenoiseDimension } from './architectures';-import { getUpscaleValidationReasons } from './settings';+import { getUpscaleValidationReasons, upscaleArchitectureFor, upscaleDenoiseDimension } from './settings';export const getUpscaleDenoisingStart = (creativity: number): number => ((creativity * -1 + 10) * 4.99) / 100;diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.test.tsindex 3ace6f83f5..db863226b6 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts@@ -4,13 +4,14 @@ import type { ModelConfig } from '@features/models';import { seedArchitectureCapabilities } from '@features/generation/core/architectureCapabilities.testing';import { describe, expect, it } from 'vitest';-import { spandrelAutoscaleDimension, upscaleDenoiseDimension } from './architectures';import {clearDeletedUpscaleInput,createDefaultUpscaleWidgetValues,getUpscaleOutputDimensions,getUpscaleValidationReasons,normalizeUpscaleWidgetValues,+ spandrelAutoscaleDimension,+ upscaleDenoiseDimension,syncUpscaleWidgetValuesWithModels,UPSCALE_PRESETS,} from './settings';diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.tsindex 3a166dbcd9..3fec6fd6cc 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts@@ -27,12 +27,99 @@ import { isSeedMode, SEED_MAX } from '@platform/core/seed';import type { SpandrelModelConfig, TileControlNetModelConfig, UpscaleWidgetValues } from './types';-import {- isUpscaleBase,- needsExplicitComponents,- supportedUpscaleArchitectureLabels,- upscaleArchitectureFor,-} from './architectures';+/**+ * Which main-model architectures the Upscale widget can drive, and what each one needs.+ *+ * This is the single source of truth: the graph compiler keys its builders off the same record+ * (`UPSCALE_PATH_BUILDERS`, enforced by `satisfies`), validation reads the requirements from here,+ * and the widget shows a control only where the architecture has something for it to steer. Adding+ * an architecture should mean adding one entry and one builder, not hunting for a base string.+ */+export interface UpscaleArchitecture {+ /**+ * A tile ControlNet anchors the second pass to the upscaled frame. Where one exists the widget+ * requires it and the Structure slider drives its weights; where it does not, Structure has+ * nothing to scale and is hidden rather than left inert.+ */+ readonly usesTileControlNet: boolean;+ /**+ * Whether the pipeline's parts must be picked separately. FLUX transformers ship as bare+ * checkpoints far more often than not, and `flux_model_loader` refuses those without an explicit+ * T5 encoder, CLIP Embed *and* VAE -- only a complete SDNQ pipeline install can supply its own.+ */+ readonly needsExplicitComponents: boolean;+ /**+ * The size granularity the architecture's denoise node demands. Spandrel's autoscale rounds to a+ * multiple of 8, which `flux_denoise` (multiple_of=16) rejects outright — after the upscale has+ * already run. Where this is coarser than 8 the compiler resizes the frame down to it and passes+ * the size as a literal, so the graph cannot be built with a size the backend will refuse.+ */+ readonly denoiseGrid: number;+ /** Guidance-distilled architectures ignore a negative prompt; showing one invites a silent no-op. */+ readonly usesNegativePrompt: boolean;+ /** Shown in validation messages, so a user reads "FLUX.1" rather than "flux". */+ readonly label: string;+}++export const UPSCALE_ARCHITECTURES = {+ 'sd-1': {+ denoiseGrid: 8,+ label: 'SD1.5',+ needsExplicitComponents: false,+ usesNegativePrompt: true,+ usesTileControlNet: true,+ },+ sdxl: {+ denoiseGrid: 8,+ label: 'SDXL',+ needsExplicitComponents: false,+ usesNegativePrompt: true,+ usesTileControlNet: true,+ },+ flux: {+ denoiseGrid: 16,+ label: 'FLUX.1',+ needsExplicitComponents: true,+ usesNegativePrompt: false,+ usesTileControlNet: false,+ },+} as const satisfies Record<string, UpscaleArchitecture>;++export type UpscaleBase = keyof typeof UPSCALE_ARCHITECTURES;++export const isUpscaleBase = (base: unknown): base is UpscaleBase =>+ typeof base === 'string' && base in UPSCALE_ARCHITECTURES;++export const upscaleArchitectureFor = (model: MainModelConfig | null): UpscaleArchitecture | null =>+ model && isUpscaleBase(model.base) ? UPSCALE_ARCHITECTURES[model.base] : null;++/** "SD1.5, SDXL or FLUX.1" — built from the table so the copy cannot go stale. */+export const supportedUpscaleArchitectureLabels = (): string => {+ const labels = Object.values(UPSCALE_ARCHITECTURES).map((architecture) => architecture.label);+ const last = labels[labels.length - 1];++ return labels.length > 1 ? `${labels.slice(0, -1).join(', ')} or ${last}` : (last ?? '');+};++/**+ * A self-contained SDNQ pipeline carries its own transformer, CLIP, T5 and VAE, so asking the user+ * to pick them would be busywork. Every other FLUX format must have them chosen explicitly.+ *+ * The backend is stricter still -- it also checks the pipeline actually contains those submodels+ * (`is_self_contained_sdnq_flux1_pipeline`), which the model list does not expose. An SDNQ install+ * missing a submodel therefore passes here and is refused by the loader with a precise message,+ * which is the right way round.+ */+export const needsExplicitComponents = (model: MainModelConfig | null): boolean =>+ (upscaleArchitectureFor(model)?.needsExplicitComponents ?? false) && model?.format !== 'sdnq_quantized';++/** What Spandrel's autoscale produces: the scaled dimension floored to a multiple of 8. */+export const spandrelAutoscaleDimension = (dimension: number, scale: number): number =>+ Math.floor(Math.trunc(dimension * scale) / 8) * 8;++/** The same dimension floored to what the architecture's denoise node will accept. */+export const upscaleDenoiseDimension = (dimension: number, scale: number, grid: number): number =>+ Math.max(grid, Math.floor(spandrelAutoscaleDimension(dimension, scale) / grid) * grid);export const UPSCALE_SCALE_SLIDER_MIN = 2;export const UPSCALE_SCALE_SLIDER_MAX = 8;diff --git a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleFormFields.tsx b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleFormFields.tsxindex d3ef4aa420..3b69dc59b0 100644--- a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleFormFields.tsx+++ b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleFormFields.tsx@@ -5,7 +5,7 @@ import type { UpscaleWidgetValues } from '@features/upscale/core/types';import { HStack, NumberInput, Stack, Switch, Text } from '@chakra-ui/react';import { NegativePromptField, PositivePromptField } from '@features/generation/components';import { areProjectPromptDraftsEqual } from '@features/generation/settings';-import { upscaleArchitectureFor } from '@features/upscale/core/architectures';+import { upscaleArchitectureFor } from '@features/upscale/core/settings';import { IconButton } from '@platform/ui/Button';import { MiddleTruncate } from '@platform/ui/MiddleTruncate';import { Trash2Icon } from 'lucide-react';diff --git a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsxindex 87fc2cac2b..c35b28b5b2 100644--- a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx+++ b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx@@ -16,14 +16,15 @@ import {} from '@features/generation/settings';import { ensureModelsLoaded, useModelsSelector } from '@features/models';import { ModelSelect } from '@features/models/react';-import { needsExplicitComponents, upscaleArchitectureFor } from '@features/upscale/core/architectures';import {createDefaultUpscaleWidgetValues,+ needsExplicitComponents,getUpscaleOutputDimensions,isSpandrelModelConfig,isSupportedUpscaleMainModel,isTileControlNetCandidate,normalizeUpscaleWidgetValues,+ upscaleArchitectureFor,syncUpscaleWidgetValuesWithModels,UPSCALE_CREATIVITY_MAX,UPSCALE_CREATIVITY_MIN,