Text-to-Image
Diffusers
OpenVINO
ZImagePipeline
int4
optimum
optimum-intel
nncf
z-image
transformer
cpu
Instructions to use HelloSun/Z-Image-Turbo-OpenVINO-INT4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use HelloSun/Z-Image-Turbo-OpenVINO-INT4 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("HelloSun/Z-Image-Turbo-OpenVINO-INT4", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Add inference_int4.py
Browse files- inference_int4.py +28 -0
inference_int4.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Z-Image-Turbo OpenVINO INT4 inference example (optimum-intel).
|
| 2 |
+
Requires: diffusers==0.37.1, transformers==4.57.6, optimum-intel, openvino, nncf
|
| 3 |
+
Export: optimum-cli export openvino -m Tongyi-MAI/Z-Image-Turbo --task text-to-image --weight-format fp16 ./fp16
|
| 4 |
+
Quantize: see quantize_int4.py (OVWeightQuantizationConfig bits=4, group 128, fallback adjust)
|
| 5 |
+
"""
|
| 6 |
+
import time
|
| 7 |
+
import torch
|
| 8 |
+
from optimum.intel import OVDiffusionPipeline
|
| 9 |
+
|
| 10 |
+
MODEL_ID = "HelloSun/Z-Image-Turbo-OpenVINO-INT4" # or local path ./z-image-turbo-ov-int4
|
| 11 |
+
|
| 12 |
+
def main():
|
| 13 |
+
pipe = OVDiffusionPipeline.from_pretrained(MODEL_ID, compile=True)
|
| 14 |
+
|
| 15 |
+
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
| 16 |
+
# Turbo: num_inference_steps=9 => 8 DiT forwards (official README), guidance_scale=0.0
|
| 17 |
+
image = pipe(
|
| 18 |
+
prompt=prompt,
|
| 19 |
+
height=1024, width=1024,
|
| 20 |
+
num_inference_steps=9,
|
| 21 |
+
guidance_scale=0.0,
|
| 22 |
+
generator=torch.Generator().manual_seed(42),
|
| 23 |
+
).images[0]
|
| 24 |
+
image.save("z_image_turbo_ov_int4.png")
|
| 25 |
+
print("saved z_image_turbo_ov_int4.png")
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
main()
|