Repository navigation
[Z-Image] Resize the init image to height/width in img2img and inpaint - #15452
Open
menglcai-amd wants to merge 1 commit into
Open
menglcai-amd wants to merge 1 commit into
menglcai-amd wants to merge 1 commit into
Conversation
Signed-off-by: menglcai <menglcai@amd.com>
menglcai-amd
marked this pull request as ready for review
December 1, 2026 17:37
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #15337
This PR has two changes:
Fix 1. Resize the init image to
height/widthinZImageImg2ImgPipelineandZImageInpaintPipeline.Fix 2. Keep 16-channel latents passed as
imageworking in img2img after Fix 1.New tests:
test_height_width_differ_from_image(img2img and inpaint): covers Fix 1. Fails onmainwith the error from the issue, passes with this PR.test_latent_image_with_height_width(img2img): covers Fix 2. Passes onmain, fails with Fix 1 alone, passes with this PR.Testing
Real model:
Tongyi-MAI/Z-Image-Turbo, bf16, 8 steps, strength 0.5, on an AMD MI250 (ROCm). 512x512 input image.mainheight/width= 768x512RuntimeErrorheight/width= 256x384RuntimeErrorheight/width= 768x512RuntimeErrorheight/width= 256x384RuntimeErrorimage+height/width= 512x512mainheight/width; img2img withheight/widthequal to the image; 2 images + 2 promptsmain(*)(*) 3 of these outputs are bit-identical to
main. The other 2 differ by at most 0.0078; running the same code twice on this GPU differs by up to 0.0176, so this is run-to-run variation, not the change.Unit tests:
tests/pipelines/z_image/mainmain+ new teststest_height_width_differ_from_imagefailed, latent test passedtest_height_width_differ_from_image), 113 passed, 43 skippedMore input cases (tiny test components, CPU)
Compared
main, Fix 1 alone, and this PR, using the components from the Z-Image tests (32x32 input).mainheight/width!= image (img2img and inpaint)RuntimeErrorheight/widthsetRuntimeErrorRuntimeErrorlatents+height/widthRuntimeErrorlatents+height/widthimage+height/widthRuntimeErrorheight/widthheight/widthnot a multiple of the required sizeValueErrorValueErrorValueErrorimagewithoutheight/width; latent asimagein inpaintSelf-review notes
Final round on the full diff. Verdict: READY, no blocking issues, no dead code.
ruff check,ruff format --checkandutils/check_copies.pypass. Test results are in the Testing section above.Left for the reviewer:
latent_channelsis a local in__init__(as in SD3 img2img), notself.latent_channels(as in Flux / QwenImage img2img). Happy to switch if you prefer the attribute.height/widthdocstrings say "defaults to 1024", but the input image size is used when they are not passed, and theimagedocstring doesn't mention that a latent can be passed. Both predate this PR; happy to fix them here if you prefer.imageanyway.Possible addition to
.ai/references/pipelines.md: an img2img pipeline that passesheight/widthtoimage_processor.preprocessand accepts latents asimageshould build itsVaeImageProcessorwithvae_latent_channels, otherwise those latents get resized like images.Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@yiyixuxu @sayakpaul