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

Đang mở Phù hợp với người mới
#15,337 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@chessing234 đang làm issue này rồi.

Từ ngày 20/11/2026.

  • #15353 của @chessing234 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, pytorch
Lĩnh vực
machine-learning

Hướng nghiên cứu

Đọc src/diffusers/pipelines/z_image/pipeline_z_image_img2img.py gần phần tiền xử lý ảnh khởi tạo ở dòng 489 và mã inpaint tương ứng gần dòng 673. So sánh cách SD3, Flux, QwenImage và Chroma truyền kích thước cho image_processor.preprocess; tái hiện với một ảnh đầu vào và các giá trị height/width khác nhau. Hoàn tất khi cả hai pipeline chấp nhận kích thước đầu ra được yêu cầu mà không bị lệch kích thước.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
34.9k
Fork
7.5k
Merge trung bình
3 ngày 16 giờ
Pull request đã merge (30 ngày)
65

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của huggingface/diffusers

Tất cả issue của huggingface/diffusers

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.