Z-Image-Turbo, 8-bit (bitsandbytes)
An 8-bit copy of Tongyi-MAI/Z-Image-Turbo, made to fit and load quickly on a 16 GB GPU such as the free Colab T4. It is about 11 GB instead of 31 GB.
Changes from the original
- The transformer and the Qwen3 text encoder are quantized to 8 bit with bitsandbytes (
load_in_8bit) viadiffusers.PipelineQuantizationConfig, and saved withsave_pretrained. - The VAE, scheduler and tokenizer are unchanged.
This copy is not affiliated with or endorsed by Tongyi-MAI. All credit for the model goes to the original authors. The original is released under the Apache License 2.0, and this copy keeps the same license (see LICENSE).
Usage
import torch
from diffusers import ZImagePipeline
pipe = ZImagePipeline.from_pretrained("EnzinoGenie/z-image-turbo-8bit", torch_dtype=torch.float16).to("cuda")
pipe.vae.enable_tiling()
image = pipe(prompt="...", width=1088, height=1920, num_inference_steps=9, guidance_scale=0.0).images[0]
fp16 on a T4. The T4 has no fast bfloat16, so fp16 is the practical choice there. In plain fp16 some activations go past the fp16 range and the output is noise. The outputs of attention.to_out.0 and feed_forward.w2 exceed it. A forward hook that clamps them fixes this, and the results look practically the same as bfloat16:
def clamp(module, args, out):
return torch.nan_to_num(out, nan=0.0, posinf=65000.0, neginf=-65000.0).clamp(-65000, 65000)
for name, module in pipe.transformer.named_modules():
if name.endswith(("attention.to_out.0", "feed_forward.w2")):
module.register_forward_hook(clamp)
Timings on the free T4, 1088×1920, 9 steps:
- loading the pipeline from local disk: about 45 s;
- each image: about 65–95 s.