ImageFolder: Autoregressive Image Generation with Folded Tokens

## Abstract

Abstract Image tokenizers are crucial for visual generative models, e.g., diffusion models (DMs) and autoregressive (AR) models, as they construct the latent representation for modeling. Increasing token length is a common approach to improve the image reconstruction quality. However, tokenizers with longer token lengths are not guaranteed to achieve better generation quality. There exists a trade-off between reconstruction and generation quality regarding token length. In this paper, we investigate the impact of token length on both image reconstruction and generation and provide a flexible solution to the tradeoff. We propose ImageFolder , a semantic tokenizer that provides spatially aligned image tokens that can be folded during autoregressive modeling to improve both generation efficiency and quality. To enhance the representative capability without increasing token length, we leverage dual-branch product quantization to capture different contexts of images. Specifically, semantic regularization is introduced in one branch to encourage compacted semantic information while another branch is designed to capture the remaining pixel-level details. Extensive experiments demonstrate the superior quality of image generation and shorter token length with ImageFolder tokenizer.

## 1 Introduction

Image generation Chang et al. (); Dhariwal & Nichol (); He et al. (); Esser et al. (); Yu et al. (); Weber et al. () has achieved notable progress empowered by diffusion models (DMs) Dhariwal & Nichol (); Rombach et al. (); Peebles & Xie () and autoregressive (AR) models/large language models (LLMs) Vaswani et al. (). Different from diffusion models that leverage a continuous image representation Li et al. (); Dhariwal & Nichol (); Rombach et al. (); Peebles & Xie (), AR models and LLMs typically discretize image features into tokens Yu et al. (); Li et al. (); Tian et al. () and conduct the autoregressive modeling in the discrete space. Therefore, the performance of AR models/LLMs is largely influenced by the properties of the image tokenizers. This motivates the community to push the edge of image tokenizers for high-quality and efficient visual generation with large language models.

VQGAN Esser et al. () is a pioneer work on image tokenization that leverages a vector quantization Gray () operation to map the continuous image feature to discrete tokens with a learnable codebook. Recently, several improvements from different perspectives have been made to the original VQGAN Lee et al. (); Yu et al. (); Mentzer et al. (); Zhu et al. (); Takida et al. (); Huang et al. (); Zheng et al. (); Yu et al. (); Weber et al. (); Yu et al. (); Luo et al. (). For example, VAR Tian et al. () proposes a multi-scale vector quantization (MSVQ) which quantizes images into a series of multi-scale tokens and conducts the autoregressive modeling in a scale-based manner, leading to a remarkable latency reduction and reconstruction improvement. However, in a trade-off of the speed and reconstruction quality, the sequence length of the quantized tokens is much longer compared to other models which could result in a larger training cost and difficulty of incorporating in LLMs with long contexts Jin et al. (); Ding et al. (). SEED Ge et al. () and TiTok Yu et al. () improve the VQGAN by injecting semantics into the quantized codewords. Since the semantic tokens can convey more compacted information about the image, they can achieve a much smaller token number to represent an image compared to the VQGAN. Nevertheless, a smaller token number typically leads to information loss. SEED Ge et al. () tokenizer discards all pixel-level details and only retains semantics to achieve a smaller token number. TiTok Yu et al. () conducts concatenated tokenization with multiple quantization operations to achieve a higher compression rate while still suffering from detail distortion during reconstruction. Based on previous arts, we can summarize a trade-off between reconstruction and generation: (1) a longer token number can lead to a better reconstruction performance while making the sequence length too long for autoregressive generation (e.g., requiring larger model capacity Sun et al. (), suffering more error propagation during AR sampling Kaiser et al. () and more training costs Tian et al. ()), and (2) a smaller token number can lead to inferior reconstruction performance while benefit generation. Motivated by this, we aim to explore whether it is possible to retain a sufficient number of tokens for high-quality reconstruction without lengthening the sequence length for generation.

Figure: Figure 2: Token dependency.
Refer to caption: x2.png

While it is possible to predict multiple tokens parallelly from one logit Alexey (); Peebles & Xie () as shown in Fig. 1 (b). This predicting scheme ignores the dependency between tokens predicted in parallel in the AR modeling. However, as the vector quantization Esser et al. () is typically conducted on the spatial-preserved image features, each quantized token represents a spatial region of the original image, leading to high spatial dependency among tokens as shown in Fig. 2. To address this problem, we aim to maintain spatial dependency in AR modeling while constructing distinct tokens within each spatial location to obtain token pairs with low dependency using product quantization Jegou et al. ().

In this paper, we propose ImageFolder, a semantic image tokenizer that provides spatially aligned image tokens, which can be folded for a shorter token length during autoregressive modeling. We demonstrate that even if the overall token number remains the same, the folded tokens demonstrate a better generation performance compared to unfolded ones. Specifically, different from previous tokenizers Lee et al. (); Yu et al. (); Mentzer et al. (); Zhu et al. (); Takida et al. (); Huang et al. (); Zheng et al. (), we leverage product quantization to separately capture different information of images, i.e., semantics and pixel-level details, with two branches. Within each branch, we use the multi-scale residual quantization as our quantizer. A quantizer dropout is further proposed to force each residual layer to represent an image with different bitrates, thus compensating the unmodeled dependency in the next-scale AR modeling Tian et al. (). With the above designs, the spatially aligned tokens from ImageFolder can be folded for a parallel prediction during AR modeling as shown in Fig. 1 (b), which leads to half of the modeling token length while achieving a better generation quality.
Our contribution can be summarized in three-fold:

- •
We present ImageFolder, a novel image tokenizer that enables shorter token length during autoregressive modeling while not losing reconstruction/generation quality.
- •
We explore the product quantization in the image tokenizer. Moreover, we introduce semantic regularization and quantizer dropout to enhance the representation capability of the quantized image tokens.
- •
We investigate the trade-off between the generation and reconstruction regarding token length with extensive experiments, facilitating the understanding of image generation with AR modeling.

## 2 Related Works

### 2.1 Image Tokenizers

