Skip to content

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.

fix(z-image): accept only the Qwen3 4B text encoder (#9936)

Josh Corbett0d65141e6c41
diff --git a/docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx b/docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx
index 7279c395b1..7582a8806e 100644
--- a/docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx
+++ b/docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx
@@ -58,7 +58,7 @@ Ministral 3B encoder. Others are recognized by their layer names and fail, or mi
|---|---|---|---|---|---|---|---|---|
| T5-XXL | FLUX.1, SD 3 | ✓ | ✗ | ✗ | ✗ | ✗ | ✓ | ✓ (and bitsandbytes int8) |
| CLIP-L / CLIP-G | SD, SDXL, FLUX.1, SD 3 | ✓ | ✓ | R | R | – | ✗ | CLIP-L inside a FLUX.1 SDNQ pipeline |
-| Qwen3 0.6B / 4B / 8B | Z-Image, FLUX.2 Klein, Anima | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
+| Qwen3 0.6B / 4B / 8B | Z-Image (4B), FLUX.2 Klein (4B, 8B), Anima (0.6B) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Qwen3-VL 4B / 8B | Krea-2, Ideogram 4, Qwen-Image-2.1 (8B) | ✓ | ✓ | ✓ | ✓ | ✗ | ✓ | ✗ |
| Qwen3-VL 32B (truncated) | MiniMax H3 | in the Diffusers folder | ✓ | L | ✓ | L | ✗ | ✗ |
| Qwen3.5 4B | Anima 3.8B | ✗ | ✓ | L | L | L | ✗ | ✗ |
diff --git a/docs/src/content/docs/Users Guide/03.Models/Local Models/z-image.mdx b/docs/src/content/docs/Users Guide/03.Models/Local Models/z-image.mdx
index 4e6b763219..b47d5d87d3 100644
--- a/docs/src/content/docs/Users Guide/03.Models/Local Models/z-image.mdx
+++ b/docs/src/content/docs/Users Guide/03.Models/Local Models/z-image.mdx
@@ -72,7 +72,10 @@ When the selected Z-Image model is not a self-contained pipeline, the **Componen
model shows three slots:
- **Component source**: a Diffusers (or SDNQ) Z-Image pipeline to borrow the encoder and VAE from.
-- **Qwen3 Encoder**: a standalone Qwen3 4B encoder.
+- **Qwen3 Encoder**: a standalone Qwen3 4B encoder. Only 4B encoders are listed: the Qwen3 8B encoder that
+ FLUX.2 Klein 9B uses is too wide for Z-Image. A project that still has an 8B encoder selected shows it in the
+ slot with an error, and Invoke stays unavailable until you pick a 4B encoder or clear the slot. In a
+ workflow, **Main Model - Z-Image** refuses any other Qwen3 encoder by name when it runs.
- **VAE**: Z-Image decodes with the FLUX VAE, so FLUX-base VAEs are listed here.
You need either a component source or both a Qwen3 encoder and a VAE before you can generate.
diff --git a/invokeai/app/invocations/z_image/z_image_model_loader.py b/invokeai/app/invocations/z_image/z_image_model_loader.py
index feb04b825b..5a2591c4b0 100644
--- a/invokeai/app/invocations/z_image/z_image_model_loader.py
+++ b/invokeai/app/invocations/z_image/z_image_model_loader.py
@@ -17,7 +17,13 @@ from invokeai.app.invocations.model import (
)
from invokeai.app.services.shared.invocation_context import InvocationContext
from invokeai.backend.architectures import accepted_vae_bases
-from invokeai.backend.model_manager.taxonomy import BaseModelType, ModelFormat, ModelType, SubModelType
+from invokeai.backend.model_manager.taxonomy import (
+ BaseModelType,
+ ModelFormat,
+ ModelType,
+ Qwen3VariantType,
+ SubModelType,
+)
@invocation_output("z_image_model_loader_output")
@@ -122,6 +128,7 @@ class ZImageModelLoaderInvocation(BaseInvocation):
# Determine Qwen3 Encoder source
if self.qwen3_encoder_model is not None:
# Use standalone Qwen3 Encoder
+ self._validate_qwen3_encoder_variant(context, self.qwen3_encoder_model)
qwen3_tokenizer = self.qwen3_encoder_model.model_copy(update={"submodel_type": SubModelType.Tokenizer})
qwen3_encoder = self.qwen3_encoder_model.model_copy(update={"submodel_type": SubModelType.TextEncoder})
elif self.qwen3_source_model is not None:
@@ -145,6 +152,23 @@ class ZImageModelLoaderInvocation(BaseInvocation):
vae=VAEField(vae=vae),
)
+ def _validate_qwen3_encoder_variant(self, context: InvocationContext, encoder: ModelIdentifierField) -> None:
+ """Z-Image's caption embedder takes the Qwen3 4B hidden size (2560). Every Qwen3 size installs
+ under the same model type, so the 8B (4096) or 0.6B (1024) would otherwise load and then fail
+ as a shape mismatch on the first denoise step, naming a tensor rather than the selection."""
+ config = context.models.get_config(encoder)
+ variant = getattr(config, "variant", None)
+ is_qwen3 = config.type is ModelType.Qwen3Encoder
+ if is_qwen3 and variant == Qwen3VariantType.Qwen3_4B:
+ return
+ described = (
+ f"a Qwen3 encoder of variant '{getattr(variant, 'value', variant)}'" if is_qwen3 else "not a Qwen3 encoder"
+ )
+ raise ValueError(
+ f"'{config.name}' is {described}. Z-Image conditions on the Qwen3 4B encoder (hidden size 2560): "
+ "select a Qwen3 4B encoder, or clear it and set 'Qwen3 Source' to a Z-Image pipeline."
+ )
+
def _get_self_contained_source(self, context: InvocationContext) -> Optional[ModelIdentifierField]:
"""Return the main model as a submodel source when it is a self-contained pipeline that
ships its own VAE and Qwen3 submodels.
diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
index d4b75ad47a..f4f3ea64af 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
@@ -506,16 +506,58 @@ describe('component policies', () => {
).toEqual([]);
});
- it('validates Z-Image non-anima Qwen3 and flux VAE requirements', () => {
+ describe('Z-Image Qwen3 encoder', () => {
const model = createModel('z-image', { format: 'checkpoint' });
+ const qwen3_4b: ComponentModelConfig = { ...qwen3Encoder, key: 'qwen3-4b', name: 'Qwen3 4B', variant: 'qwen3_4b' };
+ const qwen3_8b: ComponentModelConfig = { ...qwen3Encoder, key: 'qwen3-8b', name: 'Qwen3 8B', variant: 'qwen3_8b' };
+ const source = createModel('z-image', { key: 'z-image-diffusers', format: 'diffusers' });
+ const incompatible =
+ 'The selected Qwen3 Encoder is not the 4B one Z-Image conditions on. Select a Qwen3 4B Encoder or clear it.';
+
+ it('requires a Qwen3 4B encoder and a FLUX VAE without a component source', () => {
+ expect(getGenerationValidationReasons(model, createSettings(model))).toEqual([
+ 'Generate needs a Qwen3 4B Encoder for Z-Image models.',
+ 'Generate needs a VAE for Z-Image models.',
+ ]);
+ expect(
+ getGenerationValidationReasons(model, createSettings(model, { qwen3EncoderModel: qwen3_4b, vae: fluxVae }))
+ ).toEqual([]);
+ });
- expect(getGenerationValidationReasons(model, createSettings(model))).toEqual([
- 'Generate needs a Qwen3 Encoder for Z-Image models.',
- 'Generate needs a VAE for Z-Image models.',
- ]);
- expect(
- getGenerationValidationReasons(model, createSettings(model, { qwen3EncoderModel: qwen3Encoder, vae: fluxVae }))
- ).toEqual([]);
+ it('names a saved 8B encoder as incompatible, with or without a component source to fall back on', () => {
+ expect(
+ getGenerationValidationReasons(model, createSettings(model, { qwen3EncoderModel: qwen3_8b, vae: fluxVae }))
+ ).toEqual([incompatible]);
+ expect(
+ getGenerationValidationReasons(
+ model,
+ createSettings(model, { componentSourceModel: source, qwen3EncoderModel: qwen3_8b })
+ )
+ ).toEqual([incompatible]);
+ expect(getGenerationValidationReasons(model, createSettings(model, { componentSourceModel: source }))).toEqual(
+ []
+ );
+ });
+
+ it('offers only the 4B encoder and clears an 8B one when switching to Z-Image', () => {
+ const settings = createSettings(model);
+ const slot = getComponentSectionPolicy(model, settings).slots.find((s) => s.key === 'qwen3EncoderModel');
+ const ctx = { model, selectedComponents: { ...settings }, settings };
+ const klein9b = createModel('flux2', { format: 'gguf_quantized', variant: 'klein_9b' });
+
+ expect(
+ [qwen3_4b, qwen3_8b, animaQwen3Encoder].map((encoder) => slot?.filter?.(encoder as GenerateModelConfig, ctx))
+ ).toEqual([true, false, false]);
+
+ const result = getGenerateModelSelectionResult({
+ currentValues: createSettings(klein9b, { qwen3EncoderModel: qwen3_8b, vae: fluxVae }),
+ model,
+ models: [],
+ });
+
+ expect(result.settings.qwen3EncoderModel).toBeNull();
+ expect(result.clearedLabels).toContain('Qwen3 Encoder');
+ });
});
it('offers FLUX.1 only CLIP-L encoders, the one its text encoder runs', () => {
diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
index c70f7ca260..61ca0422ee 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
@@ -42,10 +42,10 @@ import {
isQwen3Vl8bEncoder,
isIdeogram4UnconditionalBranch,
isKrea2Qwen3VlEncoder,
- isNonAnimaQwen3Encoder,
isSelfContainedSDNQFlux1Pipeline,
isSelfContainedSDNQPipeline,
isVaeAcceptedByBase,
+ isZImageQwen3Encoder,
type GenerateComponentFilter,
} from './componentCompatibility';
import { DYNAMIC_PROMPTS_DEFAULT_MAX_PROMPTS } from './dynamicPrompts';
@@ -595,6 +595,11 @@ export interface ComponentSlotPolicy {
filter?: (candidate: ModelConfig, ctx: ComponentPolicyContext) => boolean;
required?: (ctx: ComponentPolicyContext) => boolean;
missingMessage?: string;
+ /**
+ * Reported whenever the selected value fails `filter`, required or not, so a saved selection the graph cannot use
+ * blocks Invoke by name instead of being dropped in favour of a component source.
+ */
+ incompatibleMessage?: string;
}
export interface ComponentSectionPolicy {
@@ -885,13 +890,17 @@ const isBundledOrDiffusersSourceSatisfied = (ctx: ComponentPolicyContext): boole
// Slot validation is shared by invocation readiness and graph preflight so picker requirements cannot drift.
const validateSlots = (policy: Pick<ComponentSectionPolicy, 'slots'>, ctx: ComponentPolicyContext): string[] =>
policy.slots.flatMap((slotPolicy) => {
+ const value = ctx.selectedComponents[slotPolicy.key];
+ const isValid = value && (!slotPolicy.filter || slotPolicy.filter(value as ModelConfig, ctx));
+
+ if (value && !isValid && slotPolicy.incompatibleMessage) {
+ return [slotPolicy.incompatibleMessage];
+ }
+
if (!slotPolicy.required?.(ctx)) {
return [];
}
- const value = ctx.selectedComponents[slotPolicy.key];
- const isValid = value && (!slotPolicy.filter || slotPolicy.filter(value as ModelConfig, ctx));
-
return isValid ? [] : [slotPolicy.missingMessage ?? `Generate needs a ${slotPolicy.label} for this model.`];
});
@@ -1004,9 +1013,15 @@ const getBaseComponentSectionPolicy = (
'Select a bundled Z-Image pipeline to provide VAE and Qwen3 components.'
),
{
- ...qwen3EncoderSlot('Required unless a Diffusers component source is available.', isNonAnimaQwen3Encoder),
+ ...qwen3EncoderSlot(
+ 'Z-Image conditions on the Qwen3 4B encoder, not the 8B one FLUX.2 Klein 9B uses. Required unless a ' +
+ 'Diffusers component source is available.',
+ isZImageQwen3Encoder
+ ),
required: (ctx) => !isBundledOrDiffusersSourceSatisfied(ctx),
- missingMessage: 'Generate needs a Qwen3 Encoder for Z-Image models.',
+ missingMessage: 'Generate needs a Qwen3 4B Encoder for Z-Image models.',
+ incompatibleMessage:
+ 'The selected Qwen3 Encoder is not the 4B one Z-Image conditions on. Select a Qwen3 4B Encoder or clear it.',
},
{
...vaeSlot(
diff --git a/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.test.ts b/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.test.ts
index 5c6ad975ae..c0056ee1a6 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.test.ts
@@ -14,11 +14,11 @@ import {
isFlux2DiffusersSourceForModel,
isFlux2MistralEncoder,
isFlux2Qwen3EncoderForModel,
- isNonAnimaQwen3Encoder,
isSelfContainedSDNQFlux1Pipeline,
isSelfContainedSDNQPipeline,
isVaeAcceptedByBase,
isVaeCompatibleWithGenerateModel,
+ isZImageQwen3Encoder,
type GenerateComponentCandidate,
} from './componentCompatibility';
@@ -96,14 +96,15 @@ describe('Generate component compatibility', () => {
).toBe(false);
});
- it('separates Anima Qwen3 0.6B encoders from other Qwen3 encoders', () => {
+ it('gives Anima the Qwen3 0.6B encoder and Z-Image only the 4B one', () => {
const qwen06b = candidate({ variant: 'qwen3_06b' });
const qwen4b = candidate({ variant: 'qwen3_4b' });
+ const qwen8b = candidate({ variant: 'qwen3_8b' });
- expect(isAnimaQwen3Encoder(qwen06b)).toBe(true);
- expect(isAnimaQwen3Encoder(qwen4b)).toBe(false);
- expect(isNonAnimaQwen3Encoder(qwen06b)).toBe(false);
- expect(isNonAnimaQwen3Encoder(qwen4b)).toBe(true);
+ expect([qwen06b, qwen4b, qwen8b].map(isAnimaQwen3Encoder)).toEqual([true, false, false]);
+ // The 8B encoder is 4096 wide; Z-Image's caption embedder takes 2560.
+ expect([qwen06b, qwen4b, qwen8b].map(isZImageQwen3Encoder)).toEqual([false, true, false]);
+ expect(isZImageQwen3Encoder(candidate({ type: 'qwen3_vl_encoder', variant: 'qwen3_4b' }))).toBe(false);
});
it('matches FLUX.2 Klein models to compatible Qwen3 encoder variants', () => {
@@ -114,6 +115,15 @@ describe('Generate component compatibility', () => {
expect(filter(candidate({ variant: 'qwen3_06b' }))).toBe(false);
});
+ it('lets a FLUX.2 Klein model of unknown size take either Klein encoder but never the Anima one', () => {
+ const filter = isFlux2Qwen3EncoderForModel(flux2Model('klein_unknown'));
+
+ expect(filter(candidate({ variant: 'qwen3_4b' }))).toBe(true);
+ expect(filter(candidate({ variant: 'qwen3_8b' }))).toBe(true);
+ expect(filter(candidate({ variant: 'qwen3_06b' }))).toBe(false);
+ expect(filter(candidate({ type: 'mistral_encoder', variant: 'qwen3_8b' }))).toBe(false);
+ });
+
it('matches FLUX.2 component sources by shared Qwen3 encoder variant', () => {
const filter = isFlux2DiffusersSourceForModel(flux2Model('klein_9b'));
diff --git a/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.ts b/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.ts
index d5713a5fe9..ccdd20f1a4 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/componentCompatibility.ts
@@ -81,8 +81,9 @@ export const isAnimaQwen3Encoder: GenerateComponentFilter = (model) =>
export const isAnimaQwen35Encoder: GenerateComponentFilter = (model) =>
model.type === 'qwen3_5_encoder' && model.variant === 'qwen3_5_4b';
-export const isNonAnimaQwen3Encoder: GenerateComponentFilter = (model) =>
- model.type === 'qwen3_encoder' && model.variant !== 'qwen3_06b';
+/** Z-Image's caption embedder is 2560 wide, the Qwen3 4B hidden size; the 8B encoder's 4096 cannot feed it. */
+export const isZImageQwen3Encoder: GenerateComponentFilter = (model) =>
+ model.type === 'qwen3_encoder' && model.variant === 'qwen3_4b';
/** The optional 4-channel ControlNet-LLLite adapter the canvas feeds during Anima inpainting and outpainting. */
export const isAnimaInpaintAdapter: GenerateComponentFilter = (model) => isAnimaInpaintAdapterModel(model);
@@ -119,7 +120,7 @@ export const isFlux2Qwen3EncoderForModel = (selectedModel: GenerateModelConfig):
typeof selectedModel.variant === 'string' ? KLEIN_TO_QWEN3_VARIANT[selectedModel.variant] : null;
return (model) => {
- if (!isNonAnimaQwen3Encoder(model)) {
+ if (model.type !== 'qwen3_encoder' || model.variant === 'qwen3_06b') {
return false;
}
diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts
index a70cebf808..9d8716f313 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts
@@ -474,6 +474,22 @@ describe('compileGenerateGraph', () => {
expect(zImage.nodes.model_loader).toMatchObject({ qwen3_encoder_model: undefined, vae_model: undefined });
});
+ it('sends a standalone Z-Image transformer the Qwen3 4B encoder and refuses the 8B one', () => {
+ const zImageGguf: MainModelConfig = { ...zImageModel, format: 'gguf_quantized' };
+ const qwen3_4b: ComponentModelConfig = { ...qwen3Encoder, key: 'qwen3-4b', variant: 'qwen3_4b' };
+ const qwen3_8b: ComponentModelConfig = { ...qwen3Encoder, key: 'qwen3-8b', variant: 'qwen3_8b' };
+ const graph = compile(zImageGguf, { qwen3EncoderModel: qwen3_4b, vae: fluxVae });
+
+ expect(graph.nodes.model_loader).toMatchObject({
+ qwen3_encoder_model: qwen3_4b,
+ type: 'z_image_model_loader',
+ vae_model: fluxVae,
+ });
+ expect(() => compile(zImageGguf, { qwen3EncoderModel: qwen3_8b, vae: fluxVae })).toThrow(
+ 'The selected Qwen3 Encoder is not the 4B one Z-Image conditions on.'
+ );
+ });
+
it('builds FLUX.2 [dev] graphs with standalone components and dev LoRAs', () => {
const graph = compile(flux2DevGgufModel, {
loras: [{ isEnabled: true, model: flux2DevLora, weight: 0.75 }],
diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.ts
index 598c1dbbf0..211e6abd6f 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/graph.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.ts
@@ -37,9 +37,9 @@ import {
isFlux2Qwen3EncoderForModel,
isQwen3Vl8bEncoder,
isKrea2Qwen3VlEncoder,
- isNonAnimaQwen3Encoder,
isSelfContainedSDNQFlux1Pipeline,
isVaeCompatibleWithGenerateModel,
+ isZImageQwen3Encoder,
type GenerateComponentFilter,
} from './componentCompatibility';
import {
@@ -1100,9 +1100,7 @@ const buildZImageGraph = (
): BackendGraphContract => {
const sourceModel = getDiffusersSource(settings, model);
const qwen3EncoderModel =
- settings.qwen3EncoderModel && isNonAnimaQwen3Encoder(settings.qwen3EncoderModel)
- ? settings.qwen3EncoderModel
- : null;
+ settings.qwen3EncoderModel && isZImageQwen3Encoder(settings.qwen3EncoderModel) ? settings.qwen3EncoderModel : null;
const vaeModel = getCompatibleVae(settings, model);
if (!sourceModel && (!vaeModel || !qwen3EncoderModel)) {
diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.ts
index 8835da181c..d4a2959399 100644
--- a/invokeai/frontend/webv2/src/features/generation/settings.ts
+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts
@@ -80,9 +80,9 @@ export {
isFlux2MistralEncoder,
isFlux2Qwen3EncoderForModel,
isKrea2Qwen3VlEncoder,
- isNonAnimaQwen3Encoder,
isVaeAcceptedByBase,
isVaeCompatibleWithGenerateModel,
+ isZImageQwen3Encoder,
} from './core/componentCompatibility';
export {
isValidKrea2RebalanceWeights,
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateComponentsSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateComponentsSection.tsx
index 33caaa57d1..1450a51c07 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateComponentsSection.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateComponentsSection.tsx
@@ -97,10 +97,13 @@ const ComponentPicker = ({
const value = ctx.selectedComponents[slot.key];
const filter = useCallback((model: ModelConfig) => slot.filter?.(model, ctx) ?? false, [ctx, slot]);
const modelTypes = useMemo(() => [...slot.modelTypes], [slot.modelTypes]);
- const selectedValue = value && (!filter || filter(value as ModelConfig)) ? value.key : null;
+ const isIncompatible = Boolean(value && slot.filter && !filter(value as ModelConfig));
+ // A slot that names an incompatible selection keeps it visible, so the error has a value to point at and clear.
+ const error = isIncompatible ? slot.incompatibleMessage : undefined;
+ const selectedValue = value && (!isIncompatible || error) ? value.key : null;
return (
- <Field label={slot.label} helpText={slot.helpText}>
+ <Field label={slot.label} helpText={slot.helpText} error={error}>
<ModelSelect
filter={slot.filter ? filter : undefined}
isClearable
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx
index 225add4359..4c83f094b9 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx
@@ -107,7 +107,7 @@ const ANIMA_SKETCH_ADAPTER = {
* The picker, reduced to buttons that hand a model to its real selection handler: the model card's main picks, and
* for a component slot the catalog models of its types that pass its filter.
*/
-const MainModelPicker = ({ filter, modelTypes, onChange }: GenerationModelSelectProps) =>
+const MainModelPicker = ({ filter, modelTypes, onChange, value }: GenerationModelSelectProps) =>
modelTypes.includes('external_image_generator') ? (
[OTHER_SDXL, FLUX].map((model) => (
<button key={model.key} data-model-pick={model.key} type="button" onClick={() => onChange(model)}>
@@ -115,7 +115,7 @@ const MainModelPicker = ({ filter, modelTypes, onChange }: GenerationModelSelect
</button>
))
) : (
- <div data-component-types={modelTypes.join(',')}>
+ <div data-component-types={modelTypes.join(',')} data-component-value={value ?? ''}>
{stableGroups.models.catalog
.filter((model) => modelTypes.includes(model.type) && (filter?.(model) ?? true))
.map((model) => (
@@ -340,6 +340,45 @@ describe('GenerateSettingsForm Anima inpaint adapter', () => {
});
});
+describe('GenerateSettingsForm Z-Image Qwen3 encoder', () => {
+ const Z_IMAGE = { ...MODEL, base: 'z-image', format: 'gguf_quantized', key: 'z-image', name: 'Z-Image' };
+ const encoder = (variant: string) =>
+ ({ base: 'any', key: `qwen3-${variant}`, name: `Qwen3 ${variant}`, type: 'qwen3_encoder', variant }) as const;
+ const QWEN3_4B = encoder('qwen3_4b');
+ const QWEN3_8B = encoder('qwen3_8b');
+ const encoderSlot = () => host!.querySelector<HTMLElement>('[data-component-types="qwen3_encoder"]');
+ const encoderError = () => encoderSlot()?.closest('[data-scope="field"]')?.querySelector('[role="alert"]');
+
+ it('keeps a saved 8B encoder visible with its reason until a 4B one replaces it', async () => {
+ stableGroups.models.catalog = [MODEL, Z_IMAGE, QWEN3_4B, QWEN3_8B] as GenerationModelCatalogItem[];
+ await renderAdapter(buildAdapter());
+ await settle(() =>
+ storedValues().patchSnapshot({
+ ...getDefaultGenerateSettings(Z_IMAGE as never),
+ modelKey: Z_IMAGE.key,
+ qwen3EncoderModel: QWEN3_8B,
+ })
+ );
+
+ expect(encoderSlot()?.getAttribute('data-component-value')).toBe(QWEN3_8B.key);
+ expect(encoderError()?.textContent).toBe(
+ 'The selected Qwen3 Encoder is not the 4B one Z-Image conditions on. Select a Qwen3 4B Encoder or clear it.'
+ );
+ expect(
+ [...(encoderSlot()?.querySelectorAll('[data-component-pick]') ?? [])].map((pick) =>
+ pick.getAttribute('data-component-pick')
+ )
+ ).toEqual([QWEN3_4B.key]);
+
+ await settle(() => host!.querySelector<HTMLElement>(`[data-component-pick="${QWEN3_4B.key}"]`)?.click());
+ await settle(flushGenerateDrafts);
+
+ expect(storedValues().getSnapshot()).toMatchObject({ qwen3EncoderModel: { key: QWEN3_4B.key } });
+ expect(encoderSlot()?.getAttribute('data-component-value')).toBe(QWEN3_4B.key);
+ expect(encoderError()).toBeNull();
+ });
+});
+
describe('GenerateSettingsForm render isolation', () => {
it('preserves a settled weight draft when removing another concept from an already open menu', async () => {
const first: LoraModelConfig = { base: 'sdxl', key: 'ink', name: 'Ink', type: 'lora' };
diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
index 629782ce93..59029b0d8c 100644
--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
@@ -28,6 +28,7 @@ import {
isModelIdentifierConfig,
isVaeCompatibleWithGenerateModel,
isVaeModelConfig,
+ isZImageQwen3Encoder,
MAX_NEGATIVE_PROMPT_HEIGHT_PX,
MAX_POSITIVE_PROMPT_HEIGHT_PX,
MIN_NEGATIVE_PROMPT_HEIGHT_PX,
@@ -171,12 +172,9 @@ const CLIP_EMBED_SLOT: UpscaleComponentSlot = {
field: 'clipEmbedModel',
label: 'CLIP Embed model',
};
-// Z-Image and Anima both read a `qwen3_encoder`, but not the same one. Z-Image's caption embedder is
-// 2560 wide, so it takes the 4B and nothing else: Generate's shared filter also lets FLUX.2 Klein's
-// 8B through, which fails in the denoise -- here, after the upscale has run, and it would be the
-// automatic pick wherever its name sorts first. Anima's is the 0.6B.
+// Z-Image and Anima both read a `qwen3_encoder`, but not the same one: Z-Image takes the 4B, Anima the 0.6B.
const Z_IMAGE_QWEN3_SLOT: UpscaleComponentSlot = {
- accepts: (candidate) => candidate.type === 'qwen3_encoder' && candidate.variant === 'qwen3_4b',
+ accepts: isZImageQwen3Encoder,
field: 'qwen3EncoderModel',
label: 'Qwen3 4B encoder',
};
diff --git a/tests/app/invocations/test_z_image_model_loader.py b/tests/app/invocations/test_z_image_model_loader.py
index 41fc3f2ace..18ba774d79 100644
--- a/tests/app/invocations/test_z_image_model_loader.py
+++ b/tests/app/invocations/test_z_image_model_loader.py
@@ -6,6 +6,7 @@ source. In that case the loader must fall back to the main model itself for the
encoder/tokenizer submodels.
"""
+import re
from types import SimpleNamespace
from unittest.mock import MagicMock
@@ -13,7 +14,13 @@ import pytest
from invokeai.app.invocations.model import ModelIdentifierField
from invokeai.app.invocations.z_image.z_image_model_loader import ZImageModelLoaderInvocation
-from invokeai.backend.model_manager.taxonomy import BaseModelType, ModelFormat, ModelType, SubModelType
+from invokeai.backend.model_manager.taxonomy import (
+ BaseModelType,
+ ModelFormat,
+ ModelType,
+ Qwen3VariantType,
+ SubModelType,
+)
def _make_main_model() -> ModelIdentifierField:
@@ -111,6 +118,59 @@ class TestZImageSelfContainedSDNQ:
invocation.invoke(context)
+class TestStandaloneQwen3EncoderVariant:
+ """Every Qwen3 size installs as one model type, but Z-Image's caption embedder only takes the 4B
+ width. A workflow can wire any of them, so the loader refuses the others by name."""
+
+ @staticmethod
+ def _invoke(encoder_config: SimpleNamespace):
+ encoder = ModelIdentifierField(
+ key="encoder",
+ hash="h-encoder",
+ name=encoder_config.name,
+ base=BaseModelType.Any,
+ type=ModelType.Qwen3Encoder,
+ )
+ vae = ModelIdentifierField(
+ key="vae", hash="h-vae", name="FLUX VAE", base=BaseModelType.Flux, type=ModelType.VAE
+ )
+ configs = {
+ "z-image-sdnq-key": SimpleNamespace(format=ModelFormat.GGUFQuantized, submodels=None, name="Z-Image GGUF"),
+ "encoder": encoder_config,
+ }
+ context = MagicMock()
+ context.models.get_config.side_effect = lambda identifier: configs[identifier.key]
+ invocation = ZImageModelLoaderInvocation(model=_make_main_model(), vae_model=vae, qwen3_encoder_model=encoder)
+ return invocation.invoke(context)
+
+ def test_qwen3_4b_encoder_is_passed_through(self):
+ output = self._invoke(
+ SimpleNamespace(type=ModelType.Qwen3Encoder, variant=Qwen3VariantType.Qwen3_4B, name="Qwen3 4B")
+ )
+
+ assert output.qwen3_encoder.text_encoder.key == "encoder"
+ assert output.qwen3_encoder.text_encoder.submodel_type is SubModelType.TextEncoder
+ assert output.qwen3_encoder.tokenizer.key == "encoder"
+
+ @pytest.mark.parametrize("variant", [Qwen3VariantType.Qwen3_8B, Qwen3VariantType.Qwen3_06B])
+ def test_other_qwen3_sizes_are_refused_by_name(self, variant: Qwen3VariantType):
+ config = SimpleNamespace(type=ModelType.Qwen3Encoder, variant=variant, name="Picked Encoder")
+ expected = (
+ f"'Picked Encoder' is a Qwen3 encoder of variant '{variant.value}'. Z-Image conditions on the Qwen3 4B "
+ "encoder (hidden size 2560): select a Qwen3 4B encoder, or clear it and set 'Qwen3 Source' to a "
+ "Z-Image pipeline."
+ )
+
+ with pytest.raises(ValueError, match=re.escape(expected)):
+ self._invoke(config)
+
+ def test_a_non_qwen3_model_in_the_encoder_slot_is_refused(self):
+ config = SimpleNamespace(type=ModelType.Qwen3VLEncoder, variant="qwen3_vl_4b", name="Qwen3-VL 4B")
+
+ with pytest.raises(ValueError, match=re.escape("'Qwen3-VL 4B' is not a Qwen3 encoder. Z-Image conditions")):
+ self._invoke(config)
+
+
class TestQwen3SourceFieldTemplate:
"""The generic node/workflow model pickers filter candidates by the field template's
ui_model_base / ui_model_type / ui_model_format hints. Since _validate_diffusers_format now