Z-Image README

The project's README from github.com/Tongyi-MAI/Z-Image. As one markdown file: README.md.

⚡️- Image
An Efficient Image Generation Foundation Model with Single-Stream Diffusion Transformer

Official Site  Hugging Face  Hugging Face  Hugging Face  Hugging Face  ModelScope Model  ModelScope Model  ModelScope Space  ModelScope Space  Art Gallery PDF  Web Art Gallery 

Welcome to the official repository for the Z-Image(造相)project!

✨ Z-Image

Z-Image is a powerful and highly efficient image generation model family with 6B parameters. Currently there are four variants:

📣 News

📥 Model Zoo

Model Pre-Training SFT RL Step CFG Task Visual Quality Diversity Fine-Tunability Hugging Face ModelScope
Z-Image-Omni-Base ✅ ❌ ❌ 50 ✅ Gen. / Editing Medium High Easy To be released To be released
Z-Image ✅ ✅ ❌ 50 ✅ Gen. High Medium Easy Hugging Face
Hugging Face Space
ModelScope Model
ModelScope Space
Z-Image-Turbo ✅ ✅ ✅ 8 ❌ Gen. Very High Low N/A Hugging Face
Hugging Face Space
ModelScope Model
ModelScope Space
Z-Image-Edit ✅ ✅ ❌ 50 ✅ Editing High Medium Easy To be released To be released

The figure below illustrates at which training stage each model is produced.

Training Pipeline of Z-Image

🖼️ Showcase

📸 Photorealistic Quality: Z-Image-Turbo delivers strong photorealistic image generation while maintaining excellent aesthetic quality.

Showcase of Z-Image on Photo-realistic image Generation

📖 Accurate Bilingual Text Rendering: Z-Image-Turbo excels at accurately rendering complex Chinese and English text.

Showcase of Z-Image on Bilingual Text Rendering

💡 Prompt Enhancing & Reasoning: Prompt Enhancer empowers the model with reasoning capabilities, enabling it to transcend surface-level descriptions and tap into underlying world knowledge.

reasoning.jpg

🧠 Creative Image Editing: Z-Image-Edit shows a strong understanding of bilingual editing instructions, enabling imaginative and flexible image transformations.

Showcase of Z-Image-Edit on Image Editing

🏗️ Model Architecture

We adopt a Scalable Single-Stream DiT (S3-DiT) architecture. In this setup, text, visual semantic tokens, and image VAE tokens are concatenated at the sequence level to serve as a unified input stream, maximizing parameter efficiency compared to dual-stream approaches.

Architecture of Z-Image and Z-Image-Edit

📈 Performance

Z-Image-Turbo's performance has been validated on multiple independent benchmarks, where it consistently demonstrates state-of-the-art results, especially as the leading open-source model.

Artificial Analysis Text-to-Image Leaderboard

On the highly competitive Artificial Analysis Leaderboard, Z-Image-Turbo ranked 8th overall and secured the top position as the 🥇 #1 Open-Source Model, outperforming all other open-source alternatives.

Z-Image Rank on Artificial Analysis Leaderboard
Artificial Analysis Leaderboard

Z-Image Rank on Artificial Analysis Leaderboard (Open-Source Model Only)
Artificial Analysis Leaderboard (Open-Source Model Only)

Alibaba AI Arena Text-to-Image Leaderboard

According to the Elo-based Human Preference Evaluation on Alibaba AI Arena, Z-Image-Turbo also achieves state-of-the-art results among open-source models and shows highly competitive performance against leading proprietary models.

Z-Image Elo Rating on AI Arena
Alibaba AI Arena Text-to-Image Leaderboard

🚀 Quick Start

(1) PyTorch Native Inference

Build a virtual environment you like and then install the dependencies:

pip install -e .

Then run the following code to generate an image:

python inference.py

(2) Diffusers Inference

Install the latest version of diffusers, use the following command:

Click here for details for why you need to install diffusers from source