Image tokenizer has seen significant progress in multiple image-related tasks. Traditionally, autoencoders Hinton & Salakhutdinov (); Vincent et al. () have been used to compress images into latent spaces for downstream work such as (1) generation and (2) understanding. In the case of generation, VAEs Van Den Oord et al. (); Razavi et al. () learn to map images to probabilistic distributions; VQGAN Esser et al. (); Razavi et al. () and its subsequent variants Lee et al. (); Yu et al. (); Mentzer et al. (); Zhu et al. (); Takida et al. (); Huang et al. (); Zheng et al. (); Yu et al. (); Weber et al. (); Yu et al. (); Luo et al. () introduce a discrete latent space for better compression for generation. On the other hand, understanding tasks, such as CLIP Radford et al. (), DINO Oquab et al. (); Darcet et al. (), rely heavily on LLM Vaswani et al. (); Dosovitskiy et al. () to tokenize images into semantic representations Dong et al. (); . These representations are effective for tasks like classification Dosovitskiy et al. (), object detection Zhu et al. (), segmentation Wang et al. (), and multi-modal application Yang et al. (). For a long time, image tokenizers have been divided between methods tailored for generation and those optimized for understanding. After the appearance of Yu et al. (), which proved the feasibility of using LLM as a tokenizer for generation, some works Wu et al. () are dedicated to unify the tokenizer for generation and understanding due to the finding in Gu et al. ().

### 2.2 Autoregressive Visual Generation

Autoregressive models have shown remarkable success in generating high-quality images by modeling the distribution of pixels or latent codes in a sequential manner. Early autoregressive models such as PixelCNN Van den Oord et al. () pioneered the approach of predicting pixel values conditioned on previously generated pixels. The transformer architecture Vaswani et al. (), first proposed in NLP, has spread rapidly to image generation Shi et al. (); Mizrahi et al. () because of its scalability and efficiency. MaskGIT Chang et al. () accelerated the generation by predicting tokens in parallel, while MAGE Li et al. () applied MLLM Bao et al. (); Peng et al. () to unify the visual understanding and the generation task. Recently, autoregressive models continued to show their scalability power in larger datasets and multimodal tasks He et al. (); models like LlamaGen Sun et al. () adapting Llama Touvron et al. () architectures for image generation. New directions such as VAR Tian et al. (); Li et al. (), MAR Li et al. () and Mamba Li et al. () have further improved flexibility and efficiency in image synthesis. Currently, more and more unified multimodal models like SHOW-O Xie et al. (), Transfusion Zhou et al. () and Lumina-mGPT Liu et al. () continue to push the boundaries of autoregressive image generation, demonstrating scalability and efficiency in diverse visual tasks.

### 2.3 Diffusion Models for Image Generation

Diffusion models, initially introduced by Sohl-Dickstein et al. Sohl-Dickstein et al. () as a generative process and later expanded into image generation by progressively infusing fixed Gaussian noise into an image as a forward process. A model, such as U-Net Ronneberger et al. (), is then employed to learn the reverse process, gradually denoising the noisy image to recover the original data distribution. In recent years, this method has witnessed significant advancements driven by various research efforts. Nichol et al. Nichol & Dhariwal (), Dhariwal et al. Dhariwal & Nichol (), and Song et al. Song et al. () proposed various techniques to enhance the effectiveness and efficiency of diffusion models, paving the way for improved image generation capabilities. Notably, the paradigm shift towards modeling the diffusion process in the latent space of a pre-trained image encoder as a strong prior Van Den Oord et al. (); Esser et al. () rather than in raw pixel spaces Vahdat et al. (); Rombach et al. () has proven to be a more efficient and instrumental method for high-quality image generation. Moreover, a lot of research on the model architecture replaces or integrates the vanilla U-Net with a transformer Peebles & Xie () to further improve the capacity and efficiency of multi-model synthesis on diffusion model. Inspired by these promising advancements in diffusion models, numerous foundational models have emerged, driving innovation in both image quality and flexibility. For instance, Glide Nichol et al. () introduced a diffusion model for text-guided image generation, combining diffusion techniques with text encoders to control the generated content. Cogview Ding et al. () leveraged transformer architectures alongside diffusion methods to enhance image generation tasks. Make-A-Scene Gafni et al. () and Imagen Saharia et al. () focused on high-fidelity image synthesis conditioned on textual inputs, showcasing the versatility of diffusion models across modalities. DALL-E Ramesh et al. () and Stable Diffusion Rombach et al. () brought diffusion models to mainstream applications, demonstrating their ability to generate high-resolution photorealistic images. Additionally, recent models such as MidJourney MidJourney Inc. () and SORA OpenAI () have further refined the use of diffusion models in creative and commercial contexts, illustrating the growing influence and adaptability of these models in a range of domains. Even though the performance of image generation in diffusion models has shown impressive results, the training cost and inference speed remain bottlenecks, motivating the exploration of more efficient approaches such as leveraging large language models (LLMs) for image generation.

## 3 Method

Figure: Figure 3: Overview of ImageFolder. ImageFolder leverages vision transformers Alexey () to encode and decode images. Given an image, two sets of $K\times K$ learnable tokens are used to generate spatially-aligned low-resolution features from the image. After that, a product quantization is used to obtain discrete image representation. A semantic regularization is applied in one of the quantizers to inject semantic constraints. The quantized tokens are concatenated to serve as input for the image decoder to reconstruct images.
Refer to caption: x3.png

#### Preliminaries.

Product quantization (PQ) Jegou et al. () aims to quantize a high-dimension vector to a combination of several low-dimension tokens, which has shown a promising capability to capture different contexts across sub-quantizers Baevski et al. (). Given a continuous feature $z$, product quantization performs as:

$$ $\mathcal{P}(z)=\mathcal{Q}_{1}(z_{1})\oplus\cdots\oplus\mathcal{Q}_{P}(z_{P}), \mathcal{Q}_{p}\sim\mathcal{C}_{p},$ (1) $$

