Disty0/Z-Image-Turbo-SDNQ-int8

Disty0
Texto a imagen

Cuantización de 8 bits de Tongyi-MAI/Z-Image-Turbo usando SDNQ. Está optimizado para reducir el tamaño del modelo de 12,3 GB en BF16 a 6,2 GB en INT8, con soporte opcional para INT8 MatMul en GPUs AMD, Intel ARC y Nvidia.

Como usar

Instalación y ejemplo de inferencia:

pip install sdnq

import torch
import diffusers
from sdnq import SDNQConfig
# import sdnq to register it into diffusers and transformers
from sdnq.common import use_torch_compile as triton_is_available
from sdnq.loader import apply_sdnq_options_to_model

pipe = diffusers.ZImagePipeline.from_pretrained("Disty0/Z-Image-Turbo-SDNQ-int8", torch_dtype=torch.bfloat16)

# Enable INT8 MatMul for AMD, Intel ARC and Nvidia GPUs:
if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()):
    pipe.transformer = apply_sdnq_options_to_model(pipe.transformer, use_quantized_matmul=True)
    pipe.text_encoder = apply_sdnq_options_to_model(pipe.text_encoder, use_quantized_matmul=True)
    pipe.transformer = torch.compile(pipe.transformer) # optional for faster speeds

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."
image = pipe(
    prompt=prompt,
    height=1024,
    width=1024,
    num_inference_steps=9,
    guidance_scale=0.0,
    generator=torch.manual_seed(42),
).images[0]
image.save("z-image-turbo-sdnq-int8")

Funcionalidades

Modelo de texto a imagen basado en ZImagePipeline de Diffusers.
Pesos en formato Safetensors.
Cuantización SDNQ INT8 con tamaños de grupo desactivados para acelerar INT8 MatMul.
INT8 MatMul opcional, desactivado por defecto.
Compatible con inferencia en bfloat16 y descarga de modelo a CPU mediante Diffusers.
Licencia Apache 2.0.

Casos de uso

Generación de imágenes a partir de texto con menor uso de memoria que la versión BF16 original.
Inferencia local de Z-Image-Turbo en hardware compatible con INT8 MatMul.
Pruebas de rendimiento y comparación entre BF16, SDNQ INT8 y SDNQ INT8 MatMul.
Despliegues de texto a imagen donde el tamaño reducido del modelo sea importante.