File size: 3,616 Bytes
35dc66c 9fed2c9 35dc66c 9fed2c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
---
license: other
license_name: ncslv1
pipeline_tag: text-to-image
tags:
- nvidia
- pytorch
language:
- en
---
# DC-HT: Tokenizer for DC-AR
<div align="center">
<a href="https://hanlab.mit.edu/projects/dc-ar"><img src="https://img.shields.io/static/v1?label=Website&message=DC-AR&color=darkred&logo=github-pages"></a>  
<a href="https://github.com/dc-ai-projects/DC-AR"><img src="https://img.shields.io/static/v1?label=Github&message=DC-AR&color=blue&logo=github"></a>  
<a href="https://arxiv.org/abs/2507.04947"><img src="https://img.shields.io/static/v1?label=arXiv&message=DC-AR&color=red&logo=arxiv"></a>  
<a href="https://dc-ar.hanlab.ai"><img src="https://img.shields.io/static/v1?label=Demo&message=DC-AR&color=yellow"></a>  
</div>

## Overview
We introduce DC-AR, a novel masked autoregressive (AR) text-to-image generation framework that delivers superior image generation quality with exceptional computational efficiency. Due to the tokenizers' limitations, prior masked AR models have lagged behind diffusion models in terms of quality or efficiency. We overcome this limitation by introducing DC-HT - a deep compression hybrid tokenizer for AR models that achieves a 32× spatial compression ratio while maintaining high reconstruction fidelity and cross-resolution generalization ability. Building upon DC-HT, we extend MaskGIT and create a new hybrid masked autoregressive image generation framework that first produces the structural elements through discrete tokens and then applies refinements via residual tokens. DC-AR achieves state-of-the-art results with a gFID of **5.49** on MJHQ-30K and an overall score of **0.69** on GenEval, while offering **1.5-7.9×** higher throughput and **2.0-3.5×** lower latency compared to prior leading diffusion and autoregressive models.
## Setup
Download the github repo and install the environment:
```bash
git clone https://github.com/mit-han-lab/dc-ar
cd dc-ar
conda create -n dcar python=3.10
conda activate dcar
pip install -e .
```
Download DC-HT and DC-AR
```bash
git clone https://huggingface.co/mit-han-lab/dc-ar-512
git clone https://huggingface.co/mit-han-lab/dc-ht
```
Download the safety check model:
```bash
git clone https://huggingface.co/google/shieldgemma-2b
```
Note: We use ShieldGemma-2B from Google DeepMind to filter out unsafe prompts in our demo. We strongly recommend using it if you are distributing our demo publicly.
## Usage
### Gradio demo
You may launch the Gradio demo using the following script:
```bash
python app.py --shield_model_path /path/to/ShieldGemma2B
```
### Command Line Inference
1. Sampling with single prompt:
```bash
python sample.py --prompt "YOUR_PROMPT" \
--sample_folder_dir /path/to/save_dir \
--shield_model_path /path/to/ShieldGemma2B
```
2. Sampling with multiple prompts:
```bash
# You can add --store_seperately to store each image individually, otherwise images will be stored in one grid.
python sample.py --prompt_list [Prompt1, Prompt2, ..., PromptN] \
--sample_folder_dir /path/to/save_dir \
--shield_model_path /path/to/ShieldGemma2B
```
## Citation
```bibtex
@article{wu2025dcar,
title={DC-AR: Efficient Masked Autoregressive Image Generation with Deep Compression Hybrid Tokenizer},
author={Wu, Yecheng and Chen, Junyu and Zhang, Zhuoyang and Xie, Enze and Yu, Jincheng and Chen, Junsong and Hu, Jinyi and Lu, Yao and Han, Song and Cai, Han},
journal={arXiv preprint arXiv:2410.10733},
year={2025}
}
```
|