where $\oplus$ denotes channel-wise concatenation (cartesian product), $\sim$ denotes that vector quantizer $\mathcal{Q}_{p}$ is associated with the codebook $\mathcal{C}_{p}=\{e_{j}\}_{j=1}^{J}$, i.e., $\mathcal{Q}_{p}$ maps a feature $z_{p}$ to a codeword $e_{p}=\arg\min_{e_{j}\in\mathcal{C}_{p}}\|z_{p}-e_{j}\|_{2}^{2}$ that minimizes the distance between $z_{p}$ and $e_{j}\in\mathcal{C}_{p}$. $P$ is the product number, i.e., sub-vector number and $z_{p}$ is a sub-vector from $z$ having $z=\oplus_{p=1}^{P}z_{p}$. Product quantization first divides the target vector into several sub-vectors and then quantizes them separately. After the quantization, the quantized vectors resemble the original vector by concatenation.

### 3.1 ImageFolder

**Table 1: Performance against #Tokens.**
| # Tokens | 10$\times$10 | 12$\times$12 | 14$\times$14 |
| --- | --- | --- | --- |
| rFID | 4.15 | 3.21 | 2.40 |
| gFID | 5.22 | 5.34 | 6.24 |

Imagefolder is a semantic image tokenizer that tokenizes an image into spatially aligned semantic and detail tokens with product quantization. The Imagefolder is designed based on two preliminary observations.
(1) As preliminary experiments shown in Tab 1, increasing the token number generally leads to better reconstruction quality. However, generation behaves differently — longer token sequences can result in inferior outcomes.

Figure: Figure 4: Image reconstruction.
Refer to caption: x4.png

(2) Semantic tokenizers, e.g., SEED Ge et al. () and Titok Yu et al. () can encode an image into only a few tokens (32 tokens). As shown in Fig. 4, even though losing pixel-level structure/details of the image, the reconstructed images are semantically correct spatially. This motivates us to leverage semantics to obtain compacted image representation while encoding the remaining image details with additional tokens.

#### Architecture.

As shown in Fig. 3, given an input image $I$, we first patchify it into a set of ${L\times L}$ tokens where $L$ is the patch size. After that, the image tokens are concatenated with two sets of ${K\times K}$ learnable tokens and serve as the input to the transformer encoder $\mathcal{E}$. The same spatial positional encodings are added to the learnable tokens to inform the spatial alignment. A level embedding is additionally used to convey the difference across $K\times K$ tokens. Let us denote the encoded tokens corresponding to the learnable tokens as $z_{d},z_{s}$. To discretize them, we use a detail quantizer $\mathcal{Q}_{d}$ and a semantic quantizer $\mathcal{Q}_{s}$ to conduct product quantization. The quantized tokens $z^{\prime}_{d}$ and $z^{\prime}_{s}$ are further concatenated with a set of ${L\times L}$ learnable tokens to decode the reconstructed image with a decoder $\mathcal{D}$.

#### Token quantization.

As shown in Fig. 3, we leverage product quantization to quantize an image with semantics and pixel-level details using two branches separately. Specifically, semantic regularization is applied to the semantic branch to guide the semantics and distinguish it from the detail branch. Moreover, a quantizer dropout strategy is used to facilitate the quantizer to learn multi-scale image representation.

Figure: Figure 5: Illustration of quantizer dropout in multi-scale residual quantizer.
Refer to caption: x5.png

(1) Quantizer dropout: We use multi-scale residual quantizer (MSRQ) Tian et al. () for each branch, leading to multi-resolution tokens $z^{\prime}_{1},z^{\prime}_{2},\cdots,z^{\prime}_{N}$ where $N$ denotes the number of residual steps. In the $i$-th residual step, the MSRQ quantizer first downsamples the input to a smaller $L_{i}\times L_{i}$ resolution and then quantizes it by mapping it to its closest vector in the codebook $\mathcal{C}=\{e_{j}\}_{j=1}^{J}$ as $\hat{z_{i}}[a,b]=\arg\min_{e_{j}\in\mathcal{C}}\|z_{i}[a,b]-e_{j}\|_{2}^{2}$, where $[a,b]$ is the spatial coordinates. After the nearest-neighbor look-up, the quantized representation $\hat{z_{i}}$ is up-sampled back to the original resolution $K\times K$ with a convolution to handle the blurring as:

$$ $z_{i}^{\prime}=\gamma\times\text{conv}(\hat{z_{i}})+(1-\gamma)\times\hat{z_{i}},$ (2) $$

where $\gamma$ is set to an constant scalar as $0.5$.
Specifically, to enhance the representation capability, we notice that a quantizer dropout strategy Kumar et al. (); Zeghidour et al. () can largely improve generation performance.
During training, as shown in Fig. 5, we randomly drop out the last several quantizers. The quantizer dropout happens with a ratio of $p$. With the quantizer dropout, the final output of the MSVQ can be formulated as:

$$ $z^{\prime}=\sum_{i=1}^{n}z^{\prime}_{i},N_{start}\leq n\leq N.$ (3) $$

Applying quantizer dropout enables residual quantizers to encode images into different bitrates depending on the residual steps. This will significantly smooth the next-scale autoregressive prediction, as we will show in Fig. 7. To ensure training stability, the first $N_{start}=3$ quantizers with extreme low resolution are never dropped out.

(2) Product quantization: We quantize images with separate MSVQ to capture different information. Denoting the output of detail and semantic quantizer as $z_{d}^{\prime}$ and $z_{s}^{\prime}$ respectively, we concatenate them in a channel-wise manner $z_{d}^{\prime}\oplus z_{s}^{\prime}$ to form the final quantized token. It is worth noting that both quantizers share the same quantizer dropout setting for each sample. The codebooks are updated separately for each quantizer.

#### Semantic regularization.

Figure: Figure 6: Visualization of zero out $z^{\prime}_{s}$ or $z^{\prime}_{d}$.
Refer to caption: x6.png

