You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ZImageImg2ImgPipeline / ZImageInpaintPipeline: explicit height/width different from the input image raises RuntimeError #15337
In ZImageImg2ImgPipeline and ZImageInpaintPipeline, passing height/width that differ from the input image size raises a size-mismatch RuntimeError, although the docstring says they set the output size. The init image is preprocessed without them (img2img L489, inpaint L673), so it is never resized and keeps its original size, while the noise shape uses height/width. Other pipelines that take height/width (SD3, Flux, QwenImage, Chroma) pass them to image_processor.preprocess, which resizes the image first. In the inpaint pipeline the mask is already resized this way, only the image is not.
Also, passing more images than prompts (e.g. two images with one prompt string) fails with a bare AssertionError in the transformer; a clear ValueError might help.
I'm not sure whether this is intended behavior of the pipeline or an actual bug. If it is a bug, I'd be happy to open a PR that passes height/width to preprocess (and adds the ValueError above, if wanted). Would that be appropriate?
Reproduction
importtorchfromPILimportImagefromdiffusersimportZImageImg2ImgPipelinepipe=ZImageImg2ImgPipeline.from_pretrained(
"Tongyi-MAI/Z-Image-Turbo", torch_dtype=torch.bfloat16
).to("cuda")
img=Image.new("RGB", (256, 256))
# Works without height/width (output 256x256).# With height/width != image size it raises:# RuntimeError: The size of tensor a (16) must match the size of tensor b (32)pipe("a cat", image=img, height=128, width=128,
num_inference_steps=4, strength=0.6, guidance_scale=0.0)
Context
I'm building an app that runs image-to-image and inpainting on user images of various sizes, with a target output size chosen by the user. SD3 / SD3 Inpaint and Flux Img2Img / Inpaint work fine with explicit height/width, but Z-Image Img2Img / Inpaint raise the error above.
Logs
File ".../pipeline_z_image_img2img.py", line 345, in prepare_latents
latents = self.scheduler.scale_noise(image_latents, timestep, noise)
File ".../scheduling_flow_match_euler_discrete.py", line 234, in scale_noise
sample = sigma * noise + (1.0 - sigma) * sample
RuntimeError: The size of tensor a (16) must match the size of tensor b (32) at non-singleton dimension 3
Checked the code and the diagnosis looks right. In pipeline_z_image_img2img.py the init image is preprocessed at line 489 without height or width, and the same in the inpaint pipeline at line 673, while the noise shape is built from the height and width you passed. The mask in the inpaint pipeline does get resized with them at line 695, so the image path looks like an oversight rather than intended behavior. The reporter already offered to open a PR for this, so I will leave the fix to them unless the maintainers would rather someone else pick it up. Is this a bug from your side?
Thanks for taking a look! We ran into this while putting together an app demo where users can choose the output size. I'll send a fix once a maintainer confirms it's actually a bug.
Activity
SIDDARTHAREDDY8 commentedon Nov 19, 2026
Checked the code and the diagnosis looks right. In pipeline_z_image_img2img.py the init image is preprocessed at line 489 without height or width, and the same in the inpaint pipeline at line 673, while the noise shape is built from the height and width you passed. The mask in the inpaint pipeline does get resized with them at line 695, so the image path looks like an oversight rather than intended behavior. The reporter already offered to open a PR for this, so I will leave the fix to them unless the maintainers would rather someone else pick it up. Is this a bug from your side?
menglcai commentedon Nov 19, 2026
Thanks for taking a look! We ran into this while putting together an app demo where users can choose the output size. I'll send a fix once a maintainer confirms it's actually a bug.