#239·Sana

use device map instead of quantalization to save VRAM and keep image quality

Author: Willian7004Created Mar 31, 2025Updated Sep 27, 2026
Labelsdocumentation

I tried Inference with 8bit with SANA1.5 1.6B and the image quality is worse than the demo. Then I tried device_map, the inference on 8g VRAM is about 65% slower than using 8bit quantalization, it isn't much slower consider that the speed is twice of 16bit computing when computing in 8bit. Here is the code I use:

python
# run `pip install git+https://github.com/huggingface/diffusers` before use Sana in diffusers
import torch
from diffusers import SanaPipeline

pipe = SanaPipeline.from_pretrained(
    "Efficient-Large-Model/SANA1.5_1.6B_1024px_diffusers",
    torch_dtype=torch.bfloat16,
    device_map="balanced",
)

pipe.vae.to(torch.bfloat16)
pipe.text_encoder.to(torch.bfloat16)
prompt = 'a castle in forest,photography'
image = pipe(
    prompt=prompt,
    height=1024,
    width=1024,
    guidance_scale=4.5,
    num_inference_steps=20,
    generator=torch.Generator().manual_seed(42),
)[0]

image[0].save("sana.png")