To impose semantics into the tokenized image representation, we propose a semantic regularization term to the quantized token $z_{s}^{\prime}$. A frozen pre-trained DINOv2 model Oquab et al. () is utilized to extract the semantic-rich visual feature $f_{s}$ of the input image $I$. We first pool the quantized token $z^{\prime}_{s}$ to $1\times 1$. After that, a CLIP-style contrastive loss Radford et al. () is used to perform visual alignment: maximizing the similarity between the quantized tokens $z^{\prime}_{s}$ and their corresponding DINO representation $f_{s}$, while minimizing the similarity between $z^{\prime}_{s}$ and other representations $f_{s}$ from different images within one batch. To facilitate semantic learning, we initialize the image encoder $\mathcal{E}$ with the same DINOv2 weight as the frozen one. We notice that the tokens with quantizer dropout will lead to instability during training. In this way, the contrastive loss is only applied to the tokens without being applied dropout. As shown in Fig. 6, we visualize reconstructed images with zero $z_{s}^{\prime}$ or $z_{d}^{\prime}$ to investigate the information captured by different quantizers. When we zero out the semantic tokens $z_{s}^{\prime}$, we notice that the boundary of the reconstructed image remains aligned with the input. In contrast, zeroing out detail tokens reconstructs an image that is more similar to the input while the object identity is not maintained (like what SEED Ge et al. () and TiTok Yu et al. () perform).

**Table 2: rFID of DINOv2 as tokenizer.**
| Tuning | Linear | LORA | Full |
| --- | --- | --- | --- |
| rFID | $>$5 | 3.55 | 1.57 |

We provide a more in-depth discussion here to facilitate the understanding of adopting semantic regularization only in one branch. We notice a concurrent work VILA-U Wu et al. () also aims to inject semantics into the quantized tokens while their design results in performance degradation for image generation. As shown in Tab 2, we compare the rFID with pre-trained DINOv2 Oquab et al. () as an image encoder. We can find that the semantic-rich features from DINOv2 are not suitable for image reconstruction. We consider this can be because the features only contain structural semantics while discards pixel-level details. In this way, directly injecting semantics into all quantized tokens will force the image tokenizer to ignore high-frequency details. To address this issue, we only use semantic regularization in one branch and leave another branch to capture other information required to reconstruct the image.

#### Loss function.

The ImageFolder is trained with composite losses including reconstruction loss $\mathcal{L}_{recon}$, vector quantization loss $\mathcal{L}_{VQ}$, adverserial loss $\mathcal{L}_{ad}$, Perceptual loss $\mathcal{L}_{P}$, and CLIP loss $\mathcal{L}_{clip}$:

$$ $\mathcal{L}=\lambda_{recon}\mathcal{L}_{recon}+\lambda_{VQ}\mathcal{L}_{VQ}+ \lambda_{ad}\mathcal{L}_{ad}+\lambda_{P}\mathcal{L}_{P}+\lambda_{clip}\mathcal {L}_{clip}.$ (4) $$

Specifically, the reconstruction loss measures the $L_{2}$ distance between the reconstructed image and the ground truth; vector quantization loss encourages the encoded features and its aligned codebook vectors; adversarial loss, applied from a PatchGAN Isola et al. () discriminator trained simultaneously, ensures that the generated images are indistinguishable from real ones; perceptual loss compares high-level feature representations from a pre-trained LPIPS Zhang et al. () to capture structural differences; and CLIP loss performs semantic regularization between semantic tokens and the pre-trained DINOv2 Oquab et al. () features. A LeCam regularization Tseng et al. () is applied to the adversarial loss to stabilize the training.

### 3.2 Autoregressive Modeling

To demonstrate the effectiveness of the proposed ImageFolder tokenizer, we train an autoregressive (AR) model to perform image generation based on the tokens obtained from ImageFolder. We follow VAR Tian et al. () to conduct the next-scale AR modeling for a faster inference speed. Recall that, we leverage product quantization to achieve spatially aligned tokens.
Different from regular AR modeling which predicts one token from one logit, as shown in Fig. 1, we predict two tokens from the same logit with separate softmax operations. During training, the two predicted tokens are separately supervised with the corresponding ground truth. During inference, the tokens are sampled in parallel with a top-k-top-p sampling and then fed to the image decoder for image reconstruction. With our parallel predicting scheme, the visual tokens can be folded as input to the AR model, leading to half reduction of the original token length.
We show that a shorter token length can benefit the generation quality, even though the overall token number remains the same.

#### Parallel decoding.

We discuss the nature and differences between parallel decoding and traditional AR modeling. In vanilla AR models, given two tokens $x$ and $y$ (Fig. 1 (b)), the joint distribution $p(x,y)$ is modeled through the conditional dependency $p(x\mid y)p(y)$, meaning $x$ is sampled based on $y$. In contrast, our approach samples the joint distribution in parallel, assuming

$$ $p(x,y)=p(x)p(y),$ (5) $$

which imposes independence between tokens $x$ and $y$. This independent assumption makes most existing image tokenizers, such as Esser et al. (); Tian et al. (), unsuitable for parallel decoding as the spatial dependency is strong. To address this, we introduce product quantization, a technique commonly used to quantize high-dimensional spaces into several low-dimensional subspaces to reduce the dependencies. Specifically, we apply semantic regularization to one quantization branch while allowing the other branch to learn complementary information. This encourages that tokens from different branches capture distinct aspects of the image, resulting in weaker dependencies compared to the traditional spatial dependency among tokens.

In addition, with the quantizer dropout, each residual step can represent images with different bitrates. During the next-scale AR modeling, although the dependency within the current scale is not considered, the conditional dependency can still be refered from the low-resolution tokens in previous AR steps.

## 4 Experiments

**Table 3: Ablation study on the improvement of ImageFolder. We evaluate the rFID and gFID on the ImageNet validation set.**
| ID | Method | Length | Evaluation Metric |  |
| --- | --- | --- | --- | --- |
|  | rFID$\downarrow$ | gFID$\downarrow$ |  |  |
| 1 | Multi-scale residual quantization Tian et al. () | 680 | 1.92 | 7.52 |
| 2 | + Quantizer dropout | 680 | 1.71 | 6.03 |
| 3 | + Smaller patch size $K=11$ | 265 | 3.24 | 6.56 |
| 4 | + Product quantization & Parallel decoding | 265 | 2.06 | 5.96 |
| 5 | + Semantic regularization on all branches | 265 | 1.97 | 5.21 |
| 6 | + Semantic regularization on one branch | 265 | 1.57 | 3.53 |
| 7 | + Strong discriminator | 265 | 1.04 | 2.94 |
| 8 | + Equilibrium enhancement | 265 | 0.80 | 2.60 |

### 4.1 Experimental Settings

