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
Merge branch 'main' into feat/krea2-edit-references-ui
Lincoln Stein5cf250ce46aa
diff --cc docs/src/content/docs/Users Guide/04.Image Generation/generate-panel.mdxindex eda1fb3922,fc6920b06d..6a47817814--- a/docs/src/content/docs/Users Guide/04.Image Generation/generate-panel.mdx+++ b/docs/src/content/docs/Users Guide/04.Image Generation/generate-panel.mdx@@@ -120,14 -119,13 +120,15 @@@ What a reference does, and what option|---|---|---|| **SD 1.5, SDXL** | An IP-Adapter model carries the reference's look into the image. | **Mode**: **Style**, **Composition** or **Both**. **Weight**. Under **Advanced**: the IP-Adapter model, a **Style variant** and the **Active steps** range. || **FLUX.1** | An IP-Adapter, or a **FLUX Redux** model, which transfers the reference's content. | IP-Adapter options as above, or **Image influence** (Lowest to Highest) for Redux. |+ | **Anima** (not Anima-3.8B) | An Anima IP-Adapter carries a character's appearance (hair, outfit, accessories) into the image. Up to four references (experimental); images of one character combine well, different characters blend. | **Strength** (0 to 2; 0 turns it off), per reference. Under **Advanced**: the IP-Adapter model and the **Active steps** range. || **FLUX.1 Kontext** | Kontext edits or recombines the reference images according to your prompt. | None beyond the model. || **FLUX.2, Qwen Image Edit** | The model reads the references directly and uses them as your prompt instructs, for example *put the jacket from the first image on the person in the second*. | None. |-| **Krea-2** | One reference's look — palette, texture, rendering — is transferred into the image while the prompt keeps driving the content; see [Krea-2](/users-guide/models/local-models/krea-2/#style-reference). | **Style strength** (0–2; 0 turns the reference off). |+| **Krea-2** | **Style**: one reference's look — palette, texture, rendering — is transferred into the image while the prompt keeps driving the content. **Edit**: up to three references for an edit LoRA, such as a pose skeleton or a depth map, read in card order. See [Krea-2 style reference](/users-guide/models/local-models/krea-2/#style-reference) and [edit LoRAs](/users-guide/models/local-models/krea-2/#edit-loras-and-reference-images). | **Mode**: **Style** or **Edit**. **Style strength** (0–2; 0 turns the reference off) for Style. |- Reference images require an extra model for SD 1.5, SDXL and FLUX.1 (an IP-Adapter or FLUX Redux model). These are available as starter models in the Model Manager, and an installed IP-Adapter is selected automatically.+ Reference images require an extra model for SD 1.5, SDXL, FLUX.1 and Anima (an IP-Adapter or FLUX Redux model). These are available as starter models in the Model Manager, and an installed IP-Adapter is selected automatically.+A new Krea-2 reference starts as **Style** when it is the only active one; added beside other active references, or several at once, it starts as **Edit**. A Style reference at strength 0 is not active. Adding an image beside a lone Style reference still at its default strength turns that card into **Edit** too; one whose strength was changed keeps its mode. Krea-2 runs either one Style reference or up to three Edit references, never both; Invoke stays disabled and says why until the active references fit. The **Mode** can be changed while a card is switched off. Switching a card back to Style resets its strength to 1.+## Prompt toolsThe toolbar above the prompt box holds tools that help you write prompts. From left to right: **Templates**, **Dynamic**, **Add prompt trigger**, **Expand prompt**, **Image to prompt** and **Prompt history**.diff --cc invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.jsonindex dd26322fec,8e69c765d0..97d8cfdc41--- a/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json+++ b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json@@@ -1306,11 -1377,40 +1386,42 @@@"value"]},+ "ip_adapter": {+ "inputs": [],+ "literalInputs": {+ "begin_step_percent": [+ 0+ ],+ "clip_vision_model": [+ "ViT-H"+ ],+ "end_step_percent": [+ 1+ ],+ "image": [],+ "ip_adapter_model": [],+ "is_intermediate": [+ true+ ],+ "method": [+ "full"+ ],+ "use_cache": [+ true+ ],+ "weight": [+ 1+ ]+ },+ "outputs": [+ "ip_adapter"+ ]+ },"krea2_denoise": {"inputs": [+ "negative_conditioning","positive_conditioning",+ "reference_latents","seed","style_reference","transformer"diff --cc invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.tsindex 4da4b16318,da26b8faf7..ca515517ef--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts@@@ -1458,110 -1458,36 +1487,138 @@@ export const isReferenceImageCompatiblereturn true;};+/** A new or re-targeted reference, typed for the model; existing references keep theirs. */+interface ReferenceImageAddition {+ image: GenerateReferenceImageAsset | null;+ isEnabled: boolean;+}++/**+ * Configs for `additions` joining `referenceImages`. A Krea-2 addition is the style reference only when it would be+ * the sole running Krea-2 reference, counting the other additions and itself as switched on; arriving with or beside+ * others, it is an edit reference.+ */+const getDefaultReferenceImageConfigs = (+ model: GenerateModelConfig | undefined,+ models: readonly ReferenceModelCandidate[],+ additions: readonly ReferenceImageAddition[],+ referenceImages: readonly GenerateReferenceImage[]+): GenerateReferenceImageConfig[] => {+ if (model?.type !== 'main' || model.base !== 'krea-2') {+ return additions.map(({ image }) => getFamilyDefaultReferenceImageConfig(model, models, image));+ }++ const runningElsewhere = referenceImages.filter(isReferenceImageActive).length;+ const enabledAdditions = additions.filter((addition) => addition.isEnabled).length;++ return additions.map(({ image, isEnabled }) =>+ runningElsewhere + enabledAdditions + (isEnabled ? 0 : 1) === 1+ ? { image, styleStrength: DEFAULT_KREA2_STYLE_STRENGTH, type: 'krea2_reference_image' }+ : { image, type: 'krea2_edit_reference_image' }+ );+};++/** Within the model's limit; Krea-2 runs either one style reference or a set of edit references, never both. */+const canRunWithEnabledReferenceImages = (+ model: GenerateModelConfig,+ enabled: readonly GenerateReferenceImage[],+ referenceImage: GenerateReferenceImage+): boolean => {+ if (enabled.length >= getMaxReferenceImages(model)) {+ return false;+ }++ if (model.base !== 'krea-2') {+ return true;+ }++ return referenceImage.config.type === 'krea2_reference_image'+ ? enabled.length === 0+ : enabled.every((kept) => kept.config.type !== 'krea2_reference_image');+};++/**+ * The list's one running reference when it is a Krea-2 style reference still at its default strength, which an+ * addition turns into an edit reference.+ */+const getLoneDefaultStyleReference = (+ referenceImages: readonly GenerateReferenceImage[]+): GenerateReferenceImage | null => {+ const active = referenceImages.filter(isReferenceImageActive);+ const [lone] = active;++ return active.length === 1 &&+ lone?.config.type === 'krea2_reference_image' &&+ lone.config.styleStrength === DEFAULT_KREA2_STYLE_STRENGTH+ ? lone+ : null;+};++/**+ * `referenceImages` with `additions` appended as enabled references typed for the model; every way of adding a+ * reference goes through here. A lone first Krea-2 reference starts as the style reference, so an edit set built one+ * image at a time begins with one: the next addition turns it into an edit reference too, unless its strength was+ * changed, which marks it as meant for style. Validation then reports the mix.+ */+export const withAddedReferenceImages = (+ model: GenerateModelConfig | undefined,+ models: readonly ReferenceModelCandidate[],+ referenceImages: GenerateReferenceImage[],+ additions: readonly { id: string; image: GenerateReferenceImageAsset | null }[]+): GenerateReferenceImage[] => {+ if (additions.length === 0) {+ return referenceImages;+ }++ const lone = model?.type === 'main' && model.base === 'krea-2' ? getLoneDefaultStyleReference(referenceImages) : null;+ const kept = lone+ ? referenceImages.map((referenceImage): GenerateReferenceImage =>+ referenceImage === lone+ ? { ...referenceImage, config: { image: referenceImage.config.image, type: 'krea2_edit_reference_image' } }+ : referenceImage+ )+ : referenceImages;+ const configs = getDefaultReferenceImageConfigs(+ model,+ models,+ additions.map(({ image }) => ({ image, isEnabled: true })),+ kept+ );++ return [...kept, ...additions.map(({ id }, index) => ({ config: configs[index]!, id, isEnabled: true }))];+};+/**- * Drop unsupported references; retarget incompatible ones while preserving image/enabled state. The re-targeted ones- * are typed together, beside the compatible ones. No changes return the same array.+ * An SD reference that never had an adapter (model null) passes the base check, so a switch to a strength-only base+ * would keep its unset adapter and its SD weight, which may be negative. Re-target it when that leaves it unusable and+ * re-targeting can help: a weight the node rejects, or no adapter while one is installed. Without an installed adapter+ * the re-targeted config is stable, so a repeated switch changes nothing.+ */+ const needsStrengthOnlyRetarget = (+ model: GenerateModelConfig,+ referenceImage: GenerateReferenceImage,+ models: readonly ReferenceModelCandidate[]+ ): boolean => {+ const { config } = referenceImage;++ if (config.type !== 'ip_adapter' || !isStrengthOnlyIPAdapterBase(model.base)) {+ return false;+ }++ if (!(config.weight >= 0 && config.weight <= 2)) {+ return true;+ }++ return (+ config.model === null &&+ models.some((candidate) => candidate.type === 'ip_adapter' && candidate.base === model.base)+ );+ };++ /**- * Drop unsupported references; retarget incompatible ones while preserving image/enabled state. No changes return- * the same array.++ * Drop unsupported references; retarget incompatible ones, and strength-only IP-Adapter references left unusable,++ * while preserving image/enabled state. The re-targeted ones are typed together, beside the others; a strength-only++ * base then keeps their step window, same-base adapter and strength. No changes return the same array.*/export const getCompatibleReferenceImages = (referenceImages: GenerateReferenceImage[],@@@ -1576,26 -1502,39 +1633,51 @@@return [];}- const isCompatible = referenceImages.map((referenceImage) =>- isReferenceImageCompatibleWithModel(model, referenceImage)- let didChange = false;- const next = referenceImages.map((referenceImage) => {- if (++ const isKept = referenceImages.map(++ (referenceImage) =>+ isReferenceImageCompatibleWithModel(model, referenceImage) &&+ !needsStrengthOnlyRetarget(model, referenceImage, models)- ) {+ );- const retargeted = referenceImages.filter((_, index) => !isCompatible[index]);++ const retargeted = referenceImages.filter((_, index) => !isKept[index]);++ if (retargeted.length === 0) {+ return referenceImages;+ }++ const configs = getDefaultReferenceImageConfigs(+ model,+ models,+ retargeted.map(({ config, isEnabled }) => ({ image: config.image, isEnabled })),- referenceImages.filter((_, index) => isCompatible[index])++ referenceImages.filter((_, index) => isKept[index])+ );+ let retargetIndex = 0;+- return referenceImages.map((referenceImage, index) =>- isCompatible[index] ? referenceImage : { ...referenceImage, config: configs[retargetIndex++]! }- );++ return referenceImages.map((referenceImage, index) => {++ if (isKept[index]) {+ return referenceImage;+ }+- didChange = true;+ const { config } = referenceImage;- const defaults = getDefaultReferenceImageConfig(model, models, config.image);++ const defaults = configs[retargetIndex++]!;++ // A strength-only base keeps the user's step window and strength; only the adapter and the hidden SD fields reset.+ if (config.type === 'ip_adapter' && defaults.type === 'ip_adapter' && isStrengthOnlyIPAdapterBase(model.base)) {+ // Clamping a negative SD weight to 0 would switch the reference off, so it takes the default strength instead.+ const weight =+ Number.isFinite(config.weight) && config.weight >= 0 ? Math.min(config.weight, 2) : defaults.weight;+ return {+ ...referenceImage,+ config: {+ ...defaults,+ beginEndStepPct: config.beginEndStepPct,+ model: config.model?.base === model.base ? config.model : defaults.model,+ weight,+ },+ };+ }++ return { ...referenceImage, config: defaults };+ });-- return didChange ? next : referenceImages;};const getSettingsWithCompatibleModelSelections = (diff --cc invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.tsindex b55e51f002,273b4f8448..2cc7aeed81--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.ts@@@ -7,11 -8,13 +8,16 @@@ import type { SupportedGenerateBase } fimport type { BackendGraphContract, BackendInvocationContract } from '@features/generation/core/contracts';import type { ComponentModelConfig, GenerateModelConfig, GenerateSettings } from '@features/generation/core/types';-import { getGenerationValidationReasons } from '@features/generation/core/baseGenerationPolicies';+import {+ getGenerationValidationReasons,+ hasEnabledKrea2EditReferences,+} from '@features/generation/core/baseGenerationPolicies';- import { findVaeSource, GRAPH_BUILDERS } from '@features/generation/core/graph';+ import {+ describeExternalCanvasRefusal,+ isExternalGenerationMode,+ isExternalTextOnlyCanvasModel,+ } from '@features/generation/core/externalProvider';+ import { buildExternalGraph, findVaeSource, GRAPH_BUILDERS } from '@features/generation/core/graph';import {addEdge,addNode,diff --cc invokeai/frontend/webv2/src/features/generation/core/graphCoverage.test.tsindex a8b34d7f9b,6ef5ad412e..d368f5fb29--- a/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.test.ts@@@ -10,9 -10,11 +10,11 @@@ import type { MainModelConfig, ModelIdeimport {getComponentSectionPolicy,- getDefaultReferenceImageConfig,getGenerationValidationReasons,isLoraSupported,+ isReferenceImageSupported,SUPPORTED_GENERATE_BASES,++ withAddedReferenceImages,} from './baseGenerationPolicies';import { compileGenerateGraph, GRAPH_BUILDERS } from './graph';import {@@@ -38,6 -45,23 +45,23 @@@ const compileForShape =...satisfiedSettingsFor(base, shape),projectSettings: { useCpuNoise: true, useNsfwChecker: false, useWatermark: false },};+ // One enabled reference image wherever the model takes one, so reference nodes and their fields enter the contract.+ const settings = isReferenceImageSupported(model)+ ? {+ ...satisfied,- referenceImages: [- {- config: getDefaultReferenceImageConfig(- model,- [{ base, key: `${base}-ip-adapter`, name: `${base} IP Adapter`, type: 'ip_adapter' }],- { original: { image: { height: 512, image_name: 'reference.png', width: 512 } } }- ),- id: 'coverage-reference',- isEnabled: true,- },- ],++ referenceImages: withAddedReferenceImages(++ model,++ [{ base, key: `${base}-ip-adapter`, name: `${base} IP Adapter`, type: 'ip_adapter' }],++ [],++ [++ {++ id: 'coverage-reference',++ image: { original: { image: { height: 512, image_name: 'reference.png', width: 512 } } },++ },++ ]++ ),+ }+ : satisfied;// Assert every requirement before compilation for complete diagnostics.expect(getGenerationValidationReasons(model, settings), `${base}/${shape.label} is not satisfiable`).toEqual([]);