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): recall Krea 2 conditioning rebalance from metadata
joshistoast923f0280eb6d
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.tsindex 6dd2840354..bdfe4897a3 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts@@ -13,6 +13,7 @@ import { buildImageRecallSettings, getImageRecallCapabilities } from './imageRecconst sdxlModel: MainModelConfig = { base: 'sdxl', key: 'sdxl-model', name: 'SDXL', type: 'main' };const sd1Model: MainModelConfig = { base: 'sd-1', key: 'sd1-model', name: 'SD 1.5', type: 'main' };const animaModel: MainModelConfig = { base: 'anima', key: 'anima-model', name: 'Anima', type: 'main' };+const krea2Model: MainModelConfig = { base: 'krea-2', key: 'krea2-model', name: 'Krea 2', type: 'main' };const vaeModel: VaeModelConfig = { base: 'sd-1', key: 'vae-model', name: 'SD 1.5 VAE', type: 'vae' };const qwenImageVae: VaeModelConfig = { base: 'qwen-image', key: 'qwen-vae', name: 'Qwen VAE', type: 'vae' };const animaQwen3: ComponentModelConfig = {@@ -582,4 +583,91 @@ describe('image recall', () => {expect(result?.values.qwenVLEncoderModel).toBeNull();expect(result?.fields).toContain('components');});++ describe('krea-2 conditioning rebalance', () => {+ const krea2Metadata = {+ krea2_rebalance_enabled: true,+ krea2_rebalance_multiplier: 6.5,+ krea2_rebalance_weights: '1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0',+ model: { key: krea2Model.key },+ };++ it('restores the curve and gain a Krea-2 image was generated with', () => {+ const result = buildImageRecallSettings({+ currentValues: createValues(),+ image,+ kind: 'all',+ metadata: krea2Metadata,+ models: [],+ supportedModels: [krea2Model],+ vaeModels: [],+ });++ expect(result?.values.krea2RebalanceEnabled).toBe(true);+ expect(result?.values.krea2RebalanceMultiplier).toBe(6.5);+ expect(result?.values.krea2RebalanceWeights).toBe('1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0');+ expect(result?.fields).toContain('krea2Rebalance');+ });++ it('recalls the rebalance on a remix too', () => {+ const result = buildImageRecallSettings({+ currentValues: createValues(),+ image,+ kind: 'remix',+ metadata: krea2Metadata,+ models: [],+ supportedModels: [krea2Model],+ vaeModels: [],+ });++ expect(result?.fields).toContain('krea2Rebalance');+ });++ it('ignores the rebalance when the recalled model is not Krea-2', () => {+ const result = buildImageRecallSettings({+ currentValues: createValues(),+ image,+ kind: 'all',+ metadata: { ...krea2Metadata, model: { key: sdxlModel.key } },+ models: [],+ supportedModels: [sdxlModel],+ vaeModels: [],+ });++ expect(result?.values.krea2RebalanceEnabled).toBe(false);+ expect(result?.fields).not.toContain('krea2Rebalance');+ });++ it('drops a weights string the backend would reject', () => {+ // The string is forwarded to the node verbatim, so a malformed blob must not+ // become a queued item that fails mid-generation.+ const result = buildImageRecallSettings({+ currentValues: createValues(),+ image,+ kind: 'all',+ metadata: { ...krea2Metadata, krea2_rebalance_weights: '0x10,1,1,1,1,1,1,1,1,1,1,1' },+ models: [],+ supportedModels: [krea2Model],+ vaeModels: [],+ });++ expect(result?.values.krea2RebalanceWeights).toBe(createValues().krea2RebalanceWeights);+ // The enabled flag and gain are still sound on their own.+ expect(result?.values.krea2RebalanceMultiplier).toBe(6.5);+ });++ it('offers recall for an image whose only recallable delta is the rebalance', () => {+ const capabilities = getImageRecallCapabilities({+ currentValues: createValues({ model: krea2Model }),+ image,+ metadata: { krea2_rebalance_enabled: true },+ models: [],+ supportedModels: [],+ vaeModels: [],+ });++ expect(capabilities.all).toBe(true);+ expect(capabilities.remix).toBe(true);+ });+ });});diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.tsindex 9ea789cbc3..c19cdc1a82 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts@@ -14,6 +14,7 @@ import {getSettingsWithModelDefaults,isKnownScheduler,isVaeCompatibleWithGenerateModel,+ isValidKrea2RebalanceWeights,cloneGenerateWidgetValues,getModelDefaultVae,hasModelDefaultVae,@@ -60,7 +61,8 @@ type RecalledField =| 'hiDiffusion'| 'clipSkip'| 'components'- | 'referenceImages';+ | 'referenceImages'+ | 'krea2Rebalance';export interface ImageRecallResult {fields: RecalledField[];@@ -360,6 +362,35 @@ const hasGenerationSettings = (metadata: unknown): boolean =>getBoolean(metadata, 'seamless_x') !== null ||getBoolean(metadata, 'seamless_y') !== null;+/**+ * Krea-2's conditioning rebalance, as written by `buildKrea2Graph`.+ *+ * Gated on the recalled model's base because the settings keys are family-specific, and+ * validated because `krea2RebalanceWeights` is forwarded to the node verbatim — a+ * metadata blob is not a trusted source for a string the backend will parse.+ */+const getMetadataKrea2Rebalance = (+ metadata: unknown,+ model: GenerateModelConfig | undefined+): Partial<GenerateWidgetValues> => {+ if (model?.base !== 'krea-2') {+ return {};+ }++ const enabled = getBoolean(metadata, 'krea2_rebalance_enabled');+ const multiplier = getNumber(metadata, 'krea2_rebalance_multiplier');+ const weights = getString(metadata, 'krea2_rebalance_weights');++ return {+ ...(enabled === null ? {} : { krea2RebalanceEnabled: enabled }),+ ...(multiplier === null ? {} : { krea2RebalanceMultiplier: multiplier }),+ ...(weights !== null && isValidKrea2RebalanceWeights(weights) ? { krea2RebalanceWeights: weights } : {}),+ };+};++const hasKrea2Rebalance = (metadata: unknown, model: GenerateModelConfig | undefined): boolean =>+ Object.keys(getMetadataKrea2Rebalance(metadata, model)).length > 0;+const hasComponentModels = (metadata: unknown, models: readonly ComponentModelConfig[]): boolean =>getMetadataMainModel(metadata, 'qwen3_source', models) !== undefined ||getMetadataMainModel(metadata, 'qwen_image_component_source', models) !== undefined ||@@ -443,6 +474,7 @@ export const getImageRecallCapabilities = ({const hasComponents = hasComponentModels(metadata, models);const hasReferenceImages = getMetadataReferenceImages(metadata).length > 0;const hasModel = supportedMetadataModel !== null;+ const hasRebalance = hasKrea2Rebalance(metadata, clipSkipModel);const hasAnyMetadata =hasModel ||hasVae ||@@ -453,7 +485,8 @@ export const getImageRecallCapabilities = ({hasHiDiffusion ||hasClipSkip ||hasComponents ||- hasReferenceImages;+ hasReferenceImages ||+ hasRebalance;const hasNonSeedMetadata =hasModel ||hasVae ||@@ -463,7 +496,8 @@ export const getImageRecallCapabilities = ({hasHiDiffusion ||hasClipSkip ||hasComponents ||- hasReferenceImages;+ hasReferenceImages ||+ hasRebalance;return {all: hasAnyMetadata,@@ -528,6 +562,13 @@ export const buildImageRecallSettings = ({fields.push('components');}+ const rebalancePatch = getMetadataKrea2Rebalance(metadata, values.model);++ if (Object.keys(rebalancePatch).length > 0) {+ values = { ...values, ...rebalancePatch };+ fields.push('krea2Rebalance');+ }+const vae = getMetadataVae(metadata, values.model, vaeModels);if (vae !== undefined) {