We test our ImageFolder tokenizer on the ImageNet 256x256 reconstruction and generation tasks. Our tokenizer training recipe is based on LlamaGen Sun et al. (). [Important] Due to the limited computational resources, we just report the results trained with a short training scheme, e.g., 250k iterations for the tokenizer. More results with advanced training recipes (more iterations, stronger discriminator, and strong perceptual loss) will be updated soon.

#### Metrics.

We utilize Fréchet Inception Distance (FID) Heusel et al. (), Inception Score (IS) Salimans et al. (), Precision, and Recall as metrics for assessing the image generation.

#### Implementation details.

For the ImageFolder tokenizer, if there is no other specification, we follow the VQGAN training recipe of LlamaGen Sun et al. (). We initialize the image encoder with the weight of DINOv2-base. We use a cosine learning rate scheduler with a warmup for 1 epoch and a start learning rate of 3e-5. We set the quantizer drop ratio to 0.1. We set $\lambda_{clip}=0.1$. We set the residual quantizer scales to $[1,1,2,3,3,4,5,6,8,11]$ (in total 265 tokens). The codebook size for each tokenizer is set to 4096. The residual quantization of each branch shares the same codebook across scales. For the generator, we adopt VAR’s Tian et al. () GPT-2-based Radford et al. () architecture. We double the channel of the output head to predict two tokens in parallel.

### 4.2 Performance analysis

#### Roadmap to improve the ImageFolder tokenizer.

We first discuss the core designs of ImageFolder. (1) We begin with our baseline using multi-scale residual quantization from VAR Tian et al. () with a latent resolution of $16\times 16$ and incorporate the proposed modules step by step. (2) As shown in Tab 3, with a quantizer dropout, gFID achieves a significant improvement of 1.49 FID. We consider this to be due to the smoother next-scale AR modeling as quantizer dropout will force each scale to represent the images with different resolutions. (3) After that, we adjust the latent resolution to $11\times 11$ which leads to a performance drop for both reconstruction and generation due to a smaller token number. (4) To increase the token number without enlarging the token length, we adopt a product quantization with corresponding parallel decoding. This modification results in a rFID of 2.06 and a gFID of 5.96 which outperforms the $16\times 16$ counterpart’s gFID of 6.03. (5) We further employ semantic regularization to enrich the semantics in the latent space for a more compact representation. (6) With the analysis of Tab 2, we realize that pure semantics is not enough for image reconstruction. Therefore, we adjust the semantic regularization to only one branch of the product quantization. Significant performance improvement is observed in both reconstruction and generation. Regularization on a single branch encourages different branches to capture different information about the image for a better reconstruction quality and reduces the feature dependency thus leading to a more robust sampling during generation. With all components, the VAR with ImageFolder achieves 3.53 gFID with only 265 token lengths.

**Table 4: Performance comparison on class-conditional ImageNet 256x256. [Important] Due to the computing limitation, the utilized ImageFolder tokenizer is trained with a short scheme, i.e., 250K iterations. Results with advanced training recipes as other comparable methods will be updated soon. ^∗ denotes the utilized image tokenizer is trained on OpenImage Kuznetsova et al. ().**
| Type | Method | Tokenizer | Generator |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| rFID$\downarrow$ | L.P.$\uparrow$ | gFID$\downarrow$ | IS$\uparrow$ | Pre$\uparrow$ | Rec$\uparrow$ | #Para | Leng. | Step |  |  |
| Diff. | ADM Dhariwal & Nichol () | - | - | 10.94 | 101.0 | 0.69 | 0.63 | 554M | - | 1000 |
| Diff. | LDM-4 Rombach et al. () | 0.74 | - | 3.60 | 247.7 | - | - | 400M | - | 250 |
| Diff. | DiT-L/2 Peebles & Xie () | - | - | 5.02 | 167.2 | 0.75 | 0.57 | 458M | - | 250 |
| Diff. | MAR-B Li et al. () | 1.22 | - | 2.31 | 281.7 | 0.82 | 0.57 | 208M | - | 64 |
| NAR | MaskGIT Chang et al. () | 2.28 | - | 6.18 | 182.1 | 0.80 | 0.51 | 227M | 256 | 8 |
| NAR | RCG (cond.) Li et al. () | - | - | 3.49 | 215.5 | - | - | 502M | 256 | 250 |
| NAR | TiTok-S-128 Yu et al. () | 1.52 | 50.5 | 1.94 | 215.5 | - | - | 502M | 128 | 64 |
| AR. | VQGAN Esser et al. () | 7.94 | - | 18.65 | 80.4 | 0.78 | 0.26 | 227M | 256 | 256 |
| AR. | RQ-Transformer Lee et al. () | 1.83 | - | 15.72 | 86.8 | - | - | 480M | 1024 | 64 |
| AR. | LlamaGen-L Sun et al. () | 2.19 | 2.6 | 3.80 | 248.3 | 0.83 | 0.52 | 343M | 256 | 256 |
| AR. | VAR^∗ Tian et al. () | 0.90 | 11.3 | 3.30 | 274.4 | 0.84 | 0.51 | 310M | 680 | 10 |
| AR. | ImageFolder (ours) | 0.80 | 58.0 | 2.60 | 295.0 | 0.75 | 0.63 | 362M | 265 | 10 |

#### Image generation comparison.

As shown in Tab 4, we compare ImageFolder with state-of-the-art generative models. We notice ImageFolder outperforms LlamaGen which shares a similar tokenizer training scheme. Compared with VAR (with advanced tokenizer training recipe, e.g., OpenImage, longer training, and stronger discriminator), our method achieves a comparable performance. In addition, the shorter token length of ImageFolder (265 length) also remarkably saves training/inference costs compared to VAR (680 length) which is $\mathcal{O}(n^{2})$ to the length $n$. Since VAR Tian et al. () did not release their tokenizer training code and recipe, we can not reproduce their result. With our architecture and training recipe, the vanilla MSVQ Tian et al. () only leads to a rFID of 1.92 and a gFID of 7.52.

Figure: Figure 7: Visualization of reconstructed images from different residual quantization steps. The residual scales used for this visualization is $[1,1,2,3,3,4,5,6,8,11]$. The quantizer dropout starts from the third scale $2\times 2$.
Refer to caption: x7.png

