`ZImageImg2ImgPipeline` / `ZImageInpaintPipeline`: explicit height/width different from the input image raises RuntimeError

未關閉 適合新手
#15,337 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@chessing234 已經在處理了。

開始於 2026年11月20日。

  • #15353 來自 @chessing234 —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
70/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python, pytorch

研究方向

閱讀 src/diffusers/pipelines/z_image/pipeline_z_image_img2img.py 中第 489 行附近的初始影像前處理程式碼,以及第 673 行附近對應的修補程式碼。比較 SD3、Flux、QwenImage 和 Chroma 如何將尺寸傳給 image_processor.preprocess;使用輸入影像和不同的 height/width 值重現問題。當兩個 pipeline 都能接受所要求的輸出尺寸且沒有尺寸不符時,即為完成。

由索引模型根據 Issue 內容生成。

描述

bug
Describe the bug

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
import torch
from PIL import Image
from diffusers import ZImageImg2ImgPipeline

pipe = 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
System Info
  • 🤗 Diffusers version: 0.44.0.dev0
  • Platform: Linux-7.0.0-38-generic-x86_64-with-glibc2.39
  • Running on Google Colab?: No
  • Python version: 3.12.3
  • PyTorch version (GPU?): 2.16.0a0+rocm10.3.0a20261117 (True)
  • Huggingface_hub version: 2.4.0
  • Transformers version: 5.23.0
  • Accelerate version: 1.16.0
  • PEFT version: not installed
  • Safetensors version: 0.8.0
  • xFormers version: not installed
  • Accelerator: NA
  • Using GPU in script?: Yes (AMD Radeon AI PRO R9700)
  • Using distributed or parallel set-up in script?: No

diffusers main @ e84bda1

Who can help?

@yiyixuxu @sayakpaul

主要語言
Python
星號
34.9k
分支
7.5k
平均合併
3 天 16 小時
30 天內合併 PR
65

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

huggingface/diffusers 的其他 Issue

查看 huggingface/diffusers 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。