Skip to content

Commit 2246d2c

Browse files
CalamitousFelicitousnessyiyixuxuasomoza
authored
Add ZImageImg2ImgPipeline (#12751)
* Add ZImageImg2ImgPipeline Updated the pipeline structure to include ZImageImg2ImgPipeline alongside ZImagePipeline. Implemented the ZImageImg2ImgPipeline class for image-to-image transformations, including necessary methods for encoding prompts, preparing latents, and denoising. Enhanced the auto_pipeline to map the new ZImageImg2ImgPipeline for image generation tasks. Added unit tests for ZImageImg2ImgPipeline to ensure functionality and performance. Updated dummy objects to include ZImageImg2ImgPipeline for testing purposes. * Address review comments for ZImageImg2ImgPipeline - Add `# Copied from` annotations to encode_prompt and _encode_prompt - Add ZImagePipeline to auto_pipeline.py for AutoPipeline support * Add ZImage pipeline documentation --------- Co-authored-by: YiYi Xu <[email protected]> Co-authored-by: Álvaro Somoza <[email protected]>
1 parent 671149e commit 2246d2c

File tree

9 files changed

+1126
-4
lines changed

9 files changed

+1126
-4
lines changed

docs/source/en/_toctree.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@
651651
- local: api/pipelines/wuerstchen
652652
title: Wuerstchen
653653
- local: api/pipelines/z_image
654-
title: Z-Image
654+
title: Z-Image
655655
title: Image
656656
- sections:
657657
- local: api/pipelines/allegro

docs/source/en/api/pipelines/z_image.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,41 @@ specific language governing permissions and limitations under the License.
2626

2727
Z-Image-Turbo is a distilled version of Z-Image that matches or exceeds leading competitors with only 8 NFEs (Number of Function Evaluations). It offers sub-second inference latency on enterprise-grade H800 GPUs and fits comfortably within 16G VRAM consumer devices. It excels in photorealistic image generation, bilingual text rendering (English & Chinese), and robust instruction adherence.
2828

29+
## Image-to-image
30+
31+
Use [`ZImageImg2ImgPipeline`] to transform an existing image based on a text prompt.
32+
33+
```python
34+
import torch
35+
from diffusers import ZImageImg2ImgPipeline
36+
from diffusers.utils import load_image
37+
38+
pipe = ZImageImg2ImgPipeline.from_pretrained("Tongyi-MAI/Z-Image-Turbo", torch_dtype=torch.bfloat16)
39+
pipe.to("cuda")
40+
41+
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
42+
init_image = load_image(url).resize((1024, 1024))
43+
44+
prompt = "A fantasy landscape with mountains and a river, detailed, vibrant colors"
45+
image = pipe(
46+
prompt,
47+
image=init_image,
48+
strength=0.6,
49+
num_inference_steps=9,
50+
guidance_scale=0.0,
51+
generator=torch.Generator("cuda").manual_seed(42),
52+
).images[0]
53+
image.save("zimage_img2img.png")
54+
```
55+
2956
## ZImagePipeline
3057

3158
[[autodoc]] ZImagePipeline
3259
- all
33-
- __call__
60+
- __call__
61+
62+
## ZImageImg2ImgPipeline
63+
64+
[[autodoc]] ZImageImg2ImgPipeline
65+
- all
66+
- __call__

src/diffusers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@
662662
"WuerstchenCombinedPipeline",
663663
"WuerstchenDecoderPipeline",
664664
"WuerstchenPriorPipeline",
665+
"ZImageImg2ImgPipeline",
665666
"ZImagePipeline",
666667
]
667668
)
@@ -1360,6 +1361,7 @@
13601361
WuerstchenCombinedPipeline,
13611362
WuerstchenDecoderPipeline,
13621363
WuerstchenPriorPipeline,
1364+
ZImageImg2ImgPipeline,
13631365
ZImagePipeline,
13641366
)
13651367

src/diffusers/pipelines/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404
"Kandinsky5T2IPipeline",
405405
"Kandinsky5I2IPipeline",
406406
]
407-
_import_structure["z_image"] = ["ZImagePipeline"]
407+
_import_structure["z_image"] = ["ZImageImg2ImgPipeline", "ZImagePipeline"]
408408
_import_structure["skyreels_v2"] = [
409409
"SkyReelsV2DiffusionForcingPipeline",
410410
"SkyReelsV2DiffusionForcingImageToVideoPipeline",
@@ -841,7 +841,7 @@
841841
WuerstchenDecoderPipeline,
842842
WuerstchenPriorPipeline,
843843
)
844-
from .z_image import ZImagePipeline
844+
from .z_image import ZImageImg2ImgPipeline, ZImagePipeline
845845

846846
try:
847847
if not is_onnx_available():

src/diffusers/pipelines/auto_pipeline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
)
120120
from .wan import WanImageToVideoPipeline, WanPipeline, WanVideoToVideoPipeline
121121
from .wuerstchen import WuerstchenCombinedPipeline, WuerstchenDecoderPipeline
122+
from .z_image import ZImageImg2ImgPipeline, ZImagePipeline
122123

123124

124125
AUTO_TEXT2IMAGE_PIPELINES_MAPPING = OrderedDict(
@@ -162,6 +163,7 @@
162163
("cogview4-control", CogView4ControlPipeline),
163164
("qwenimage", QwenImagePipeline),
164165
("qwenimage-controlnet", QwenImageControlNetPipeline),
166+
("z-image", ZImagePipeline),
165167
]
166168
)
167169

@@ -189,6 +191,7 @@
189191
("qwenimage", QwenImageImg2ImgPipeline),
190192
("qwenimage-edit", QwenImageEditPipeline),
191193
("qwenimage-edit-plus", QwenImageEditPlusPipeline),
194+
("z-image", ZImageImg2ImgPipeline),
192195
]
193196
)
194197

src/diffusers/pipelines/z_image/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
else:
2424
_import_structure["pipeline_output"] = ["ZImagePipelineOutput"]
2525
_import_structure["pipeline_z_image"] = ["ZImagePipeline"]
26+
_import_structure["pipeline_z_image_img2img"] = ["ZImageImg2ImgPipeline"]
2627

2728

2829
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
@@ -35,6 +36,7 @@
3536
else:
3637
from .pipeline_output import ZImagePipelineOutput
3738
from .pipeline_z_image import ZImagePipeline
39+
from .pipeline_z_image_img2img import ZImageImg2ImgPipeline
3840

3941
else:
4042
import sys

0 commit comments

Comments
 (0)