### 4.3 More Analysis

#### Reconstruction of different residual steps.

We demonstrate the visualization of reconstructed images with different residual steps in Fig. 7. Without quantizer dropout, the core information is mainly concentrated on the last several layers. In contrast, with quantizer dropout, the one residual quantizer can perform image tokenization with different bitrates based on the residual step leading to progressively improved representation for the next-scale AR modeling.

#### Conditional image generation.

Figure: Figure 8: Conditional image generation.
Refer to caption: x8.png

Inspired by the teacher-forcing guidance proposed by ControlVAR Li et al. (), we teacher-force detail tokens of a reference image to conduct zero-shot conditional image generation with an AR model trained with ImageFolder. Specifically, we first encode the reference image to obtain the detail tokens. After that, we teacher-force the detail token during the AR modeling to conduct the conditional image generation Li et al. (). As shown in Fig. 8, we visualize the reference image, the reconstruction of the reference detail token and the generated image. We notice that the generated image follows the spatial shapes of the reference image while containing different visual contents, e.g., rocky mountain to frosty mountain. This experiment demonstrates a promising novel usage of ImageFolder on conditional image generation.

#### Linear probing.

**Table 5: Linear probing Top-1 accuracy comparison on ImageNet val set.**
| Method | LlamaGen | VAR | ImageFolder |
| --- | --- | --- | --- |
| Acc. | 2.62 | 11.32 | 55.42 |

We further analyze the performance of the ImageFolder tokenizer by conducting linear probing on the ImageNet val set. As shown in Tab 5, we compare the linear probing top-1 accuracy of ImageFolder with LlamaGen and VAR. We notice that ImageFolder achieves a significantly superior linear probing accuracy compared to comparable methods. We notice that VAR also demonstrates a decent linear probing accuracy which can be credited to its advanced training with the DINO discriminator.

**(a)**
| $N_{start}$ | 1 | 3 | 5 |
| --- | --- | --- | --- |
| rFID | $>$20 | 1.57 | 1.69 |

Figure: Figure 9: Visualization of $256\times 256$ image generation task within ImageNet classes.
Refer to caption: x9.png

#### Inference latency.

**Table 7: Inference latency with $batchsize$=1 on single A100 GPU.**
| Method | LlamaGen | VAR | Ours |
| --- | --- | --- | --- |
| Time (s) | 8.851 | 0.134 | 0.130 |

We compare the inference speed of LlamaGen, VAR, and our method, as summarized in Tab 7. LlamaGen exhibits slower inference due to its next-token autoregressive (AR) mechanism. Our approach achieves comparable latency to VAR, as both methods require the same number of AR steps (without CPU optimization). However, it is important to highlight that our method operates with approximately $\frac{1}{4}$ of the FLOPs compared to VAR, indicating a significant computational efficiency.

#### Design choices.

We further demonstrate the impact of several design choices for our Imagefolder. As Tab 6 shown, (1) quantizer dropout can significantly improve the capacity of our tokenizer, but if we drop too many quantizers during training, it will unstabilize the training of our tokenizer and cause degradation. (2) Quantizer dropout will force the model to reconstruct the image with different bitrates while a too-large ratio will make the model focus too much on the intermediate outputs thus impacting the reconstruction of the last layer. (3) Increasing the number of branches can further improve the reconstruction quality whereas too many branches in the product quantizer also harm the quality of our generation, e.g., 5.24 gFID for 4 branch quantizer. (4) The use of semantic loss can facilitate the image quality for our tokenizer.

#### Visualization.

We demonstrate qualitative visualization of the generative model trained with ImageFolder as shown in Fig. 9. The classes of generated images are among the ImageNet Deng et al. () dataset with a resolution of $256\times 256$.

## 5 Conclusion

Limitations.
Though the effectiveness of ImageFolder has been verified with extensive experiments, the tokenizer performance can be further improved with a more advanced training scheme which will be our focus in the short future.

In this paper, we introduced ImageFolder, a novel semantic image tokenizer designed to balance the trade-off between token length and reconstruction quality in autoregressive modeling. By folding spatially aligned tokens, ImageFolder achieves a shorter token sequence while maintaining high generation and reconstruction performance. Through our innovative use of product quantization and the introduction of semantic regularization and quantizer dropout, we demonstrated significant improvements in the representation of image tokens. Our extensive experiments have validated the effectiveness of these approaches, shedding light on the relationship between token length and visual generation quality. ImageFolder offers a promising direction for more efficient integration of visual generation tasks to AR models/large language models.

## Appendix

## Appendix A Why do we need top-k-top-p sampling?

Figure: Figure 10: Top-k top-p sampling visualization
Refer to caption: x10.png

Top-k and top-p sampling have proven to be effective methods for controlling randomness and diversity in the output of autoregressive (AR) models. In transformer-based image generation, top-k sampling selects tokens from the top $k$ most likely candidates at each step, truncating the probability distribution to avoid low-probability tokens that could degrade image quality. Top-p sampling, on the other hand, dynamically adjusts the sampling pool by selecting tokens whose cumulative probability exceeds a predefined threshold, ensuring a balance between flexibility and diversity in the generation process.

In our approach, we separately sample the semantic and detail tokens using top-k and top-p sampling from the same logit. Since this method assumes the independence of the two token types, we aim to prevent situations where one token is selected from a high-probability region while the other comes from a low-probability region. Specifically, as illustrated in Fig. 10, top-k and top-p sampling allows us to select tokens from regions where both semantic and detail tokens have high probabilities, ensuring consistent image quality.

## Appendix B Evaluation Metrics and Dataset Details

Fréchet Inception Distance (FID) Heusel et al. ().
FID measures the distance between real and generated images in the feature space of an ImageNet-1K pre-trained classifier Szegedy et al. (), indicating the similarity and fidelity of the generated images to real images.

Inception Score (IS) Salimans et al. ().
IS also measures the fidelity and diversity of generated images.
It consists of two parts: the first part measures whether each image belongs confidently to a single class of an ImageNet-1K pre-trained image classifier Szegedy et al. () and the second part measures how well the generated images capture diverse classes.

