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(wan): require a reference image for I2V-A14B (#10319)

Lincoln Stein31e6b867f869
diff --git a/invokeai/app/invocations/wan/wan_denoise.py b/invokeai/app/invocations/wan/wan_denoise.py
index 897c9770d5..b68d8cae23 100644
--- a/invokeai/app/invocations/wan/wan_denoise.py
+++ b/invokeai/app/invocations/wan/wan_denoise.py
@@ -92,6 +92,13 @@ def _resolve_variant(context: InvocationContext, transformer_field: WanTransform
return variant
+def _validate_ref_image_present(variant: WanVariantType, ref_image: WanRefImageConditioningField | None) -> None:
+ # The I2V transformer's patch embedding takes 36 channels (16 noise + 20 reference condition);
+ # without a reference it would fail mid-denoise with a raw shape error.
+ if variant == WanVariantType.I2V_A14B and ref_image is None:
+ raise ValueError("The Wan 2.2 I2V model needs a Reference Image. Connect one, or pick a T2V or TI2V model.")
+
+
def _validate_spatial_dimensions(variant: WanVariantType, width: int, height: int) -> None:
if variant == WanVariantType.TI2V_5B and (width % 32 or height % 32):
raise ValueError(
@@ -475,6 +482,7 @@ class WanDenoiseInvocation(BaseInvocation, WithMetadata):
variant = _resolve_variant(context, self.transformer)
_validate_spatial_dimensions(variant, self.width, self.height)
+ _validate_ref_image_present(variant, self.ref_image)
spatial_scale = get_spatial_scale_factor(variant)
scheduler = self._build_scheduler(context, device)
diff --git a/invokeai/app/invocations/wan/wan_video_denoise.py b/invokeai/app/invocations/wan/wan_video_denoise.py
index 9ad068364d..3f5f5e8ce7 100644
--- a/invokeai/app/invocations/wan/wan_video_denoise.py
+++ b/invokeai/app/invocations/wan/wan_video_denoise.py
@@ -41,6 +41,7 @@ from invokeai.app.invocations.wan.wan_denoise import (
_get_wan_transformer_working_mem_bytes,
_resolve_variant,
_validate_ref_condition_shape,
+ _validate_ref_image_present,
_validate_spatial_dimensions,
)
from invokeai.app.services.shared.invocation_context import InvocationContext
@@ -210,6 +211,7 @@ class WanVideoDenoiseInvocation(BaseInvocation, WithMetadata):
variant = _resolve_variant(context, self.transformer)
_validate_spatial_dimensions(variant, self.width, self.height)
+ _validate_ref_image_present(variant, self.ref_image)
spatial_scale = get_spatial_scale_factor(variant)
# Reuse the image denoise's scheduler construction so we pick up whatever
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 7912acb134..35e61b5bbd 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
@@ -292,6 +292,15 @@ describe('architecture policy, read from the backend capability table', () => {
expect(pickFallbackGenerateModel([unconditional, gone])).toBe(gone);
expect(pickFallbackGenerateModel([unconditional])).toBeUndefined();
});
+
+ it('starts a fresh project on a model that runs without a reference frame when one is present', () => {
+ const i2v = createModel('wan', { key: 'i2v', variant: 'i2v_a14b' });
+ const t2v = createModel('wan', { key: 't2v', variant: 't2v_a14b' });
+
+ expect(pickFallbackGenerateModel([i2v, t2v])).toBe(t2v);
+ // Only I2V installed: still pick it, and its readiness issue explains why it cannot run.
+ expect(pickFallbackGenerateModel([i2v])).toBe(i2v);
+ });
});
});
@@ -1567,6 +1576,17 @@ describe('Krea-2, Ideogram 4 and Wan policies', () => {
expect(getGenerationValidationReasons(diffusers, createSettings(diffusers))).toEqual([]);
});
+
+ it('blocks the I2V expert, which needs a reference frame Generate cannot supply, and allows T2V', () => {
+ const i2v = createModel('wan', { format: 'diffusers', variant: 'i2v_a14b' });
+ const t2v = createModel('wan', { format: 'diffusers', variant: 't2v_a14b' });
+
+ expect(getGenerationValidationReasons(i2v, createSettings(i2v))).toEqual([
+ 'Wan 2.2 I2V models need a reference frame. Pick a T2V or TI2V model, or use the Video panel or the ' +
+ 'Image to Image - Wan 2.2 workflow.',
+ ]);
+ expect(getGenerationValidationReasons(t2v, createSettings(t2v))).toEqual([]);
+ });
});
describe('the guidance slider value from a model record', () => {
diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
index 4d894ce28d..33309f8012 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
@@ -505,21 +505,27 @@ export const isSupportedGenerateModel = <T extends { base: string; type: string
(model.type === 'main' && isSupportedGenerateBase(model.base)) ||
(model.type === 'external_image_generator' && model.base === 'external');
+/** Wan I2V-A14B denoises only from a reference frame, which Generate has no input for. */
+const needsReferenceFrame = (model: ModelConfig): boolean => model.base === 'wan' && model.variant === 'i2v_a14b';
+
/** Unconditional Ideogram branches stay resolvable but unselectable; Wan's other expert can span the schedule. */
export const isGenerateModelSelectable = <T extends ModelConfig>(model: T): model is T & GenerateModelConfig =>
isSupportedGenerateModel(model) && !isIdeogram4UnconditionalBranch(model);
/**
* The model a fresh project starts on, or the Generate form falls back to when none is chosen: the first one Generate
- * can select as a main model (so no standalone Ideogram 4 branch) whose files are present, else the first. Where a
- * model is stored or chosen, that one stays.
+ * can select as a main model (so no standalone Ideogram 4 branch) whose files are present, preferring one that can run
+ * without a reference frame, else the first. Where a model is stored or chosen, that one stays: an I2V model stays
+ * selectable and is blocked with a readiness issue, so a saved selection is never swapped silently.
*/
export const pickFallbackGenerateModel = <T extends ModelConfig>(
models: readonly T[]
): (T & GenerateModelConfig) | undefined => {
const selectable = models.filter(isGenerateModelSelectable);
- return selectable.find((model) => !model.is_missing) ?? selectable[0];
+ const present = selectable.filter((model) => !model.is_missing);
+
+ return present.find((model) => !needsReferenceFrame(model)) ?? present[0] ?? selectable[0];
};
export const getPromptHistoryRecallPatch = ({
@@ -3389,6 +3395,17 @@ const getModelFamilyValidationIssues = (model: MainModelConfig, settings: Genera
);
}
+ // The I2V-A14B transformer needs a reference-frame condition, which the Generate graph has no input for.
+ if (needsReferenceFrame(model)) {
+ issues.push(
+ createUntranslatedGenerationIssue(
+ 'Wan 2.2 I2V models need a reference frame. Pick a T2V or TI2V model, or use the Video panel or the ' +
+ 'Image to Image - Wan 2.2 workflow.',
+ MODEL_TARGET
+ )
+ );
+ }
+
// A persisted list can name a block MOSS-Image lacks; without CFG it has no effect and its field cannot be fixed.
if (
model.base === 'moss-image' &&
diff --git a/tests/app/invocations/test_wan_denoise.py b/tests/app/invocations/test_wan_denoise.py
index 8d56852440..6d7ae7f33b 100644
--- a/tests/app/invocations/test_wan_denoise.py
+++ b/tests/app/invocations/test_wan_denoise.py
@@ -880,18 +880,21 @@ class TestWanDenoiseRefImage:
for h_shape, *_ in transformer.calls:
assert h_shape == (1, 36, 1, 8, 8), f"expected 36-channel input, got {h_shape}"
- def test_no_ref_image_keeps_16_channels(self, fake_model_root: Path) -> None:
- """Without ref_image → transformer sees [B, 16, T, H/8, W/8] as before."""
+ @pytest.mark.parametrize("node", ["image", "video"])
+ def test_i2v_without_ref_image_raises_before_any_work(self, node: str, fake_model_root: Path) -> None:
+ """I2V_A14B with no ref_image must fail with an actionable message, not a 16-vs-36 channel error."""
transformer = _ZeroTransformer()
ctx = self._build_ctx_with_condition(
transformer, WanVariantType.I2V_A14B, fake_model_root, condition_tensor=None
)
- inv = self._make_inv_with_ref(ref_field=None)
- inv._run_diffusion(ctx)
+ inv = self._make_inv_with_ref(ref_field=None) if node == "image" else _make_video_invocation()
+ with pytest.raises(ValueError, match="needs a Reference Image"):
+ inv._run_diffusion(ctx)
- for h_shape, *_ in transformer.calls:
- assert h_shape == (1, 16, 1, 8, 8), f"expected unchanged 16-channel input, got {h_shape}"
+ # The check must run before any conditioning loads; the experts load lazily much later.
+ ctx.conditioning.load.assert_not_called()
+ assert transformer.calls == []
def test_variant_gate_rejects_ref_image_on_t2v(self, fake_model_root: Path) -> None:
"""T2V_A14B + ref_image must raise — fast-fail before doing any work."""