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(generation): take FLUX.2 [dev] components only from Diffusers pipelines (#10121)
Josh Corbett6ec84cb811bb
diff --git a/docs/src/content/docs/Users Guide/03.Models/Local Models/flux-2.mdx b/docs/src/content/docs/Users Guide/03.Models/Local Models/flux-2.mdxindex 33269ce46a..82b4886a85 100644--- a/docs/src/content/docs/Users Guide/03.Models/Local Models/flux-2.mdx+++ b/docs/src/content/docs/Users Guide/03.Models/Local Models/flux-2.mdx@@ -73,9 +73,14 @@ A FLUX.2 model needs three components:| Text encoder | bundled | Klein 4B: Qwen3 4B · Klein 9B: Qwen3 8B · [dev]: Mistral |Starter models that are not Diffusers pipelines install the VAE and the matching encoder as dependencies.-Pick them in the **Components** section next to the model. If you have a FLUX.2 Diffusers model of the-matching variant installed, InvokeAI uses its encoder and VAE automatically, so you don't need standalone-ones.+Pick them in the **Components** section next to the model. InvokeAI also takes them from another installed+FLUX.2 pipeline automatically, so you don't need standalone ones:++- **Klein** uses a Diffusers or self-contained SDNQ pipeline: any one for the VAE, one of the same size (4B or 9B)+ for the encoder.+- **[dev]** uses Diffusers pipelines only: any FLUX.2 one for the VAE, a [dev] one for the Mistral encoder. An+ SDNQ [dev] install is no pipeline of its own: it needs a standalone VAE and Mistral encoder, or a Diffusers+ pipeline as above.### Klein starter modelsdiff --git a/docs/src/content/docs/development/Architecture/model-manager.mdx b/docs/src/content/docs/development/Architecture/model-manager.mdxindex e99e2eadcc..8fb0e77b17 100644--- a/docs/src/content/docs/development/Architecture/model-manager.mdx+++ b/docs/src/content/docs/development/Architecture/model-manager.mdx@@ -1199,7 +1199,7 @@ The reset, export and summary routes act on the current device class unless `dev- The provider answers from memory. `refresh_user_fits()` rebuilds that memory per GPU generation device. `DefaultSessionRunner.run()` calls it once when it starts any queue item, calibration items included; `get_plan` calls it first, so the case sizes price with the store as it is, and every reset calls it after its write, so a reset applies at once. It stats each device class's file and re-reads it only when the mtime, size or inode or the environment changed. Each refresh of a file with runs, and each model summary, reads the queue to judge the attempts. To tell which runs are running it reads the origins of the queue's unfinished calibration items (`get_unfinished_origins`): the queue finds those items by their status and tests the origin on their rows, so the read costs what the queue has pending or running, not its history; on SQLite about 0.05 ms beside a handful of unfinished items, whatever the history, and 3 ms beside 100 (34 ms beside 1000) pending items of 64 KB sessions, whose overflow pages the origin sits behind. Grouping the runs into attempts costs about 0.5 ms at 180 runs and 11 ms at 3600. To tell whether a settled attempt was stopped it reads by id (`get_queue_item_summaries_by_ids`, the primary key) the items the store records whose end the runner did not see. A finished item never changes, so its outcome is kept, per run and item id (a recreated or restored database can give two runs' items one id), until its run is removed, by a reset or by a creation that queued nothing, and each item is read once it finished; a run with an item the queue shows pending or in progress, a retry queued since the read for running items, holds its attempt back as running for that refresh. Every judgement of these outcomes (a refresh, the model summary, a new attempt's check, a reset), with its read of the store file, and every removal holds one lock of the service, taken before the file's lock, so a removal's runs leave no outcome behind. A row counts only while it carries the run's origin: a recreated or restored database gives the id to an unrelated item, and the run's own item is gone, so it reads as canceled. An unchanged file with an unchanged set of runs held back is not fitted again. A calibration item, a retry included, is in progress when the runner refreshes before it, so it is priced without its own attempt's windows. Nothing on the estimate path reads a file. Several generation devices each use their own class's fit; calibrating them is not supported.- Shared lines: on cuDNN the SD, SD3, FLUX.1 and FLUX.2 estimators borrow one entry, so an SDXL fp16 decode calibrates every estimator's fp16 decode there. The plan lists the installed models this affects.-The plan (`working_memory_calibration_plan.py`) covers the decode of SD1, SD2, SDXL, SD3, FLUX.1, FLUX.2, Z-Image and CogView4 main models, and standalone VAEs of those bases through an installed main model that accepts them (`VaeFacet`): through Generate's `vae` slot where the base has one (FLUX.1, FLUX.2, SD3, Z-Image), otherwise with the VAE the main model decodes with, its own or the default VAE its settings name, which prices on the same lines. Each case is a two-step `txt2img` graph-export case per size and decode dtype; the SD bases set `vaePrecision` to fp16 and to fp32, the others run the dtype their loader picks: SD3 the `precision` setting; a standalone FLUX.1 or FLUX.2 VAE, and the one Z-Image decodes with, the configured dtype except fp16, which becomes bf16 where the device has it and fp32 otherwise (`TorchDevice.dtype_avoiding_float16`, which the loaders use too), so `precision: float32` plans the fp32 line at the smaller sizes an fp32 decode fits untiled; a pipeline's own VAE what its loader yields: bf16 for a FLUX.2 Diffusers pipeline, the device's bf16-safe dtype for a Z-Image one, and fp32 for a self-contained SDNQ pipeline, whose loaders call `from_pretrained` without a dtype (bf16 for a FLUX.1 SDNQ pipeline's SDNQ-quantized VAE); `test_working_memory_calibration_plan.py` holds these to the loaders. A pipeline decodes with its own VAE while the `vae` slot is empty: a FLUX.2 or Z-Image Diffusers pipeline, and a self-contained SDNQ pipeline (`is_self_contained_sdnq_pipeline`, for FLUX.1 `is_self_contained_sdnq_flux1_pipeline`). The slot is not empty when the main model's default settings name an installed VAE it accepts (`default_vae`): selecting the model applies it (`getModelDefaultVae`), the SD, SD3, FLUX.1, FLUX.2 and Z-Image graphs decode with it, and the FLUX.2 and Z-Image model loader nodes take it over a pipeline's own VAE, so the plan sizes for that standalone VAE; the graph of a self-contained FLUX.1 SDNQ pipeline, and the CogView4 graph, send no VAE. Another FLUX.2 model decodes with the VAE of the component source Generate picks on its own, the first installed FLUX.2 pipeline whose text encoder fits it ([dev] for [dev], else the Klein variant's Qwen3 size), else the first one; that graph keeps a pipeline that does not fit only beside a standalone encoder of the model's (a Mistral encoder for [dev], else a Qwen3 encoder of the Klein variant's size), which then encodes while the pipeline gives its VAE. Without a pipeline, and for every other FLUX.1 model, a standalone VAE decodes. The sizes are about 0.25, 0.5 and 1.0 of the largest square, in steps of 64 and at most 4096 px, whose calibration reservation (the estimate plus `max(1 GiB, 0.5 × estimate)`, and never below `device_working_mem_gb`, as the lock applies it) leaves the VAE fully resident (`decode_budget`): it must fit both 90% of the card (`VAE_PRETILE_VRAM_FRACTION`) and what the model cache can give on the device, each less 1 GiB for the VAE's weights. Nothing else stays beside it: inside a calibration scope, `model_on_device` first moves every other unlocked model on the device to RAM whole (`ModelCache.offload_unlocked_models_from_vram`, under the global load lock, inside the probe's lock interval; locked models, a window's co-locks among them, stay), and only then locks. The reason: a lock offloads only the shortfall it predicts and splits the last model it reaches, and a split can free a little less than predicted. On an RX 9060 XT, 9 of the 12 calibration decodes that had to split the SDXL UNet came up 35 to 55 MB short and ran the VAE partly resident, so their windows fit no line. Outside a calibration scope, locks are unchanged. That capacity is read when the plan is built, from the device's model cache: `ModelCache.calibration_capacity`, what the calibration's lock then gets from the same cache. It counts as `ModelCache._get_vram_available` counts a lock, through the same `TorchDevice.memory_available_to_process`, within `max_cache_vram_gb`, less `reserve_vram_gb`. On a dedicated card that is the driver's free memory plus what torch has allocated, so the models the pre-lock offload moves out count as available. On a device whose memory is system RAM (MPS, an integrated Intel GPU) it is the RAM the host has available plus what the backend holds for this process, less what the cache's models hold there now (`_get_vram_in_use`): the offload frees nothing on such a device, and the lock subtracts them too. The 90% share of its total would overstate what a decode finds there whenever the host is short of free memory. Memory other processes hold is thereby left out. What this process holds outside torch's allocator counts at the larger of what it holds now and the most a valid stored window of the current environment recorded at its baseline (the driver's figure for the process less torch's reserve, `recorded_outside_torch_bytes`), over the windows of the estimators a user calibration moves only, because it grows with the first generations: on a 16 GB RX 9060 XT under ROCm, HIP's retained pool and MIOpen's workspaces took about 0.3 GB in a fresh server and 2.6 GiB once it had decoded, and sized for the fresh reading its largest cases ran partly resident. A first calibration has no stored window and sizes for the reading alone, so on such a card its largest cases may run partly resident; those windows do not count, and the next plan sizes for what the first one recorded. The recorded figure comes from the store `refresh_user_fits` just read; `estimate_untiled_vae_decode` prices them with the decode nodes' own features. `DECODE_LINES` restates which estimator each base's decode node prices with; `test_working_memory_calibration_plan.py` holds it to the nodes in `invocations/vae/`. Each case runs once to warm up and twice more; `estimated_seconds` is a rough order of magnitude, not a measurement. Encodes are not planned: text-to-image runs none. Two settings of the machine leave nothing to measure, and the plan is then `supported: false` with the way out: under `force_tiled_decode` the SD, FLUX.1, Z-Image and FLUX.2 decode nodes tile every decode, so a case measures no untiled line and no estimate would read one (`FORCE_TILED_BASES`; the plan does not override the setting for calibration items); and a FLUX.1, FLUX.2 or Z-Image model that decodes with a standalone VAE needs a compatible one that runs on the GPU, since a decode on the CPU opens no window. A main model whose default VAE runs on the CPU gets a `vae` pick of the first accepted VAE on the GPU where its base has the slot, and is otherwise `supported: false` (the SD bases have no slot a case could pick through); a standalone SD VAE goes through a compatible main model whose default VAE does not run on the CPU. A FLUX.2 model that is no pipeline needs a text encoder Generate can use, a fitting pipeline's or a standalone one as above: without one no case compiles, and the plan is `supported: false` saying which encoder to install. A standalone FLUX.2 VAE goes through the first compatible main model that has one.+The plan (`working_memory_calibration_plan.py`) covers the decode of SD1, SD2, SDXL, SD3, FLUX.1, FLUX.2, Z-Image and CogView4 main models, and standalone VAEs of those bases through an installed main model that accepts them (`VaeFacet`): through Generate's `vae` slot where the base has one (FLUX.1, FLUX.2, SD3, Z-Image), otherwise with the VAE the main model decodes with, its own or the default VAE its settings name, which prices on the same lines. Each case is a two-step `txt2img` graph-export case per size and decode dtype; the SD bases set `vaePrecision` to fp16 and to fp32, the others run the dtype their loader picks: SD3 the `precision` setting; a standalone FLUX.1 or FLUX.2 VAE, and the one Z-Image decodes with, the configured dtype except fp16, which becomes bf16 where the device has it and fp32 otherwise (`TorchDevice.dtype_avoiding_float16`, which the loaders use too), so `precision: float32` plans the fp32 line at the smaller sizes an fp32 decode fits untiled; a pipeline's own VAE what its loader yields: bf16 for a FLUX.2 Diffusers pipeline, the device's bf16-safe dtype for a Z-Image one, and fp32 for a self-contained SDNQ pipeline, whose loaders call `from_pretrained` without a dtype (bf16 for a FLUX.1 SDNQ pipeline's SDNQ-quantized VAE); `test_working_memory_calibration_plan.py` holds these to the loaders. A pipeline decodes with its own VAE while the `vae` slot is empty: a FLUX.2 or Z-Image Diffusers pipeline, and a self-contained SDNQ pipeline (`is_self_contained_sdnq_pipeline`, for FLUX.1 `is_self_contained_sdnq_flux1_pipeline`), except that the FLUX.2 [dev] model loader node takes components only from a Diffusers pipeline, so an SDNQ [dev] model is no pipeline of its own. The slot is not empty when the main model's default settings name an installed VAE it accepts (`default_vae`): selecting the model applies it (`getModelDefaultVae`), the SD, SD3, FLUX.1, FLUX.2 and Z-Image graphs decode with it, and the FLUX.2 and Z-Image model loader nodes take it over a pipeline's own VAE, so the plan sizes for that standalone VAE; the graph of a self-contained FLUX.1 SDNQ pipeline, and the CogView4 graph, send no VAE. Another FLUX.2 model decodes with the VAE of the component source Generate picks on its own among the installed FLUX.2 pipelines its model loader node takes components from (Diffusers ones only for [dev]): the first whose text encoder fits it ([dev] for [dev], else the Klein variant's Qwen3 size), else the first one; that graph keeps a pipeline that does not fit only beside a standalone encoder of the model's (a Mistral encoder for [dev], else a Qwen3 encoder of the Klein variant's size), which then encodes while the pipeline gives its VAE. Without a pipeline, and for every other FLUX.1 model, a standalone VAE decodes. The sizes are about 0.25, 0.5 and 1.0 of the largest square, in steps of 64 and at most 4096 px, whose calibration reservation (the estimate plus `max(1 GiB, 0.5 × estimate)`, and never below `device_working_mem_gb`, as the lock applies it) leaves the VAE fully resident (`decode_budget`): it must fit both 90% of the card (`VAE_PRETILE_VRAM_FRACTION`) and what the model cache can give on the device, each less 1 GiB for the VAE's weights. Nothing else stays beside it: inside a calibration scope, `model_on_device` first moves every other unlocked model on the device to RAM whole (`ModelCache.offload_unlocked_models_from_vram`, under the global load lock, inside the probe's lock interval; locked models, a window's co-locks among them, stay), and only then locks. The reason: a lock offloads only the shortfall it predicts and splits the last model it reaches, and a split can free a little less than predicted. On an RX 9060 XT, 9 of the 12 calibration decodes that had to split the SDXL UNet came up 35 to 55 MB short and ran the VAE partly resident, so their windows fit no line. Outside a calibration scope, locks are unchanged. That capacity is read when the plan is built, from the device's model cache: `ModelCache.calibration_capacity`, what the calibration's lock then gets from the same cache. It counts as `ModelCache._get_vram_available` counts a lock, through the same `TorchDevice.memory_available_to_process`, within `max_cache_vram_gb`, less `reserve_vram_gb`. On a dedicated card that is the driver's free memory plus what torch has allocated, so the models the pre-lock offload moves out count as available. On a device whose memory is system RAM (MPS, an integrated Intel GPU) it is the RAM the host has available plus what the backend holds for this process, less what the cache's models hold there now (`_get_vram_in_use`): the offload frees nothing on such a device, and the lock subtracts them too. The 90% share of its total would overstate what a decode finds there whenever the host is short of free memory. Memory other processes hold is thereby left out. What this process holds outside torch's allocator counts at the larger of what it holds now and the most a valid stored window of the current environment recorded at its baseline (the driver's figure for the process less torch's reserve, `recorded_outside_torch_bytes`), over the windows of the estimators a user calibration moves only, because it grows with the first generations: on a 16 GB RX 9060 XT under ROCm, HIP's retained pool and MIOpen's workspaces took about 0.3 GB in a fresh server and 2.6 GiB once it had decoded, and sized for the fresh reading its largest cases ran partly resident. A first calibration has no stored window and sizes for the reading alone, so on such a card its largest cases may run partly resident; those windows do not count, and the next plan sizes for what the first one recorded. The recorded figure comes from the store `refresh_user_fits` just read; `estimate_untiled_vae_decode` prices them with the decode nodes' own features. `DECODE_LINES` restates which estimator each base's decode node prices with; `test_working_memory_calibration_plan.py` holds it to the nodes in `invocations/vae/`. Each case runs once to warm up and twice more; `estimated_seconds` is a rough order of magnitude, not a measurement. Encodes are not planned: text-to-image runs none. Two settings of the machine leave nothing to measure, and the plan is then `supported: false` with the way out: under `force_tiled_decode` the SD, FLUX.1, Z-Image and FLUX.2 decode nodes tile every decode, so a case measures no untiled line and no estimate would read one (`FORCE_TILED_BASES`; the plan does not override the setting for calibration items); and a FLUX.1, FLUX.2 or Z-Image model that decodes with a standalone VAE needs a compatible one that runs on the GPU, since a decode on the CPU opens no window. A main model whose default VAE runs on the CPU gets a `vae` pick of the first accepted VAE on the GPU where its base has the slot, and is otherwise `supported: false` (the SD bases have no slot a case could pick through); a standalone SD VAE goes through a compatible main model whose default VAE does not run on the CPU. A FLUX.2 model that is no pipeline needs a text encoder Generate can use, a fitting pipeline's or a standalone one as above: without one no case compiles, and the plan is `supported: false` saying which encoder to install. A standalone FLUX.2 VAE goes through the first compatible main model that has one.### Emitting model loading eventsdiff --git a/invokeai/app/invocations/flux2/flux2_dev_model_loader.py b/invokeai/app/invocations/flux2/flux2_dev_model_loader.pyindex 1cb7db7b18..c5d5e18adf 100644--- a/invokeai/app/invocations/flux2/flux2_dev_model_loader.py+++ b/invokeai/app/invocations/flux2/flux2_dev_model_loader.py@@ -182,10 +182,9 @@ class Flux2DevModelLoaderInvocation(BaseInvocation):variant-filtered in the workflow editor, so the *encoder* path is where variant gatingbelongs — see ``_validate_encoder_source``.- Note the [dev] linear UI is stricter than this: ``buildFLUXGraph`` sources from dev-only- pipelines and readiness gates on one, so the Klein-pipeline-as-VAE-source case is reachable- through the workflow editor only. (The Klein loader's linear UI *does* fall back to any- FLUX.2 diffusers pipeline for the VAE.)+ Generate follows the same rule: with a standalone Mistral encoder it takes the VAE from any+ FLUX.2 Diffusers pipeline, Klein ones included, and it never offers an SDNQ pipeline, which+ this check rejects."""config = context.models.get_config(model)if config.format != ModelFormat.Diffusers:diff --git a/invokeai/app/services/working_memory_calibration/working_memory_calibration_plan.py b/invokeai/app/services/working_memory_calibration/working_memory_calibration_plan.pyindex 38b5e4b6f5..09d40a5f61 100644--- a/invokeai/app/services/working_memory_calibration/working_memory_calibration_plan.py+++ b/invokeai/app/services/working_memory_calibration/working_memory_calibration_plan.py@@ -118,10 +118,6 @@ FORCE_TILED_BASES: Final = frozenset("""Bases whose decode node tiles every decode under `force_tiled_decode` (`latents_to_image`, `flux_vae_decode`,`z_image_latents_to_image`, `flux2_vae_decode`). The SD3, CogView4 and Ideogram 4 nodes ignore the setting."""-_OWN_VAE_BASES: Final = frozenset({BaseModelType.Flux2, BaseModelType.ZImage})-"""Bases whose Diffusers and self-contained SDNQ pipelines decode with their own VAE when Generate's `vae` slot is-empty. A FLUX.1 Diffusers pipeline does not: Generate requires a standalone VAE for it."""-PLANNABLE_BASES: Final = frozenset({BaseModelType.StableDiffusion1,@@ -182,22 +178,26 @@ def _value(field: object) -> str:def ships_its_vae(model: ModelConfig) -> bool:- """Whether a main model decodes with its own VAE while Generate's `vae` slot is empty, as Generate- (`isBundledMainForBase`) and the model loader nodes treat it: a FLUX.2 or Z-Image Diffusers pipeline, or a- self-contained SDNQ pipeline (`is_self_contained_sdnq_pipeline`; for FLUX.1 `is_self_contained_sdnq_flux1_pipeline`,- which also needs the T5 pair)."""+ """Whether a main model decodes with its own VAE while Generate's `vae` slot is empty, as its model loader node+ takes it: a Z-Image Diffusers or self-contained SDNQ pipeline (`is_self_contained_sdnq_pipeline`), a FLUX.2 one its+ own loader takes components from (`_is_flux2_source`), or a self-contained FLUX.1 SDNQ pipeline+ (`is_self_contained_sdnq_flux1_pipeline`, which also needs the T5 pair). A FLUX.1 Diffusers pipeline does not:+ Generate requires a standalone VAE for it."""if not _is_main(model):return Falseif model.base == BaseModelType.Flux:return is_self_contained_sdnq_flux1_pipeline(model)- if model.base not in _OWN_VAE_BASES:- return False- return _value(getattr(model, "format", None)) == "diffusers" or is_self_contained_sdnq_pipeline(model)+ if model.base == BaseModelType.Flux2:+ return _is_flux2_source(model, model)+ if model.base == BaseModelType.ZImage:+ return _is_diffusers(model) or is_self_contained_sdnq_pipeline(model)+ return Falsedef _ignores_vae_pick(model: ModelConfig) -> bool:"""Whether Generate drops a `vae` pick for the main model: a self-contained FLUX.1 SDNQ pipeline always decodes- with its own VAE (`buildFLUXGraph` sends none). The FLUX.2 and Z-Image model loader nodes take a picked VAE first."""+ with its own VAE (`buildFluxGraph` sends none). The FLUX.2 and Z-Image model loader nodes take a picked VAE+ first."""return model.base == BaseModelType.Flux and ships_its_vae(model)@@ -236,25 +236,42 @@ _QWEN3_NAMES: Final = {Qwen3VariantType.Qwen3_4B.value: "Qwen3 4B", Qwen3Variant"""How a reason names the Qwen3 encoder a Klein variant takes."""+def _is_dev(model: ModelConfig) -> bool:+ return _variant(model) == Flux2VariantType.Dev.value+++def _is_flux2_source(main: ModelConfig, source: ModelConfig) -> bool:+ """Whether the model loader node of the FLUX.2 model `main` takes a VAE, and where it fits (`_fits_as_source`) a+ text encoder, from the FLUX.2 pipeline `source`, `main` itself included. The Klein loader+ (`flux2_klein_model_loader`) takes them from a Diffusers or a self-contained SDNQ pipeline; the [dev] loader+ (`flux2_dev_model_loader`) only from a Diffusers one, since the SDNQ FLUX.2 model loader loads a Qwen3 encoder only:+ no SDNQ pipeline serves a [dev] model, not even an SDNQ [dev] model itself."""+ if not _is_main(source) or source.base != BaseModelType.Flux2:+ return False+ return _is_diffusers(source) or (not _is_dev(main) and is_self_contained_sdnq_pipeline(source))++def _fits_as_source(main: ModelConfig, source: ModelConfig) -> bool:- """Whether a FLUX.2 pipeline is a component source Generate prefers for `main` (`isFlux2DiffusersSourceForModel`):- [dev] for [dev], else one whose Qwen3 encoder matches the Klein variant's (`KLEIN_TO_QWEN3_VARIANT`)."""- if _variant(main) == Flux2VariantType.Dev.value:- return _variant(source) == Flux2VariantType.Dev.value+ """Whether a component source of a FLUX.2 model (`_is_flux2_source`) gives it its text encoder as well as its VAE,+ the source Generate prefers: [dev] for [dev], else one whose Qwen3 encoder matches the Klein variant's+ (`KLEIN_TO_QWEN3_VARIANT`)."""+ if _is_dev(main):+ return _is_dev(source)required = _KLEIN_QWEN3.get(_variant(main) or "")return required is None or _KLEIN_QWEN3.get(_variant(source) or "") == required-def _flux2_pipelines(models: Sequence[ModelConfig]) -> list[ModelConfig]:- """The installed FLUX.2 pipelines Generate offers as component sources, in `models`' order."""- return [model for model in models if model.base == BaseModelType.Flux2 and ships_its_vae(model)]+def _flux2_sources(main: ModelConfig, models: Sequence[ModelConfig]) -> list[ModelConfig]:+ """The installed FLUX.2 pipelines Generate offers the FLUX.2 model `main` as component sources, those its model+ loader node takes components from (`_is_flux2_source`), in `models`' order."""+ return [model for model in models if _is_flux2_source(main, model)]def _has_standalone_encoder(main: ModelConfig, models: Sequence[ModelConfig]) -> bool:"""Whether a standalone text encoder Generate can fill in for a FLUX.2 main model is installed: a Mistral encoderother than the Ministral 3B for [dev] (`isFlux2MistralEncoder`), else a Qwen3 encoder other than the 0.6B, of thesize the Klein variant takes where it names one (`isFlux2Qwen3EncoderForModel`)."""- if _variant(main) == Flux2VariantType.Dev.value:+ if _is_dev(main):return any(model.type == ModelType.MistralEncoder and _variant(model) != MistralVariantType.Ministral3B.valuefor model in models@@ -270,19 +287,19 @@ def _has_standalone_encoder(main: ModelConfig, models: Sequence[ModelConfig]) ->def _standalone_encoder_name(main: ModelConfig) -> str:"""The standalone encoder `_has_standalone_encoder` looks for, as a reason names it."""- if _variant(main) == Flux2VariantType.Dev.value:+ if _is_dev(main):return "Mistral"return _QWEN3_NAMES.get(_KLEIN_QWEN3.get(_variant(main) or "", ""), "Qwen3")def _lacks_text_encoder(main: ModelConfig, models: Sequence[ModelConfig]) -> bool:- """Whether Generate cannot compile a FLUX.2 main model's graph for want of a text encoder: the model is no pipeline- of its own, no installed pipeline fits it as a component source, and no standalone encoder for it is installed.- A pipeline that does not fit gives only its VAE (`getFlux2DiffusersComponentSource`; the model loader node takes- a source's encoder only from a fitting one)."""+ """Whether Generate cannot compile a FLUX.2 main model's graph for want of a text encoder: its loader takes none+ from the model itself, no installed component source fits it, and no standalone encoder for it is installed. A+ source that does not fit gives only its VAE: Generate keeps it only beside a standalone encoder, and the model+ loader node takes a source's encoder only from a fitting one."""if main.base != BaseModelType.Flux2 or not _is_main(main) or ships_its_vae(main):return False- if any(_fits_as_source(main, source) for source in _flux2_pipelines(models)):+ if any(_fits_as_source(main, source) for source in _flux2_sources(main, models)):return Falsereturn not _has_standalone_encoder(main, models)@@ -290,18 +307,19 @@ def _lacks_text_encoder(main: ModelConfig, models: Sequence[ModelConfig]) -> boodef vae_source(model: ModelConfig, models: Sequence[ModelConfig]) -> Optional[ModelConfig]:"""The pipeline whose own VAE decodes a main model's generations while its `vae` slot is empty: the model itself(`ships_its_vae`), or for another FLUX.2 model the component source Generate then picks on its own and its graph- keeps, whose VAE the FLUX.2 model loader node takes: the first fitting installed FLUX.2 pipeline, else the first- one (`getAutoFlux2ComponentSourceModel`), which the graph keeps only beside a standalone text encoder- (`getFlux2DiffusersComponentSource`). Generate lists the models in the order the server does, which is `models`'- order. None: a standalone VAE decodes, the model's default one included (`default_vae`), or, for a FLUX.2 model- without an encoder, no graph compiles (`_lacks_text_encoder`)."""+ keeps, whose VAE the FLUX.2 model loader node takes: among the installed pipelines that loader takes components+ from (`_flux2_sources`), the first fitting one, else the first one (`getAutoFlux2ComponentSourceModel`), which the+ graph keeps only beside a standalone text encoder. Generate lists the models in the order the server does, which is+ `models`' order. None: a standalone VAE decodes, the model's default one included (`default_vae`), or, for a FLUX.2+ model without an encoder, no graph compiles (`_lacks_text_encoder`); without a VAE either, none compiles+ (`_needs_gpu_vae`)."""if default_vae(model, models) is not None:return Noneif ships_its_vae(model):return modelif not _is_main(model) or model.base != BaseModelType.Flux2:return None- sources = _flux2_pipelines(models)+ sources = _flux2_sources(model, models)fitting = next((source for source in sources if _fits_as_source(model, source)), None)if fitting is not None:return fitting@@ -309,8 +327,8 @@ def vae_source(model: ModelConfig, models: Sequence[ModelConfig]) -> Optional[Modef own_vae_dtype(pipeline: ModelConfig, vae: VaeDtypes) -> str:- """The dtype a pipeline's own VAE loads in (`ships_its_vae`), as its loader yields it."""- if _value(getattr(pipeline, "format", None)) == "diffusers":+ """The dtype a pipeline's own VAE loads in (`vae_source`), as its loader yields it."""+ if _is_diffusers(pipeline):return vae.z_image_pipeline if pipeline.base == BaseModelType.ZImage else FLUX2_PIPELINE_VAE_DTYPEif pipeline.base == BaseModelType.Flux and vae.sdnq_quantized_vae(pipeline):return SDNQ_QUANTIZED_VAE_DTYPE@@ -345,6 +363,10 @@ def _accepts(main: ModelConfig, vae: ModelConfig) -> bool:return accepts_vae(main.base, vae.base, getattr(vae, "latent_channels", None), getattr(main, "variant", None))+def _is_diffusers(config: ModelConfig) -> bool:+ return _value(getattr(config, "format", None)) == "diffusers"++def _is_main(config: ModelConfig) -> bool:return bool(config.type == ModelType.Main)@@ -644,11 +666,12 @@ def build_plan()if _lacks_text_encoder(main, models):encoder = _standalone_encoder_name(main)+ pipeline = "a Diffusers FLUX.2 [dev] pipeline" if _is_dev(main) else "a fitting FLUX.2 pipeline"return _unsupported(target,f"{main.name} has no text encoder Generate can use, so no case compiles: Generate takes it from a FLUX.2 "f"pipeline whose encoder fits the model or from a standalone {encoder} encoder, and a pipeline that does "- f"not fit gives only its VAE. Install a {encoder} encoder or a fitting FLUX.2 pipeline.",+ f"not fit gives only its VAE. Install a {encoder} encoder or {pipeline}.",device_class,estimators,)diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.tsindex b4ed2be1e8..cfcb6e197f 100644--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts@@ -39,6 +39,7 @@ import {getSchedulerOptions,getSettingsWithModelDefaults,isReferenceImageSupported,+ isComponentCompatibleWithModel,isGenerateModelSelectable,isLossyModelSwitch,isModelFromRepo,@@ -429,18 +430,40 @@ describe('component policies', () => {});expect(getGenerationValidationReasons(model, createSettings(model))).toEqual([- 'Generate needs a Qwen3 Encoder for non-Diffusers FLUX.2 models.',- 'Generate needs a VAE for non-Diffusers FLUX.2 models.',+ 'Generate needs a Qwen3 8B Encoder or a same-size FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.',+ 'Generate needs a FLUX.2 VAE or a FLUX.2 Diffusers or SDNQ pipeline for this FLUX.2 Klein model.',]);expect(getGenerationValidationReasons(model, createSettings(model, { componentSourceModel: source }))).toEqual([]);expect(getGenerationValidationReasons(model, createSettings(model, { componentSourceModel: incompatibleSource }))- ).toEqual(['Generate needs a Qwen3 Encoder for non-Diffusers FLUX.2 models.']);+ ).toEqual([+ 'Generate needs a Qwen3 8B Encoder or a same-size FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.',+ ]);expect(getGenerationValidationReasons(model, createSettings(model, { qwen3EncoderModel: qwen3Encoder, vae: flux2Vae }))).toEqual([]);});+ it('names the Qwen3 size a FLUX.2 Klein model needs, and none when its size is unknown', () => {+ const missingEncoder = (variant: string | undefined, overrides: Partial<GenerateSettings> = {}) => {+ const model = createModel('flux2', { format: 'gguf_quantized', variant });++ return getGenerationValidationReasons(model, createSettings(model, { vae: flux2Vae, ...overrides }));+ };+ const qwen3_4b: ComponentModelConfig = { ...qwen3Encoder, key: 'qwen3-4b', variant: 'qwen3_4b' };++ // A Klein 9B with only the 4B encoder installed learns which one to get.+ expect(missingEncoder('klein_9b', { qwen3EncoderModel: qwen3_4b })).toEqual([+ 'Generate needs a Qwen3 8B Encoder or a same-size FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.',+ ]);+ expect(missingEncoder('klein_4b_base')).toEqual([+ 'Generate needs a Qwen3 4B Encoder or a same-size FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.',+ ]);+ expect(missingEncoder(undefined)).toEqual([+ 'Generate needs a Qwen3 Encoder or a FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.',+ ]);+ });+it('validates FLUX.2 [dev] Mistral and VAE requirements and allows bundled alternatives', () => {const model = createModel('flux2', { format: 'gguf_quantized', variant: 'dev' });const source = createModel('flux2', { format: 'diffusers', key: 'flux2-dev-source', variant: 'dev' });@@ -451,12 +474,12 @@ describe('component policies', () => {});expect(getGenerationValidationReasons(model, createSettings(model))).toEqual([- 'Generate needs a Mistral Encoder for non-Diffusers FLUX.2 [dev] models.',- 'Generate needs a VAE for non-Diffusers FLUX.2 models.',+ 'Generate needs a Mistral Encoder or a FLUX.2 [dev] Diffusers pipeline for this FLUX.2 [dev] model.',+ 'Generate needs a FLUX.2 VAE or a FLUX.2 Diffusers pipeline for this FLUX.2 [dev] model.',]);expect(getGenerationValidationReasons(model, createSettings(model, { componentSourceModel: source }))).toEqual([]);expect(getGenerationValidationReasons(model, createSettings(model, { componentSourceModel: kleinSource }))).toEqual(- ['Generate needs a Mistral Encoder for non-Diffusers FLUX.2 [dev] models.']+ ['Generate needs a Mistral Encoder or a FLUX.2 [dev] Diffusers pipeline for this FLUX.2 [dev] model.']);expect(getGenerationValidationReasons(@@ -472,6 +495,67 @@ describe('component policies', () => {]);});+ describe('FLUX.2 [dev] component sources', () => {+ // `flux2_dev_model_loader` reads components only from Diffusers installs, unlike the Klein loader.+ const model = createModel('flux2', { format: 'gguf_quantized', variant: 'dev' });+ const completePipeline = { text_encoder: {}, tokenizer: {}, transformer: {}, vae: {} };+ const sdnqKlein = createModel('flux2', {+ format: 'sdnq_quantized',+ key: 'flux2-klein-sdnq',+ submodels: completePipeline,+ variant: 'klein_9b',+ });+ const diffusersKlein = createModel('flux2', {+ format: 'diffusers',+ key: 'flux2-klein-diffusers',+ variant: 'klein_9b',+ });+ const mistralMissing =+ 'Generate needs a Mistral Encoder or a FLUX.2 [dev] Diffusers pipeline for this FLUX.2 [dev] model.';+ const vaeMissing = 'Generate needs a FLUX.2 VAE or a FLUX.2 Diffusers pipeline for this FLUX.2 [dev] model.';+ const selectDev = (currentValues: GenerateSettings, models: MainModelConfig[]) =>+ getGenerateModelSelectionResult({ currentValues, model, models }).settings;++ it('picks no SDNQ pipeline and names the VAE to install instead', () => {+ const settings = selectDev(createSettings(model, { mistralEncoderModel: mistralEncoder }), [sdnqKlein]);++ expect(settings.componentSourceModel).toBeNull();+ expect(getGenerationValidationReasons(model, settings)).toEqual([vaeMissing]);+ });++ it('takes the VAE from a Diffusers Klein pipeline next to a standalone Mistral encoder', () => {+ const settings = selectDev(createSettings(model, { mistralEncoderModel: mistralEncoder }), [+ sdnqKlein,+ diffusersKlein,+ ]);++ expect(settings.componentSourceModel).toBe(diffusersKlein);+ expect(getGenerationValidationReasons(model, settings)).toEqual([]);+ });++ it('drops a saved or recalled SDNQ pipeline source', () => {+ const settings = createSettings(model, { componentSourceModel: sdnqKlein, mistralEncoderModel: mistralEncoder });++ expect(isComponentCompatibleWithModel(model, settings, 'componentSourceModel', sdnqKlein)).toBe(false);+ expect(getGenerationValidationReasons(model, settings)).toEqual([vaeMissing]);+ expect(selectDev(settings, [sdnqKlein]).componentSourceModel).toBeNull();+ });++ it('does not count a self-contained SDNQ [dev] main as bundled', () => {+ const sdnqDev = createModel('flux2', { format: 'sdnq_quantized', submodels: completePipeline, variant: 'dev' });+ const settings = createSettings(sdnqDev);++ expect(getComponentSectionPolicy(sdnqDev, settings).defaultOpen).toBe(true);+ expect(getGenerationValidationReasons(sdnqDev, settings)).toEqual([mistralMissing, vaeMissing]);+ expect(+ getGenerationValidationReasons(+ sdnqDev,+ createSettings(sdnqDev, { mistralEncoderModel: mistralEncoder, vae: flux2Vae })+ )+ ).toEqual([]);+ });+ });+it('keeps FLUX.2 component source hidden and auto-selects installed Diffusers sources', () => {const model = createModel('flux2', { format: 'gguf_quantized', variant: 'klein_9b' });const source = createModel('flux2', { format: 'diffusers', variant: 'klein_9b' });diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.tsindex afc4576567..e2c57fa118 100644--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts@@ -39,7 +39,10 @@ import {isAnimaQwen3Encoder,isClipVariant,isDiffusersMainForBase,- isFlux2DiffusersSourceForModel,+ isBundledFlux2Main,+ isFlux2EncoderSourceForModel,+ isFlux2PipelineForModel,+ KLEIN_TO_QWEN3_VARIANT,isErnieImageMistralEncoder,isFlux2MistralEncoder,isFlux2Qwen3EncoderForModel,@@ -48,7 +51,6 @@ import {isMossImageQwen35Encoder,isQwen3Vl4bEncoder,isSelfContainedSDNQFlux1Pipeline,- isSelfContainedSDNQPipeline,isVaeAcceptedByBase,isZImageQwen3Encoder,type GenerateComponentFilter,@@ -945,27 +947,32 @@ type ComponentSourceCandidate = {variant?: unknown;};-const isFlux2DiffusersSource = (source: ComponentSourceCandidate | null | undefined): source is MainModelConfig =>- Boolean(source && isBundledMainForBase('flux2')(source));+const QWEN3_ENCODER_SIZE_LABELS: Partial<Record<string, string>> = { qwen3_4b: 'Qwen3 4B', qwen3_8b: 'Qwen3 8B' };-const hasFlux2DiffusersVaeSource = (ctx: ComponentPolicyContext): boolean =>+const isFlux2SourceFor =+ (model: GenerateModelConfig) =>+ (source: ComponentSourceCandidate | null | undefined): source is MainModelConfig =>+ Boolean(source && isFlux2PipelineForModel(model)(source));++const hasFlux2VaeSource = (ctx: ComponentPolicyContext): boolean =>ctx.model.type !== 'external_image_generator' &&- (isBundledMainForBase('flux2')(ctx.model) || isFlux2DiffusersSource(ctx.settings.componentSourceModel));+ (isBundledFlux2Main(ctx.model) || isFlux2SourceFor(ctx.model)(ctx.settings.componentSourceModel));-const hasFlux2DiffusersEncoderSource = (ctx: ComponentPolicyContext): boolean =>+const hasFlux2EncoderSource = (ctx: ComponentPolicyContext): boolean =>ctx.model.type !== 'external_image_generator' &&- (isBundledMainForBase('flux2')(ctx.model) ||+ (isBundledFlux2Main(ctx.model) ||Boolean(- ctx.settings.componentSourceModel && isFlux2DiffusersSourceForModel(ctx.model)(ctx.settings.componentSourceModel)+ ctx.settings.componentSourceModel && isFlux2EncoderSourceForModel(ctx.model)(ctx.settings.componentSourceModel)));-export const getFlux2DiffusersComponentSource = (+/** The saved component source the FLUX.2 loader can use: its VAE always, its encoder unless a standalone one is set. */+export const getFlux2ComponentSource = (model: MainModelConfig,settings: GenerateSettings): MainModelConfig | undefined => {const source = settings.componentSourceModel;- if (!isFlux2DiffusersSource(source)) {+ if (!isFlux2SourceFor(model)(source)) {return undefined;}@@ -975,7 +982,7 @@ export const getFlux2DiffusersComponentSource = (return source;}- return isFlux2DiffusersSourceForModel(model)(source) ? source : undefined;+ return isFlux2EncoderSourceForModel(model)(source) ? source : undefined;};export const getAutoFlux2ComponentSourceModel = (@@ -989,18 +996,20 @@ export const getAutoFlux2ComponentSourceModel = (const encoderModel = model.variant === 'dev' ? settings.mistralEncoderModel : settings.qwen3EncoderModel;- if (isBundledMainForBase('flux2')(model) || (encoderModel && settings.vae)) {+ if (isBundledFlux2Main(model) || (encoderModel && settings.vae)) {return null;}- const diffusersModels = models.filter(isFlux2DiffusersSource);- const variantMatch = diffusersModels.find(isFlux2DiffusersSourceForModel(model));+ const pipelines = models.filter(isFlux2SourceFor(model));+ const encoderSource = pipelines.find(isFlux2EncoderSourceForModel(model));if (!encoderModel && settings.vae) {- return variantMatch ?? null;+ return encoderSource ?? null;}- return variantMatch ?? diffusersModels[0] ?? null;+ // No VAE is set here. A pipeline that cannot give the encoder still gives the VAE; the encoder slot then asks for a+ // standalone one, if none is set yet.+ return encoderSource ?? pipelines[0] ?? null;};// Split/quantized families can satisfy required encoder/VAE slots from a bundled Diffusers source.@@ -1071,31 +1080,48 @@ const getBaseComponentSectionPolicy = (: [],};case 'flux2': {- const encoderSlot: ComponentSlotPolicy =- model.variant === 'dev'- ? {- ...mistralEncoderSlot(- 'Optional override; otherwise a compatible installed FLUX.2 [dev] Diffusers model is used.'- ),- required: (ctx) => !hasFlux2DiffusersEncoderSource(ctx),- missingMessage: 'Generate needs a Mistral Encoder for non-Diffusers FLUX.2 [dev] models.',- }- : {- ...qwen3EncoderSlot(- 'Optional override; otherwise a compatible installed FLUX.2 Diffusers model is used.'- ),- filter: (candidate, ctx) =>- ctx.model.type !== 'external_image_generator' && isFlux2Qwen3EncoderForModel(ctx.model)(candidate),- required: (ctx) => !hasFlux2DiffusersEncoderSource(ctx),- missingMessage: 'Generate needs a Qwen3 Encoder for non-Diffusers FLUX.2 models.',- };-- return createPolicy(!isSelfContainedSDNQPipeline(model) && model.format !== 'diffusers', [+ const isDev = model.variant === 'dev';+ // A Klein of unknown size takes either encoder, so its copy names none.+ const kleinQwen3 =+ typeof model.variant === 'string'+ ? QWEN3_ENCODER_SIZE_LABELS[KLEIN_TO_QWEN3_VARIANT[model.variant] ?? '']+ : undefined;+ const encoderSlot: ComponentSlotPolicy = isDev+ ? {+ ...mistralEncoderSlot(+ 'Optional override; otherwise taken from an installed FLUX.2 [dev] Diffusers pipeline.'+ ),+ required: (ctx) => !hasFlux2EncoderSource(ctx),+ missingMessage:+ 'Generate needs a Mistral Encoder or a FLUX.2 [dev] Diffusers pipeline for this FLUX.2 [dev] model.',+ }+ : {+ ...qwen3EncoderSlot(+ kleinQwen3+ ? `Optional ${kleinQwen3} override; otherwise taken from an installed FLUX.2 Klein Diffusers or SDNQ pipeline of the same size.`+ : 'Optional override; otherwise taken from an installed FLUX.2 Klein Diffusers or SDNQ pipeline.'+ ),+ filter: (candidate, ctx) =>+ ctx.model.type !== 'external_image_generator' && isFlux2Qwen3EncoderForModel(ctx.model)(candidate),+ required: (ctx) => !hasFlux2EncoderSource(ctx),+ missingMessage: kleinQwen3+ ? `Generate needs a ${kleinQwen3} Encoder or a same-size FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.`+ : 'Generate needs a Qwen3 Encoder or a FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.',+ };++ return createPolicy(!isBundledFlux2Main(model), [encoderSlot,{- ...vaeSlot('Optional override; otherwise an installed FLUX.2 Diffusers model is used.', isAcceptedVae),- required: (ctx) => !hasFlux2DiffusersVaeSource(ctx),- missingMessage: 'Generate needs a VAE for non-Diffusers FLUX.2 models.',+ ...vaeSlot(+ isDev+ ? 'Optional override; otherwise taken from an installed FLUX.2 Diffusers pipeline.'+ : 'Optional override; otherwise taken from an installed FLUX.2 Diffusers or SDNQ pipeline.',+ isAcceptedVae+ ),+ required: (ctx) => !hasFlux2VaeSource(ctx),+ missingMessage: isDev+ ? 'Generate needs a FLUX.2 VAE or a FLUX.2 Diffusers pipeline for this FLUX.2 [dev] model.'+ : 'Generate needs a FLUX.2 VAE or a FLUX.2 Diffusers or SDNQ pipeline for this FLUX.2 Klein model.',},]);}@@ -1417,7 +1443,7 @@ const isSelectedComponentCompatible = (}if (key === 'componentSourceModel' && model.type !== 'external_image_generator' && model.base === 'flux2') {- return Boolean(getFlux2DiffusersComponentSource(model, settings));+ return Boolean(getFlux2ComponentSource(model, settings));}if (!slotPolicy) {diff --git a/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.test.ts b/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.test.tsindex c0056ee1a6..74aaaafdbe 100644--- a/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.test.ts@@ -11,8 +11,10 @@ import {getCompatibleSelectedComponentKey,isAnimaQwen3Encoder,isErnieImageMistralEncoder,- isFlux2DiffusersSourceForModel,+ isBundledFlux2Main,+ isFlux2EncoderSourceForModel,isFlux2MistralEncoder,+ isFlux2PipelineForModel,isFlux2Qwen3EncoderForModel,isSelfContainedSDNQFlux1Pipeline,isSelfContainedSDNQPipeline,@@ -125,7 +127,7 @@ describe('Generate component compatibility', () => {});it('matches FLUX.2 component sources by shared Qwen3 encoder variant', () => {- const filter = isFlux2DiffusersSourceForModel(flux2Model('klein_9b'));+ const filter = isFlux2EncoderSourceForModel(flux2Model('klein_9b'));expect(filter(candidate({ base: 'flux2', format: 'diffusers', type: 'main', variant: 'klein_9b_base' }))).toBe(true@@ -142,17 +144,43 @@ describe('Generate component compatibility', () => {expect(isFlux2MistralEncoder(candidate({ type: 'qwen3_encoder' }))).toBe(false);expect(isFlux2Qwen3EncoderForModel(model)(candidate({ variant: 'qwen3_8b' }))).toBe(false);expect(- isFlux2DiffusersSourceForModel(model)(+ isFlux2EncoderSourceForModel(model)(candidate({ base: 'flux2', format: 'diffusers', type: 'main', variant: 'dev' }))).toBe(true);expect(- isFlux2DiffusersSourceForModel(model)(+ isFlux2EncoderSourceForModel(model)(candidate({ base: 'flux2', format: 'diffusers', type: 'main', variant: 'klein_9b' }))).toBe(false);});+ it('takes FLUX.2 [dev] components only from Diffusers pipelines and Klein ones from SDNQ pipelines too', () => {+ const pipeline = (format: string, variant: string) =>+ candidate({+ base: 'flux2',+ format,+ type: 'main',+ variant,+ ...(format === 'sdnq_quantized'+ ? { submodels: { text_encoder: {}, tokenizer: {}, transformer: {}, vae: {} } }+ : {}),+ });+ const sdnqKlein = pipeline('sdnq_quantized', 'klein_9b');+ const sdnqDev = pipeline('sdnq_quantized', 'dev');+ const diffusersKlein = pipeline('diffusers', 'klein_9b');+ const diffusersDev = pipeline('diffusers', 'dev');+ const pipelines = [sdnqKlein, sdnqDev, diffusersKlein, diffusersDev];++ // Any Diffusers pipeline gives [dev] its VAE; only a [dev] one its Mistral encoder.+ expect(pipelines.map(isFlux2PipelineForModel(flux2Model('dev')))).toEqual([false, false, true, true]);+ expect(pipelines.map(isFlux2EncoderSourceForModel(flux2Model('dev')))).toEqual([false, false, false, true]);+ expect(pipelines.map(isFlux2PipelineForModel(flux2Model('klein_9b')))).toEqual([true, true, true, true]);+ expect(pipelines.map(isFlux2EncoderSourceForModel(flux2Model('klein_9b')))).toEqual([true, false, true, false]);+ // The selected install counts as bundled by the same rule.+ expect(pipelines.map(isBundledFlux2Main)).toEqual([true, false, true, true]);+ });+it('keeps each Mistral-family encoder out of the other family slot', () => {// Filter variants even when they share a model type.const ministral = candidate({ type: 'mistral_encoder', variant: 'ministral3_3b' });diff --git a/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.ts b/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.tsindex 8972ff1999..d276af2046 100644--- a/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.ts@@ -132,12 +132,25 @@ export const isFlux2Qwen3EncoderForModel = (selectedModel: GenerateModelConfig):};};-export const isFlux2DiffusersSourceForModel = (selectedModel: GenerateModelConfig): GenerateComponentFilter => {+/**+ * The FLUX.2 pipelines whose VAE the selected model's loader takes, the selected install included.+ * `flux2_klein_model_loader` reads a Diffusers install or a self-contained SDNQ pipeline. `flux2_dev_model_loader`+ * reads only a Diffusers install: the SDNQ FLUX.2 loader builds a Qwen3 encoder, never the Mistral one [dev] runs.+ */+export const isFlux2PipelineForModel = (selectedModel: GenerateComponentCandidate): GenerateComponentFilter =>+ selectedModel.variant === 'dev' ? isDiffusersMainForBase('flux2') : isBundledMainForBase('flux2');++/** Whether a FLUX.2 main brings its own encoder and VAE to its loader. */+export const isBundledFlux2Main = (model: GenerateComponentCandidate): boolean => isFlux2PipelineForModel(model)(model);++/** The FLUX.2 pipelines that also supply the selected model's encoder: [dev] ones for [dev], same-size Klein ones for Klein. */+export const isFlux2EncoderSourceForModel = (selectedModel: GenerateModelConfig): GenerateComponentFilter => {+ const isPipeline = isFlux2PipelineForModel(selectedModel);const selectedVariant = typeof selectedModel.variant === 'string' ? selectedModel.variant : null;const requiredVariant = selectedVariant ? KLEIN_TO_QWEN3_VARIANT[selectedVariant] : null;return (model) => {- if (!isBundledMainForBase('flux2')(model)) {+ if (!isPipeline(model)) {return false;}@@ -164,7 +177,7 @@ export const isCompatibleDiffusersComponentSourceForModel = (}if (selectedModel.base === 'flux2') {- return isFlux2DiffusersSourceForModel(selectedModel)(source);+ return isFlux2EncoderSourceForModel(selectedModel)(source);}return isBundledMainForBase(selectedModel.base)(source);diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.test.tsindex 8a3597ffe0..d5d74c9cca 100644--- a/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts@@ -532,6 +532,67 @@ describe('compileGenerateGraph', () => {expect(graph.nodes.model_loader?.vae_model).toBeUndefined();});+ describe('FLUX.2 [dev] component sources', () => {+ const sdnqKleinSource: MainModelConfig = {+ ...flux2Klein9bModel,+ format: 'sdnq_quantized',+ key: 'flux2-klein-9b-sdnq-source',+ submodels: completeSdnqPipeline,+ };+ const diffusersKleinSource: MainModelConfig = {+ ...flux2Klein9bModel,+ format: 'diffusers',+ key: 'flux2-klein-9b-diffusers-source',+ };++ it('never sends an SDNQ pipeline as the Mistral source', () => {+ expect(() =>+ compile(flux2DevGgufModel, { componentSourceModel: sdnqKleinSource, mistralEncoderModel: mistralEncoder })+ ).toThrow('Generate needs a FLUX.2 VAE or a FLUX.2 Diffusers pipeline for this FLUX.2 [dev] model.');++ const graph = compile(flux2DevGgufModel, {+ componentSourceModel: sdnqKleinSource,+ mistralEncoderModel: mistralEncoder,+ vae: flux2Vae,+ });++ expect(graph.nodes.model_loader).toMatchObject({+ mistral_encoder_model: mistralEncoder,+ mistral_source_model: undefined,+ vae_model: flux2Vae,+ });+ });++ it('takes only the VAE from a Diffusers Klein pipeline', () => {+ const graph = compile(flux2DevGgufModel, {+ componentSourceModel: diffusersKleinSource,+ mistralEncoderModel: mistralEncoder,+ });++ expect(graph.nodes.model_loader).toMatchObject({+ mistral_encoder_model: mistralEncoder,+ mistral_source_model: diffusersKleinSource,+ type: 'flux2_dev_model_loader',+ vae_model: undefined,+ });+ });++ it('sends a self-contained SDNQ [dev] main its standalone encoder and VAE', () => {+ const sdnqDev: MainModelConfig = { ...flux2DevModel, format: 'sdnq_quantized', submodels: completeSdnqPipeline };++ expect(() => compile(sdnqDev)).toThrow(+ 'Generate needs a Mistral Encoder or a FLUX.2 [dev] Diffusers pipeline for this FLUX.2 [dev] model.'+ );+ expect(compile(sdnqDev, { mistralEncoderModel: mistralEncoder, vae: flux2Vae }).nodes.model_loader).toMatchObject(+ {+ mistral_encoder_model: mistralEncoder,+ type: 'flux2_dev_model_loader',+ vae_model: flux2Vae,+ }+ );+ });+ });+it('uses a complete FLUX.2 SDNQ component source without standalone overrides', () => {const source: MainModelConfig = {...flux2Klein9bModel,@@ -557,7 +618,7 @@ describe('compileGenerateGraph', () => {};expect(() => compile(flux2Klein9bModel, { componentSourceModel: source })).toThrow(- 'Generate needs a Qwen3 Encoder for non-Diffusers FLUX.2 models.'+ 'Generate needs a Qwen3 8B Encoder or a same-size FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.');});@@ -578,7 +639,7 @@ describe('compileGenerateGraph', () => {it('rejects a stale incompatible FLUX.2 component source when Qwen3 is missing', () => {expect(() => compile(flux2Klein9bModel, { componentSourceModel: incompatibleFlux2Source, vae: flux2Vae })).toThrow(- 'Generate needs a Qwen3 Encoder for non-Diffusers FLUX.2 models.'+ 'Generate needs a Qwen3 8B Encoder or a same-size FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.');});diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.tsindex 38553416f1..8685a48621 100644--- a/invokeai/frontend/webv2/src/features/generation/core/graph.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.ts@@ -21,7 +21,7 @@ import {coerceSchedulerForGraph,getExternalModeReason,getExternalProviderNodeType,- getFlux2DiffusersComponentSource,+ getFlux2ComponentSource,getGenerationDimensions,getGenerationValidationReasons,isStrengthOnlyIPAdapterBase,@@ -31,6 +31,7 @@ import {getCompatibleDiffusersComponentSource,isAnimaQwen35Encoder,isAnimaQwen3Encoder,+ isBundledFlux2Main,isBundledMainForBase,isErnieImageMistralEncoder,isFlux2MistralEncoder,@@ -758,8 +759,8 @@ const buildFlux2Graph = (projectSettings: GenerationProjectSettings): BackendGraphContract => {const isDev = model.variant === 'dev';- const sourceModel = getFlux2DiffusersComponentSource(model, settings);- const hasBundledComponents = isBundledMainForBase('flux2')(model) || sourceModel;+ const sourceModel = getFlux2ComponentSource(model, settings);+ const hasBundledComponents = isBundledFlux2Main(model) || sourceModel;const mistralEncoderModel =settings.mistralEncoderModel && isFlux2MistralEncoder(settings.mistralEncoderModel)? settings.mistralEncoderModel@@ -773,7 +774,7 @@ const buildFlux2Graph = (if (!hasBundledComponents && (!vaeModel || !encoderModel)) {throw new Error(- `FLUX.2 non-Diffusers models require a VAE and ${isDev ? 'Mistral' : 'Qwen3'} Encoder, or a compatible Diffusers component source.`+ `This FLUX.2 model needs a VAE and ${isDev ? 'Mistral' : 'Qwen3'} Encoder, or a FLUX.2 pipeline its loader can take them from.`);}diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.tsindex 45c932c23b..283dc4eb05 100644--- a/invokeai/frontend/webv2/src/features/generation/settings.ts+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts@@ -105,6 +105,7 @@ export {getCompatibleDiffusersComponentSource,isAnimaQwen35Encoder,isAnimaQwen3Encoder,+ isBundledFlux2Main,isBundledMainForBase,isDiffusersMainForBase,isFlux2MistralEncoder,diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.test.tsindex 3362f71c96..0c6124bf6a 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts@@ -485,6 +485,23 @@ describe('text encoder and VAE components', () => {expect(getUpscaleValidationReasons(ready([diffusers('dev'), spandrel]))).toEqual([]);});+ it('lets a self-contained SDNQ Klein bring its own encoder and VAE, but not an SDNQ [dev]', () => {+ const spandrel = model('spandrel', 'spandrel_image_to_image', 'any');+ const sdnq = (variant: string) =>+ ({+ ...withVariant(model('f', 'main', 'flux2'), variant),+ format: 'sdnq_quantized',+ submodels: { text_encoder: {}, tokenizer: {}, transformer: {}, vae: {} },+ }) as ModelConfig;++ expect(getUpscaleValidationReasons(ready([sdnq('klein_9b'), spandrel]))).toEqual([]);+ // The [dev] loader reads only a Diffusers install's own components.+ expect(getUpscaleValidationReasons(ready([sdnq('dev'), spandrel]))).toEqual([+ 'Upscale needs a Mistral encoder for this main model.',+ 'Upscale needs a VAE for this main model.',+ ]);+ });+it('asks a GGUF Qwen Image for its Qwen VL encoder and a VAE, and a Diffusers one for neither', () => {const spandrel = model('spandrel', 'spandrel_image_to_image', 'any');const gguf = { ...model('q', 'main', 'qwen-image'), format: 'gguf_quantized' } as ModelConfig;diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.tsindex cc59716a3b..b390737ce9 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts@@ -18,6 +18,7 @@ import {hasArchitectureCapabilities,isAnimaQwen35Encoder,isAnimaQwen3Encoder,+ isBundledFlux2Main,isBundledMainForBase,isFlux2MistralEncoder,isFlux2Qwen3EncoderForModel,@@ -376,16 +377,11 @@ export const UPSCALE_ARCHITECTURES = {tileControlNet: null,},flux2: {- // Both loaders fall back to a bundled main model's own encoder and VAE; [dev]'s counts only a Diffusers- // install as bundled, Klein's a complete SDNQ pipeline too.+ // Both loaders fall back to a bundled main model's own encoder and VAE.components: (model) =>- model.variant === 'dev'- ? model.format === 'diffusers'- ? NO_COMPONENTS- : { slots: [FLUX2_MISTRAL_SLOT], vae: true }- : isBundledMainForBase('flux2')(model)- ? NO_COMPONENTS- : { slots: [flux2KleinQwen3Slot(model)], vae: true },+ isBundledFlux2Main(model)+ ? NO_COMPONENTS+ : { slots: [model.variant === 'dev' ? FLUX2_MISTRAL_SLOT : flux2KleinQwen3Slot(model)], vae: true },denoiseGrid: 16,// `flux2_denoise` clips by sigma value like FLUX.1, then re-spaces the window to the requested steps.indexClipping: null,diff --git a/invokeai/frontend/webv2/src/workbench/invocation.test.ts b/invokeai/frontend/webv2/src/workbench/invocation.test.tsindex 832d60cd59..b46d0ace96 100644--- a/invokeai/frontend/webv2/src/workbench/invocation.test.ts+++ b/invokeai/frontend/webv2/src/workbench/invocation.test.ts@@ -185,7 +185,7 @@ describe('resolveInvocationRoute', () => {expect(route.sourceValid).toBe(false);expect(route.validationReasons.map(reasonText)).toContain(- 'Generate needs a Qwen3 Encoder for non-Diffusers FLUX.2 models.'+ 'Generate needs a Qwen3 8B Encoder or a same-size FLUX.2 Klein Diffusers or SDNQ pipeline for this FLUX.2 Klein model.');});diff --git a/tests/app/services/working_memory_calibration/test_working_memory_calibration_plan.py b/tests/app/services/working_memory_calibration/test_working_memory_calibration_plan.pyindex a7566c8e2d..05fc4065c0 100644--- a/tests/app/services/working_memory_calibration/test_working_memory_calibration_plan.py+++ b/tests/app/services/working_memory_calibration/test_working_memory_calibration_plan.py@@ -36,6 +36,7 @@ from invokeai.backend.model_manager.taxonomy import (BaseModelType,Flux2VariantType,FluxVariantType,+ MistralVariantType,ModelFormat,ModelType,ModelVariantType,@@ -287,6 +288,49 @@ KLEIN_4B_SDNQ = _sdnq_pipeline("klein-4b-sdnq", BaseModelType.Flux2, variant=FluFLUX2_VAE = _model("flux2-vae", BaseModelType.Flux2, ModelType.VAE)QWEN3_4B = _model("qwen3-4b", BaseModelType.Any, ModelType.Qwen3Encoder, variant=Qwen3VariantType.Qwen3_4B)GGUF_DEV = _model("dev-gguf", BaseModelType.Flux2, format="gguf_quantized", variant=Flux2VariantType.Dev)+SDNQ_DEV = _sdnq_pipeline("dev-sdnq", BaseModelType.Flux2, variant=Flux2VariantType.Dev)+MISTRAL = _model("mistral", BaseModelType.Any, ModelType.MistralEncoder, variant=MistralVariantType.Mistral24B)+FP16_VAES = VaeDtypes(standalone_flux="fp16", z_image_pipeline="bf16", sdnq_quantized_vae=lambda config: False)+"""A standalone FLUX.2 VAE decodes in fp16, apart from a Diffusers pipeline's bf16 and an SDNQ pipeline's fp32."""+++ "target, line",+ [(GGUF_KLEIN_9B, f"decode_{SDNQ_PIPELINE_VAE_DTYPE}"), (GGUF_DEV, "decode_fp16")],+ ids=["klein-takes-the-sdnq-pipelines-vae", "dev-decodes-with-the-standalone-vae"],+)+def test_an_sdnq_flux2_pipeline_is_a_component_source_for_klein_only(target, line) -> None:+ """The Klein model loader node takes a VAE from a self-contained SDNQ pipeline; the [dev] one takes components only+ from a Diffusers pipeline, so beside the same installed models a [dev] model decodes with the standalone VAE."""+ models = [KLEIN_4B_SDNQ, FLUX2_VAE, MISTRAL, QWEN3_8B]++ assert _lines_of(_plan(target, models, vae_dtypes=FP16_VAES)) == {(line, ())}+++def test_a_dev_model_beside_only_an_sdnq_pipeline_and_no_vae_cannot_be_calibrated() -> None:+ """Issue #10010: a [dev] GGUF model with a standalone Mistral encoder and only an SDNQ Klein pipeline has no source+ its loader takes a VAE from, so without a standalone VAE no graph compiles."""+ plan = _plan(GGUF_DEV, [KLEIN_4B_SDNQ, MISTRAL])++ assert not plan.supported and plan.cases == [] and "standalone VAE" in (plan.reason or "")+++def test_a_diffusers_klein_pipeline_gives_a_dev_model_its_vae_beside_a_mistral_encoder() -> None:+ """The [dev] loader takes the VAE of any Diffusers FLUX.2 pipeline, passing over an SDNQ one listed first."""+ klein = _model("klein-diffusers", BaseModelType.Flux2, format="diffusers", variant=Flux2VariantType.Klein4B)++ plan = _plan(GGUF_DEV, [KLEIN_4B_SDNQ, klein, FLUX2_VAE, MISTRAL], vae_dtypes=FP16_VAES)++ assert _lines_of(plan) == {(f"decode_{FLUX2_PIPELINE_VAE_DTYPE}", ())}+++def test_an_sdnq_dev_model_decodes_with_a_standalone_vae_not_its_own() -> None:+ """The [dev] loader takes no components from an SDNQ pipeline, the [dev] model itself included: it decodes with the+ standalone VAE, or with a Diffusers [dev] pipeline's where one is installed."""+ dev = _model("dev-diffusers", BaseModelType.Flux2, format="diffusers", variant=Flux2VariantType.Dev)++ assert _lines_of(_plan(SDNQ_DEV, [FLUX2_VAE, MISTRAL], vae_dtypes=FP16_VAES)) == {("decode_fp16", ())}+ assert _lines_of(_plan(SDNQ_DEV, [dev], vae_dtypes=FP16_VAES)) == {(f"decode_{FLUX2_PIPELINE_VAE_DTYPE}", ())}@pytest.mark.parametrize(@@ -298,10 +342,20 @@ GGUF_DEV = _model("dev-gguf", BaseModelType.Flux2, format="gguf_quantized", vari# The 4B encoder fits the 4B transformer only.(GGUF_KLEIN_9B, [KLEIN_4B_SDNQ, QWEN3_4B], "Qwen3 8B"),(GGUF_DEV, [KLEIN_4B_SDNQ, FLUX2_VAE, QWEN3_8B], "Mistral"),+ # The [dev] loader takes no encoder from an SDNQ [dev] model itself.+ (SDNQ_DEV, [FLUX2_VAE], "Mistral"),# A VAE goes through the only main model that takes its pick, which cannot generate.(FLUX2_VAE, [GGUF_KLEIN_9B], "Qwen3 8B"),],- ids=["unfitting-source", "unfitting-source-and-vae", "vae-alone", "encoder-of-another-size", "dev", "vae-target"],+ ids=[+ "unfitting-source",+ "unfitting-source-and-vae",+ "vae-alone",+ "encoder-of-another-size",+ "dev",+ "sdnq-dev",+ "vae-target",+ ],)def test_a_flux2_model_without_a_text_encoder_generate_can_use_cannot_be_calibrated(target, models, encoder) -> None:"""A FLUX.2 model that is no pipeline compiles only with a text encoder: a fitting pipeline's, or a standalone one of