Precision and Recall Kynkäänniemi et al. ().
The real and generated images are first converted to non-parametric representations of the manifolds using k-nearest neighbors, on which the Precision and Recall can be computed.
Precision is the probability that a randomly generated image from estimated generated data manifolds falls within the support of the manifolds of estimated real data distribution.
Recall is the probability that a random real image falls within the support of generated data manifolds.
Thus, precision measures the general quality and fidelity of the generated images, and recall measures the coverage and diversity of the generated images.

#### ImageNet dataset.

The ImageNet dataset Deng et al. () is a large-scale visual database designed for use in visual object recognition research. It contains over 14 million images, which are organized into thousands of categories based on the WordNet hierarchy. Each image is annotated with one or more object labels, making it a valuable resource for training and evaluating machine learning models in various computer vision tasks, such as image classification, object detection, and image generation. Its training set contains approximately 1.28 million images spanning 1,000 classes. Its validation set contains 50,000 images, with 50 images per class across the same 1,000 classes.

## Appendix C Visualizations

We provide additional visualizations as shown in Fig. 11 and Fig. 12.

Figure: Figure 11: More visualization for demonstrating the effectiveness of quantizer dropout.
Refer to caption: x11.png

Figure: Figure 12: More visualization for zero-shot conditional image generation. During generation sampling, we teacher forcing all detail tokens to referenced detail tokens.
Refer to caption: x12.png

## Appendix D Teacher Forcing Guidance for Conditional Generation

Classifier-free guidance has been proven to be effective in AR models Chang et al. () which take the same form as diffusion models as

$$ $\displaystyle p(I|C,c,c_{t})\propto p(c|I,C,c_{t})p(c_{t}|I,C)p(C|I)p(I).$ $$

In ControlVAR, we model the joint distribution of the controls and images. Therefore, we leverage a different extension of the probabilities as

$$ $p(c|I,C,c_{t})=\frac{p(I,C|c,c_{t})p(c,c_{t})}{p(I,C|c_{t})p(c_{t})}=\frac{p(I ,C|c,c_{t})p(c)}{p(I,C|c_{t})}$ $$

where $p(I,C|c,c_{t})$ and $p(I,C|c,c_{t})$ can be found from the output of ControlVAR. We follow previous works Esser et al. () to ignore the constant probabilities $p(c)$. By rewriting all terms with Baysian rule, we have

$$ $\displaystyle\log p(I|C,c,c_{t})\propto$ $\displaystyle\log p(I)$ $\displaystyle+$ $\displaystyle\log p(I,C|c,c_{t})-\log p(I,C|c_{t})$ $\displaystyle+$ $\displaystyle\log p(I,C|c_{t})-\log p(I,C)$ $\displaystyle+$ $\displaystyle\log p(I,C)-\log p(I).$ $$

This corresponds to the image logits as

$$ $\displaystyle x^{*}=x(\Rsh\!\!\emptyset|\emptyset,\emptyset)$ $\displaystyle+\gamma_{cls}(x(\Rsh\!\!C|c,c_{t})-x(\Rsh\!\!C|\emptyset,c_{t}))$ (6) $\displaystyle+\gamma_{typ}(x(\Rsh\!\!C|\emptyset,c_{t})-x(\Rsh\!\!C|\emptyset, \emptyset))$ $\displaystyle+\gamma_{pix}(x(\Rsh\!\!C|\emptyset,\emptyset)-x(\Rsh\!\! \emptyset|\emptyset,\emptyset))$ $$

where $\gamma_{cls},\gamma_{typ},\gamma_{pix}$ are guidance scales for controlling the generation.

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 5
presentation: 3
questions: - To better understand the method, the authors should add more analysis about the proposed tokenizer, such as the perplexity (codebook usage) with different techniques.

 -  Although this work primarily experiments with autoregressive modeling, the tokenizer does not seem to be particularly designed for AR modeling. How would this tokenizer perform on other generative schemes, such as diffusion, and non-autoregressive modeling?
soundness: 3
strengths: - This paper targets learning more semantically compact and disentangled image token representations, which leads to better autoregressive modeling with improved performance and shorter token length. The issue of information density(token length) and the explanation of previous image tokenizers have been hindering the performance of visual autoregressive modeling.

  - Compared to previous work on image tokenizers, this work investigates product quantization to separate different information about images. With the proposed muti-scale RQ, semantic regularization, and quantizer dropout, the representation of image tokens is enhanced.

 - Extensive experiments on autoregressive modeling and visualization demonstrate the superiority of ImageFold.
summary: - This paper presents a semantic image tokenizer that provides better token representations for visual autoregressive modeling, with improved generation quality and efficiency. 

 - The authors leverage product quantization and semantic regularization for a more compact representation. Extensive experiments demonstrate the advantage of the proposed tokenizer over previous ones.
weaknesses: - Several important components in this work have been investigated in previous works, including adopting semantic regularization, multi-scale RQ, and parallel decoding has been explored in earlier works. 

 - This work lacks either enough theoretical or empirical discussions about product quantization.  Additional details, such as more visualization and discussion as in Fig. 8, should be provided to validate the "disentangled" nature of the obtained image tokens.  (see Questions)

 - This work missed some important references. Although product quantization has been rarely discussed in image tokenizers. Previous works[1] on tokenizing other modalities such as audio have adopted relevant strategies. 

[1] Addressing Index Collapse of Large-Codebook Speech Tokenizer with Dual-Decoding Product-Quantized Variational Auto-Encoder.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: Please solve the problem I mentioned above
soundness: 4
strengths: 1. The idea of this paper is novel. Through Product Quantization, token processing is carried out in smaller spaces, and good performance is achieved under fewer tokens.
2. The logic of this paper is rigorous, the argumentation is clear, the method is fully explained, and the experimental setting is rigorous.
summary: This paper proposes a novel method to solve the problem of how to improve image quality under finite length tokens, and proposes a semantic tokenizer, which realizes good image quality under smaller length tokens through Product Quantization.
weaknesses: Although this paper has reached an acceptable level, there are still several small problems that need to be worked on.
1. The description of performance indicators in the article is not in place. Tables 1, 2 and some later tables do not give a simple indication of superior performance represented by high or low indicators.
2. In Formula 4, the description of several hyperparameters and their Settings is missing.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: 1.The training is based on the tokenizer from LlamaGen. Is it possible to train one from scratch to better demonstrate its effectiveness?

