🚀 高效高分辨率扩散模型的深度压缩自编码器
本项目提出了一种新的自编码器模型家族,用于加速高分辨率扩散模型,解决了现有自编码器在高空间压缩比下重建精度不足的问题,显著提升了训练和推理速度。
[论文] [GitHub]
本仓库包含论文 SANA 1.5: Efficient Scaling of Training-Time and Inference-Time Compute in Linear Diffusion Transformer 中的模型。
项目页面:https://hanlab.mit.edu/projects/sana/

图 1:我们解决了高空间压缩自编码器的重建精度下降问题。

图 2:DC - AE 在不降低性能的情况下显著加快了训练和推理速度。

图 3:DC - AE 使笔记本电脑能够高效地进行文本到图像的生成。
📚 摘要
我们提出了深度压缩自编码器(Deep Compression Autoencoder,DC - AE),这是一个用于加速高分辨率扩散模型的新型自编码器模型家族。现有的自编码器模型在中等空间压缩比(如 8 倍)下取得了令人印象深刻的结果,但在高空间压缩比(如 64 倍)下无法保持令人满意的重建精度。我们通过引入两项关键技术来应对这一挑战:(1)残差自编码,我们设计模型基于空间到通道转换后的特征学习残差,以缓解高空间压缩自编码器的优化难度;(2)解耦高分辨率自适应,一种高效的解耦三阶段训练策略,用于减轻高空间压缩自编码器的泛化惩罚。通过这些设计,我们将自编码器的空间压缩比提高到 128,同时保持了重建质量。将我们的 DC - AE 应用于潜在扩散模型,我们在不降低精度的情况下实现了显著的加速。例如,在 ImageNet 512x512 上,与广泛使用的 SD - VAE - f8 自编码器相比,我们的 DC - AE 在 H100 GPU 上为 UViT - H 提供了 19.1 倍的推理加速和 17.9 倍的训练加速,同时实现了更好的 FID。
💻 使用示例
基础用法
from efficientvit.ae_model_zoo import DCAE_HF
dc_ae = DCAE_HF.from_pretrained(f"mit-han-lab/dc-ae-f64c128-in-1.0")
from PIL import Image
import torch
import torchvision.transforms as transforms
from torchvision.utils import save_image
from efficientvit.apps.utils.image import DMCrop
device = torch.device("cuda")
dc_ae = dc_ae.to(device).eval()
transform = transforms.Compose([
DMCrop(512),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
])
image = Image.open("assets/fig/girl.png")
x = transform(image)[None].to(device)
latent = dc_ae.encode(x)
print(latent.shape)
y = dc_ae.decode(latent)
save_image(y * 0.5 + 0.5, "demo_dc_ae.png")
高级用法
from efficientvit.diffusion_model_zoo import DCAE_Diffusion_HF
dc_ae_diffusion = DCAE_Diffusion_HF.from_pretrained(f"mit-han-lab/dc-ae-f64c128-in-1.0-uvit-h-in-512px-train2000k")
import torch
import numpy as np
from torchvision.utils import save_image
torch.set_grad_enabled(False)
device = torch.device("cuda")
dc_ae_diffusion = dc_ae_diffusion.to(device).eval()
seed = 0
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
eval_generator = torch.Generator(device=device)
eval_generator.manual_seed(seed)
prompts = torch.tensor(
[279, 333, 979, 936, 933, 145, 497, 1, 248, 360, 793, 12, 387, 437, 938, 978], dtype=torch.int, device=device
)
num_samples = prompts.shape[0]
prompts_null = 1000 * torch.ones((num_samples,), dtype=torch.int, device=device)
latent_samples = dc_ae_diffusion.diffusion_model.generate(prompts, prompts_null, 6.0, eval_generator)
latent_samples = latent_samples / dc_ae_diffusion.scaling_factor
image_samples = dc_ae_diffusion.autoencoder.decode(latent_samples)
save_image(image_samples * 0.5 + 0.5, "demo_dc_ae_diffusion.png", nrow=int(np.sqrt(num_samples)))
📖 引用
如果 DC - AE 对你的研究有用或相关,请通过引用我们的论文来认可我们的贡献:
@article{chen2024deep,
title={Deep Compression Autoencoder for Efficient High-Resolution Diffusion Models},
author={Chen, Junyu and Cai, Han and Chen, Junsong and Xie, Enze and Yang, Shang and Tang, Haotian and Li, Muyang and Lu, Yao and Han, Song},
journal={arXiv preprint arXiv:2410.10733},
year={2024}
}
关于 SANA 1.5 的工作可以按如下方式引用:
@misc{xie2025sana,
title={SANA 1.5: Efficient Scaling of Training-Time and Inference-Time Compute in Linear Diffusion Transformer},
author={Enze Xie and Junyu Chen and Han Cai and Junsong Chen and Haotian Tang and Yao Lu and Song Han},
year={2025},
eprint={2501.18427},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2501.18427},
}