We have submitted two pull requests (#12703 and #12715) to the 🤗 diffusers repository to add support for Z-Image. Both PRs have been merged into the latest official diffusers release. Therefore, you need to install diffusers from source for the latest features and Z-Image support.

pip install git+https://github.com/huggingface/diffusers
Z-Image-Turbo - Click to expand

Then, try the following code to generate an image:

import torch
from diffusers import ZImagePipeline

# 1. Load the pipeline
# Use bfloat16 for optimal performance on supported GPUs
pipe = ZImagePipeline.from_pretrained(
    "Tongyi-MAI/Z-Image-Turbo",
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=False,
)
pipe.to("cuda")

# [Optional] Attention Backend
# Diffusers uses SDPA by default. Switch to Flash Attention for better efficiency if supported:
# pipe.transformer.set_attention_backend("flash")    # Enable Flash-Attention-2
# pipe.transformer.set_attention_backend("_flash_3") # Enable Flash-Attention-3

# [Optional] Model Compilation
# Compiling the DiT model accelerates inference, but the first run will take longer to compile.
# pipe.transformer.compile()

# [Optional] CPU Offloading
# Enable CPU offloading for memory-constrained devices.
# pipe.enable_model_cpu_offload()

prompt = "Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp (⚡️), bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda (西安大雁塔), blurred colorful distant lights."

# 2. Generate Image
image = pipe(
    prompt=prompt,
    height=1024,
    width=1024,
    num_inference_steps=9,  # This actually results in 8 DiT forwards
    guidance_scale=0.0,     # Guidance should be 0 for the Turbo models
    generator=torch.Generator("cuda").manual_seed(42),
).images[0]

image.save("example.png")
Z-Image - Click to expand

Recommended Parameters:

  • Resolution: 512×512 to 2048×2048 (total pixel area, any aspect ratio)
  • Guidance scale: 3.0 – 5.0
  • Inference steps: 28 – 50
  • Negative prompts: Strongly recommended for better control
  • CFG normalization: False for general stylism, True for realism

Then, try the following code to generate an image:

import torch
from diffusers import ZImagePipeline

# Load the pipeline
pipe = ZImagePipeline.from_pretrained(
    "Tongyi-MAI/Z-Image",
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=False,
)
pipe.to("cuda")

# Generate image
prompt = "两名年轻亚裔女性紧密站在一起,背景为朴素的灰色纹理墙面,可能是室内地毯地面。左侧女性留着长卷发,身穿藏青色毛衣,左袖有奶油色褶皱装饰,内搭白色立领衬衫,下身白色裤子;佩戴小巧金色耳钉,双臂交叉于背后。右侧女性留直肩长发,身穿奶油色卫衣,胸前印有"Tun the tables"字样,下方为"New ideas",搭配白色裤子;佩戴银色小环耳环,双臂交叉于胸前。两人均面带微笑直视镜头。照片,自然光照明,柔和阴影,以藏青、奶油白为主的中性色调,休闲时尚摄影,中等景深,面部和上半身对焦清晰,姿态放松,表情友好,室内环境,地毯地面,纯色背景。"
negative_prompt = "" # Optional, but would be powerful when you want to remove some unwanted content

image = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    height=1280,
    width=720,
    cfg_normalization=False,
    num_inference_steps=50,
    guidance_scale=4,
    generator=torch.Generator("cuda").manual_seed(42),
).images[0]

image.save("example.png")

🔬 Decoupled-DMD: The Acceleration Magic Behind Z-Image

arXiv

Decoupled-DMD is the core few-step distillation algorithm that empowers the 8-step Z-Image model.

Our core insight in Decoupled-DMD is that the success of existing DMD (Distribution Matching Distillation) methods is the result of two independent, collaborating mechanisms:

By recognizing and decoupling these two mechanisms, we were able to study and optimize them in isolation. This ultimately motivated us to develop an improved distillation process that significantly enhances the performance of few-step generation.

Diagram of Decoupled-DMD

🤖 DMDR: Fusing DMD with Reinforcement Learning

arXiv

Building upon the strong foundation of Decoupled-DMD, our 8-step Z-Image model has already demonstrated exceptional capabilities. To achieve further improvements in terms of semantic alignment, aesthetic quality, and structural coherence—while producing images with richer high-frequency details—we present DMDR.

Our core insight behind DMDR is that Reinforcement Learning (RL) and Distribution Matching Distillation (DMD) can be synergistically integrated during the post-training of few-step models. We demonstrate that:

Diagram of DMDR

🎉 Community Works

Z-Image (Tongyi-MAI/Z-Image)

bilingual
Searching Database…

12.1K ·GitHub
What is this?Z-Image is a family of efficient image generation models with 6B parameters, built around a single-stream diffusion transformer architecture, developed by Alibaba's Tongyi team.
Is this a single model or a family of variants?It's a family of four checkpoints: Z-Image-Turbo (fast distilled version), Z-Image (base foundation model), Z-Image-Omni-Base (generation plus editing), and Z-Image-Edit (dedicated image editing).
How do I run it to generate an image?You can run native PyTorch inference after building a virtual environment and installing the dependencies, or use the Hugging Face Diffusers library instead.
Do I need the Diffusers library or can I use plain PyTorch?Either works: there's a native PyTorch inference path, or you can use Diffusers, though currently you must install Diffusers from source since the Z-Image support is only merged into the latest release.
Are all four model checkpoints available right now?No — Z-Image and Z-Image-Turbo are released on Hugging Face and ModelScope, but Z-Image-Omni-Base and Z-Image-Edit checkpoints are still marked as 'to be released'.
How much VRAM do I need to run Z-Image-Turbo?Z-Image-Turbo fits comfortably within 16GB VRAM on consumer devices and gives sub-second latency on H800 GPUs; community projects like stable-diffusion.cpp can even run it with as little as 4GB of VRAM.
What makes Decoupled-DMD special?It splits few-step distillation into two separable mechanisms — CFG Augmentation, which drives the distillation, and Distribution Matching, which regularizes quality — letting the team tune each independently for better 8-step generation.
Can Z-Image generate accurate Chinese and English text in images?Yes, bilingual text rendering is a highlighted strength: the model is specifically noted for accurately rendering complex Chinese and English text.
What does Z-Image-Edit add over the base model?It's fine-tuned specifically for editing tasks, letting you make precise, instruction-following edits to an existing image from a natural-language prompt.
Has Z-Image been benchmarked against other models?Yes — Z-Image-Turbo ranked 8th overall on the Artificial Analysis Text-to-Image Leaderboard and is ranked the #1 open-source model there.
Creator
Tongyi-MAI
Size
56.1 MB
Stars
12.1K
Updated
CommitFeb 09
Age
10mo
Commits · 90 Days