2.How is the token length of 265 derived from the residual scales [1, 1, 2, 3, 3, 4, 5, 6, 8, 11]?

3.Are there other length design comparisons for token length, such as 265, 430, etc., to better validate the results?
soundness: 3
strengths: 1.The ImageFolder tokenizer achieves better generation performance by effectively folding tokens, which enhances the efficiency of the autoregressive modeling process.

2.Despite reducing token length, the proposed method does not sacrifice the quality of image reconstruction, making it a balanced solution for generative tasks.

3.By leveraging product quantization and introducing mechanisms like semantic regularization and quantizer dropout, the tokenizer captures richer semantic and pixel-level information, leading to more accurate image representations.

4.The paper provides extensive experimental results that validate the effectiveness of the proposed method, offering a solid foundation for its claims and demonstrating its superiority over existing tokenizers.

5.The investigation into the trade-off between generation and reconstruction quality with respect to token length contributes to a better understanding of the dynamics involved in image generation, which can inform future research in the field.
summary: This paper introduces a novel image tokenizer called ImageFolder, which addresses the trade-off between image reconstruction quality and generation quality in visual generative models, such as diffusion models and autoregressive (AR) models. The key contributions of the paper can be summarized as follows: 1. The proposed tokenizer provides spatially aligned image tokens that can be folded during autoregressive modeling, resulting in a shorter token length without compromising reconstruction or generation quality. The experiments demonstrate that folded tokens outperform unfolded ones in terms of generation performance, even when the overall token count remains the same. 2. The paper explores the use of product quantization within the image tokenizer. It introduces semantic regularization and quantizer dropout to enhance the representational capability of the quantized image tokens by separately capturing semantic information and pixel-level details. 3. Extensive experiments are conducted to investigate the relationship between token length, generation quality, and reconstruction quality, providing deeper insights into the image generation process in AR modeling.
weaknesses: 1.The training is based on the tokenizer from LlamaGen. Is it possible to train one from scratch to better demonstrate its effectiveness?

2.How is the token length of 265 derived from the residual scales [1, 1, 2, 3, 3, 4, 5, 6, 8, 11]?

3.Are there other length design comparisons for token length, such as 265, 430, etc., to better validate the results?

---

confidence: 4
contribution: 2
initial_rating: 8
presentation: 3
questions: Q1: In Table 1, does “tokens” refer to the number of input tokens or codebook tokens?

Q2: The symbol “L” in “247 quantizer drop” can be confusing as it is also used for patch size in the previous context. Additionally, in Table 3, patch size is denoted as  K=1, which adds to the confusion. Could you clarify this section further? Also, please consider refining the symbol definitions.

Q3: In Figure 5, should the grid size double after each downsampling? Currently, it shows 1x1 to 2x2 to 3x3—how should this be understood? Why does the grid increase with the step size? Also, why does resolution increase from left to right? Is this sequence reversed? Normally, the input has the highest resolution, which decreases as the step deepens.

Q4: In line 273, is dropout necessary for a simple semantic quantizer? Is it possible to dropout only one branch during training, so that we may know which branch will be impacted much more?

Q5: Has contrastive loss been considered using CLIP’s prompt or image features to create a more robust text-image pre-trained model? The paper mentions that DINO’s semantic-rich feature isn’t suitable for image generation. Would using models like CLIP potentially alleviate this issue, making a separate semantic quantizer branch unnecessary?

Q6: In AR modeling, does dividing one token into two sub-tokens and computing losses for each mean we are increasing the token count without lengthening the token length? Line 408, mentions increasing the token count without enlarging the token length, yet line 340 states that a shorter token length benefits quality while keeping the token count the same. Could you clarify this part?

Q7: A smaller patch size ( k=1 ) impacts performance significantly. Is this necessary, and have you tried other designs or experiments around patch size?

Q8: Could you add a comparison of different tokenizer performances for better illustration, such as comparisons with different VAEs and token quantizers?

Q9: In the 4-branch quantizer, how is the contrastive loss applied? Does this only worsen gFID in your results?
soundness: 3
strengths: 1. The paper is well-structured, comprehensive, and easy to understand, making the proposed concepts accessible.

2. It presents a novel approach to decoupling features using separated quantizers and manages both the separated quantizers and input features through product quantization.

3. This approach effectively mitigates the performance drop observed in previous work caused by incorporating semantic features.

4. The model achieves comparable performance to state-of-the-art (SOTA) methods, demonstrating the efficacy of the proposed method.

5. Overall, the paper offers valuable insights and design strategies for quantizer development, contributing to advancements in feature token quantization.
summary: The paper is well-structured, comprehensive, and easy to understand, making the proposed concepts accessible. It presents a novel approach to decoupling features using separated quantizers and manages both the separated quantizers and input features through product quantization. Overall, the paper offers valuable insights and design strategies for quantizer development, contributing to advancements in feature token quantization.
weaknesses: 1. The results section lacks a comprehensive comparison with a broader range of current state-of-the-art VAE and autoregressive (AR) token quantizers. Including such comparisons would provide stronger validation of the method’s performance.

2. In the main paper, the VAR model training has not reached final results, only intermediate outcomes are presented. Showing the final results would strengthen the evaluation.

3. In terms of ablation studies, the paper would benefit from additional experiments that test the model with only the semantic branch or only the detail branch under the same experimental setting. Additionally, showing results where only a single branch incorporates semantic information would provide a more complete analysis of the method’s effectiveness.

4. Finally, presenting quantizer dropout—a popular regularization technique—as a primary contribution does not seem particularly solid.

Meta-review: This paper introduces a novel image tokenizer, ImageFolder, which improves the balance between image reconstruction quality and generation quality in visual generative models like diffusion models and autoregressive models. Key contributions include spatially aligned tokens for better generation, product quantization with semantic regularization for enhanced representational capability, and insights into the relationship between token length and quality in image generation.

Decision: Accept (Poster)