Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

warn instead of failing every Qwen 2.1 load when the pipeline lacks the private encode hook

[._.]/ Adam Eivyc311d41aee15
diff --git a/scripts/z_image_turbo.py b/scripts/z_image_turbo.py
index 9aa1af640f..51d7a5bc11 100644
--- a/scripts/z_image_turbo.py
+++ b/scripts/z_image_turbo.py
@@ -195,7 +195,12 @@ def encode_references_in_vae_dtype(pipe):
"""Qwen 2.1 reference images reach the VAE encoder in the transformer's bfloat16,
which the float32 MPS VAE rejects ("Input type (BFloat16) and bias type (float)").
Encode in the VAE's dtype and hand the latents back in the caller's dtype."""
- encode_vae_image = pipe._encode_vae_image
+ encode_vae_image = getattr(pipe, "_encode_vae_image", None)
+ if encode_vae_image is None:
+ # A diffusers release without this private hook: generations without references
+ # still work, so warn instead of failing every Qwen 2.1 load.
+ print("⚠️ qwen-image-2.1 pipeline has no _encode_vae_image; reference images may fail on MPS", file=sys.stderr)
+ return
def encode_in_vae_dtype(image, generator):
return encode_vae_image(image.to(dtype=pipe.vae.dtype), generator).to(dtype=image.dtype)
diff --git a/scripts/z_image_turbo_test.py b/scripts/z_image_turbo_test.py
index 4ee42ee669..f53b77f9bf 100644
--- a/scripts/z_image_turbo_test.py
+++ b/scripts/z_image_turbo_test.py
@@ -126,6 +126,16 @@ class RunnerContract(unittest.TestCase):
self.assertEqual(seen, ['fp32'])
self.assertEqual(latents.dtype, 'bf16')
+ def test_qwen21_reference_wrapper_skips_a_pipeline_without_the_hook(self):
+ with patch.dict(sys.modules, {'torch': SimpleNamespace()}):
+ runner = importlib.import_module('z_image_turbo')
+ pipe = SimpleNamespace(vae=SimpleNamespace(dtype='fp32'))
+ stderr = io.StringIO()
+ with contextlib.redirect_stderr(stderr):
+ runner.encode_references_in_vae_dtype(pipe)
+ self.assertFalse(hasattr(pipe, '_encode_vae_image'))
+ self.assertIn('no _encode_vae_image', stderr.getvalue())
+
def test_qwen21_decode_guard_accepts_finite_output_and_retries_once(self):
torch = SimpleNamespace(
float32='fp32',