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
feat(qwen-image): make VAE tiling usable on both Qwen-Image VAE nodes
Alexander Eichhorn39b237565ddc
diff --git a/invokeai/app/invocations/qwen_image_image_to_latents.py b/invokeai/app/invocations/qwen_image_image_to_latents.pyindex 785fb8e73c..16d6377951 100644--- a/invokeai/app/invocations/qwen_image_image_to_latents.py+++ b/invokeai/app/invocations/qwen_image_image_to_latents.py@@ -113,7 +113,12 @@ class QwenImageImageToLatentsInvocation(BaseInvocation, WithMetadata, WithBoard)# If target dimensions are specified, resize the image BEFORE encoding# (matching the diffusers pipeline which resizes in pixel space, not latent space).- if self.width is not None and self.height is not None:+ #+ # `width`/`height` are `int | None`, but the workflow UI cannot represent None in a number+ # input and sends 0 for "unset" — which `is not None`, so a naive check reached+ # `resize((0, 0))` and raised "height and width must be > 0". Treat any non-positive value+ # as unset, which is also how `tile_size` uses 0.+ if self.width and self.height and self.width > 0 and self.height > 0:image = image.convert("RGB").resize((self.width, self.height), resample=PILImage.LANCZOS)# multiple_of=16 ensures the post-VAE latents (vae_scale_factor=8) have evendiff --git a/invokeai/app/invocations/qwen_image_latents_to_image.py b/invokeai/app/invocations/qwen_image_latents_to_image.pyindex 38ecd1e594..d93ab89f5a 100644--- a/invokeai/app/invocations/qwen_image_latents_to_image.py+++ b/invokeai/app/invocations/qwen_image_latents_to_image.py@@ -27,7 +27,7 @@ from invokeai.backend.util.vae_working_memory import estimate_vae_working_memorytitle="Latents to Image - Qwen Image",tags=["latents", "image", "vae", "l2i", "qwen_image"],category="latents",- version="1.0.0",+ version="1.1.0",classification=Classification.Prototype,)class QwenImageLatentsToImageInvocation(BaseInvocation, WithMetadata, WithBoard):@@ -35,12 +35,26 @@ class QwenImageLatentsToImageInvocation(BaseInvocation, WithMetadata, WithBoard)latents: LatentsField = InputField(description=FieldDescriptions.latents, input=Input.Connection)vae: VAEField = InputField(description=FieldDescriptions.vae, input=Input.Connection)+ tiled: bool = InputField(default=False, description=FieldDescriptions.tiled)+ # NOTE: tile_size = 0 is a special value meaning "use the model's default", matching the+ # SD/SDXL l2i node. `int | None` is avoided because the workflow UI does not handle it well.+ tile_size: int = InputField(default=0, multiple_of=8, description=FieldDescriptions.vae_tile_size)@torch.no_grad()def invoke(self, context: InvocationContext) -> ImageOutput:latents = context.tensors.load(self.latents.latents_name)vae_info = context.models.load(self.vae.vae)+ tiled = self.tiled or context.config.get().force_tiled_decode+ # Resolve tile_size=0 ("model default") before estimating, so the memory the cache reserves+ # matches the tiles the VAE will actually use. Without this the estimate stays at the+ # full-frame figure (~21 GB at 2560x1440 on CUDA) and tiling frees nothing: the VAE is+ # bounded, but the cache still evicts other models to honour the reservation.+ effective_tile_size = None+ if tiled:+ effective_tile_size = (+ self.tile_size if self.tile_size > 0 else getattr(vae_info.model, "tile_sample_min_height", 256)+ )# NOTE: vae_info.model may be an AutoencoderKLWan (a native-layout qwen_image_vae single file is# classified with the Anima base); it is reinterpreted as AutoencoderKLQwenImage inside the# model_on_device context below. The working-memory estimate only reads tensor shape + element@@ -49,6 +63,7 @@ class QwenImageLatentsToImageInvocation(BaseInvocation, WithMetadata, WithBoard)operation="decode",image_tensor=latents,vae=vae_info.model,+ tile_size=effective_tile_size,)with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):context.util.signal_progress("Running VAE")@@ -62,13 +77,15 @@ class QwenImageLatentsToImageInvocation(BaseInvocation, WithMetadata, WithBoard)# which would wrongly place the latents (and thus the whole decode) on the CPU (see #9373).latents = latents.to(device=vae_info.compute_device, dtype=vae.dtype)- # Honor the global force_tiled_decode setting, like the SD/SDXL l2i node. Tiling bounds the- # VAE's per-tile memory, which is the scalable way to decode very large outputs that would- # exceed VRAM even after offloading the transformer/text encoder. For normal sizes, leave- # it off (faster, no tile blending) — the reserved working memory offloads other models so- # the full-frame decode fits.- if context.config.get().force_tiled_decode:- vae.enable_tiling()+ # Tiling bounds the VAE's per-tile memory, which is the scalable way to decode very+ # large outputs that would exceed VRAM even after offloading the transformer/text+ # encoder. For normal sizes, leave it off (faster, no tile blending) — the reserved+ # working memory offloads other models so the full-frame decode fits.+ if tiled:+ if self.tile_size > 0:+ vae.enable_tiling(tile_sample_min_height=self.tile_size, tile_sample_min_width=self.tile_size)+ else:+ vae.enable_tiling()else:vae.disable_tiling()diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.jsonindex 3443471415..157b4be667 100644--- a/invokeai/frontend/web/openapi.json+++ b/invokeai/frontend/web/openapi.json@@ -71875,6 +71875,27 @@"input": "connection","orig_required": true},+ "tiled": {+ "default": false,+ "description": "Processing using overlapping tiles (reduce memory consumption)",+ "field_kind": "input",+ "input": "any",+ "orig_default": false,+ "orig_required": false,+ "title": "Tiled",+ "type": "boolean"+ },+ "tile_size": {+ "default": 0,+ "description": "The tile size for VAE tiling in pixels (image space). If set to 0, the default tile size for the model will be used. Larger tile sizes generally produce better results at the cost of higher memory usage.",+ "field_kind": "input",+ "input": "any",+ "multipleOf": 8,+ "orig_default": 0,+ "orig_required": false,+ "title": "Tile Size",+ "type": "integer"+ },"type": {"const": "qwen_image_l2i","default": "qwen_image_l2i",@@ -71887,7 +71908,7 @@"tags": ["latents", "image", "vae", "l2i", "qwen_image"],"title": "Latents to Image - Qwen Image","type": "object",- "version": "1.0.0",+ "version": "1.1.0","output": {"$ref": "#/components/schemas/ImageOutput"}diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.tsindex a51b010759..c49ebfb8a8 100644--- a/invokeai/frontend/web/src/services/api/schema.ts+++ b/invokeai/frontend/web/src/services/api/schema.ts@@ -30380,6 +30380,18 @@ export type components = {* @default null*/vae?: components["schemas"]["VAEField"] | null;+ /**+ * Tiled+ * @description Processing using overlapping tiles (reduce memory consumption)+ * @default false+ */+ tiled?: boolean;+ /**+ * Tile Size+ * @description The tile size for VAE tiling in pixels (image space). If set to 0, the default tile size for the model will be used. Larger tile sizes generally produce better results at the cost of higher memory usage.+ * @default 0+ */+ tile_size?: number;/*** type* @default qwen_image_l2i