> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sglang.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Z-Image-Turbo

> Deploy Z-Image-Turbo with SGLang - community contribution guide for Z-Image's fast image generation model.

## 1. Quick start

Follow the [SGLang Diffusion installation guide](https://docs.sglang.io/docs/sglang-diffusion/installation.md) for your GPU platform.

## 2. Model capabilities

[Z-Image-Turbo](https://huggingface.co/Tongyi-MAI/Z-Image-Turbo) is a distilled 6B single-stream DiT for fast text-to-image generation. It reaches its intended operating point in 8 function evaluations and is particularly strong at photorealistic scenes, prompt adherence, and English/Chinese text rendering.

Choose it when latency and a relatively small deployment footprint matter more than the editability or maximum capacity of larger image models. It is a generation-only checkpoint; use Qwen-Image-Edit or FLUX.2 when the request includes source images or identity-preserving edits.

## 3. Model Deployment

This section provides deployment configurations optimized for different hardware platforms and use cases.

### 3.1 Basic Configuration

Z-Image-Turbo is optimized for high-quality image generation with only 8 inference steps. The recommended launch configurations vary by hardware.

Use the [command builder](#1-quick-start) above.

### 3.2 Configuration Tips

See [Performance Optimization](https://docs.sglang.io/docs/sglang-diffusion/performance-optimization.md) for acceleration features and their runtime requirements.

* `--vae-path`: Path to a custom VAE model or HuggingFace model ID (e.g., fal/FLUX.2-Tiny-AutoEncoder). If not specified, the VAE will be loaded from the main model path.
* `--num-gpus`: Number of GPUs to use
* `--tp-size`: Tensor parallelism size (only for the encoder; should not be larger than 1 if text encoder offload is enabled, as layer-wise offload plus prefetch is faster)
* `--sp-degree`: Sequence parallelism size (typically should match the number of GPUs)
* `--ulysses-degree`: The degree of DeepSpeed-Ulysses-style SP in USP
* `--ring-degree`: The degree of ring attention-style SP in USP

**AMD ROCm Notes**: Requires SGLang >= v0.5.8.

## 4. API Usage

For complete API documentation, please refer to the [official API usage guide](https://docs.sglang.io/docs/sglang-diffusion/api/openai_api.md).

### 4.1 Generate an Image

```python Example theme={null}
import base64
from openai import OpenAI

client = OpenAI(api_key="EMPTY", base_url="http://localhost:30000/v1")

response = client.images.generate(
    model="Tongyi-MAI/Z-Image-Turbo",
    prompt="A logo With Bold Large text: SGL Diffusion",
    n=1,
    response_format="b64_json",
)

# Save the generated image
image_bytes = base64.b64decode(response.data[0].b64_json)
with open("output.png", "wb") as f:
    f.write(image_bytes)
```

### 4.2 Advanced Usage

Z-Image uses `positive + guidance_scale * (positive - negative)` guidance, unlike
the standard CFG convention. Any positive `guidance_scale` enables CFG; omitted
negative prompts use an empty string. Z-Image-Turbo defaults to `guidance_scale=0`
and does not run the negative branch. Enabling CFG adds a second DiT branch, so
expect additional inference cost; it is not automatically recommended for Turbo.

#### 4.2.1 Cache-DiT Acceleration

SGLang integrates [Cache-DiT](https://github.com/vipshop/cache-dit), a caching acceleration engine for Diffusion Transformers (DiT), to achieve up to 7.4x inference speedup with minimal quality loss. You can set `SGLANG_CACHE_DIT_ENABLED=True` to enable it. For more details, please refer to the SGLang Cache-DiT [documentation](https://docs.sglang.io/docs/sglang-diffusion/cache_dit.md).

**Basic Usage**

```bash Command theme={null}
SGLANG_CACHE_DIT_ENABLED=true sglang serve --model-path Tongyi-MAI/Z-Image-Turbo
```

**Advanced Usage**

* DBCache Parameters: DBCache controls block-level caching behavior:

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Env Variable</th>
      <th>Default</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Fn</td>
      <td>`SGLANG_CACHE_DIT_FN`</td>
      <td>1</td>
      <td>Number of first blocks to always compute</td>
    </tr>

    <tr>
      <td>Bn</td>
      <td>`SGLANG_CACHE_DIT_BN`</td>
      <td>0</td>
      <td>Number of last blocks to always compute</td>
    </tr>

    <tr>
      <td>W</td>
      <td>`SGLANG_CACHE_DIT_WARMUP`</td>
      <td>4</td>
      <td>Warmup steps before caching starts</td>
    </tr>

    <tr>
      <td>R</td>
      <td>`SGLANG_CACHE_DIT_RDT`</td>
      <td>0.24</td>
      <td>Residual difference threshold</td>
    </tr>

    <tr>
      <td>MC</td>
      <td>`SGLANG_CACHE_DIT_MC`</td>
      <td>3</td>
      <td>Maximum continuous cached steps</td>
    </tr>
  </tbody>
</table>

* TaylorSeer Configuration: TaylorSeer improves caching accuracy using Taylor expansion:

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Env Variable</th>
      <th>Default</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Enable</td>
      <td>`SGLANG_CACHE_DIT_TAYLORSEER`</td>
      <td>false</td>
      <td>Enable TaylorSeer calibrator</td>
    </tr>

    <tr>
      <td>Order</td>
      <td>`SGLANG_CACHE_DIT_TS_ORDER`</td>
      <td>1</td>
      <td>Taylor expansion order (1 or 2)</td>
    </tr>
  </tbody>
</table>

Combined Configuration Example:

```bash Command theme={null}
SGLANG_CACHE_DIT_ENABLED=true \
SGLANG_CACHE_DIT_FN=2 \
SGLANG_CACHE_DIT_BN=1 \
SGLANG_CACHE_DIT_WARMUP=4 \
SGLANG_CACHE_DIT_RDT=0.4 \
SGLANG_CACHE_DIT_MC=4 \
SGLANG_CACHE_DIT_TAYLORSEER=true \
SGLANG_CACHE_DIT_TS_ORDER=2 \
sglang serve --model-path Tongyi-MAI/Z-Image-Turbo
```

#### 4.2.2 CPU Offload

* `--dit-cpu-offload`: Use CPU offload for DiT inference. Enable if run out of memory.
* `--text-encoder-cpu-offload`: Use CPU offload for text encoder inference.
* `--vae-cpu-offload`: Use CPU offload for VAE.
* `--pin-cpu-memory`: Pin memory for CPU offload. Only added as a temp workaround if it throws "CUDA error: invalid argument".

#### 4.2.3 Known LoRA examples

Use `--lora-path` at startup or the [LoRA management API](https://docs.sglang.io/docs/sglang-diffusion/api/openai_api.md#lora-management) to load an adapter. Known Z-Image-Turbo examples include:

* [`tarn59/pixel_art_style_lora_z_image_turbo`](https://huggingface.co/tarn59/pixel_art_style_lora_z_image_turbo)
* [`wcde/Z-Image-Turbo-DeJPEG-Lora`](https://huggingface.co/wcde/Z-Image-Turbo-DeJPEG-Lora)

## 5. Benchmark

Test Environment:

* Hardware: AMD Instinct MI300X GPU (1x)
* Model: Tongyi-MAI/Z-Image-Turbo
* Docker Image: lmsysorg/sglang:v0.5.8-rocm700-mi30x
* sglang diffusion version: 0.5.8

### 5.1 Speedup Benchmark

#### 5.1.1 Generate an image

**AMD MI300X**

**Server Command**:

```shell Command theme={null}
sglang serve --model-path Tongyi-MAI/Z-Image-Turbo \
    --ulysses-degree=1 --ring-degree=1 --port 30000
```

**Benchmark Command**:

```shell Command theme={null}
python3 -m sglang.multimodal_gen.benchmarks.bench_serving \
    --dataset vbench --task text-to-image --num-prompts 1 --max-concurrency 1
```

**Result**:

```text Output theme={null}
================= Serving Benchmark Result =================
Task:                                    text-to-image
Model:                                   Tongyi-MAI/Z-Image-Turbo
Dataset:                                 vbench
--------------------------------------------------
Benchmark duration (s):                  1.84
Request rate:                            inf
Max request concurrency:                 1
Successful requests:                     1/1
--------------------------------------------------
Request throughput (req/s):              0.54
Latency Mean (s):                        1.8435
Latency Median (s):                      1.8435
Latency P99 (s):                         1.8435
--------------------------------------------------
Peak Memory Max (MB):                    30689.20
Peak Memory Mean (MB):                   30689.20
Peak Memory Median (MB):                 30689.20
============================================================
```

**Ascend A3 Series**

**Server Command**:

```shell Command theme={null}
#One A3 Series card has 2 npu chips
sglang serve --model-path Tongyi-MAI/Z-Image-Turbo --tp-size 2 --sp-degree 1 --num-gpus 2
```

**Benchmark Command**:

```shell Command theme={null}
python -m sglang.multimodal_gen.benchmarks.bench_serving --dataset vbench --task text-to-image --num-prompts 1 --max-concurrency 1
```

**Result**:

```text Output theme={null}
================= Serving Benchmark Result =================
Task:                                         text-to-image
Model:                                        Tongyi-MAI/Z-Image-Turbo
Dataset:                                      vbench
--------------------------------------------------
Benchmark duration (s):                       2.43
Request rate:                                 inf
Max request concurrency:                      1
Successful requests:                          1/1
Completed outputs:                            1
Outputs per prompt:                           1
--------------------------------------------------
Request throughput (req/s):                   0.41
Output throughput (outputs/s):                0.41
Latency Mean (s):                             2.43
Latency Median (s):                           2.43
Latency P90 (s):                              2.43
Latency P95 (s):                              2.43
Latency P99 (s):                              2.43
--------------------------------------------------
Peak Memory Max (MB):                         11052.00
Peak Memory Mean (MB):                        11052.00
Peak Memory Median (MB):                      11052.00
------------------------------------------------------------
```

#### 5.1.2 Generate images with high concurrency

**AMD MI300X**

**Benchmark Command**:

```shell Command theme={null}
python3 -m sglang.multimodal_gen.benchmarks.bench_serving \
    --dataset vbench --task text-to-image --num-prompts 20 --max-concurrency 20
```

**Result**:

```text Output theme={null}
================= Serving Benchmark Result =================
Task:                                    text-to-image
Model:                                   Tongyi-MAI/Z-Image-Turbo
Dataset:                                 vbench
--------------------------------------------------
Benchmark duration (s):                  35.32
Request rate:                            inf
Max request concurrency:                 20
Successful requests:                     20/20
--------------------------------------------------
Request throughput (req/s):              0.57
Latency Mean (s):                        18.5672
Latency Median (s):                      18.5573
Latency P99 (s):                         34.9880
--------------------------------------------------
Peak Memory Max (MB):                    30689.26
Peak Memory Mean (MB):                   30689.21
Peak Memory Median (MB):                 30689.21
============================================================
```

**Ascend A3 Series**

**Benchmark Command**:

```shell Command theme={null}
python -m sglang.multimodal_gen.benchmarks.bench_serving --dataset vbench --task text-to-image --num-prompts 20 --max-concurrency 20
```

**Result**:

```text Output theme={null}
================= Serving Benchmark Result =================
Task:                                         text-to-image
Model:                                        /models/Tongyi-MAI/Z-Image-Turbo/Z-Image-Turbo
Dataset:                                      vbench
--------------------------------------------------
Benchmark duration (s):                       49.08
Request rate:                                 inf
Max request concurrency:                      20
Successful requests:                          20/20
Completed outputs:                            20
Outputs per prompt:                           1
--------------------------------------------------
Request throughput (req/s):                   0.41
Output throughput (outputs/s):                0.41
Latency Mean (s):                             25.78
Latency Median (s):                           25.77
Latency P90 (s):                              44.42
Latency P95 (s):                              46.75
Latency P99 (s):                              48.61
--------------------------------------------------
Peak Memory Max (MB):                         11054.00
Peak Memory Mean (MB):                        11054.00
Peak Memory Median (MB):                      11054.00
------------------------------------------------------------
```

## 6. Run in ComfyUI

Run this model from ComfyUI with the
[SGLDiffusion plugin](https://github.com/sgl-project/sglang/tree/main/python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion), which ships in the SGLang
repository at `python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion`.

**Server mode** — SGLang runs the pipeline and ComfyUI
sends the request. Start a server as shown above, point the
`SGLDiffusion Server Model` node at it, then generate with
`SGLDiffusion Generate Image`.

**Integrated mode** — ComfyUI's own sampler, CLIP, and
VAE drive the loop while SGLang replaces the model forward. Load the
checkpoint with `SGLDiffusion UNET Loader` and set
`model_type` to `lumina2` on the
`SGLDiffusion Options` node.

A reference workflow is included at
`python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/workflows/z-image_sgld.json`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.