Exploiting Discriminative Codebook Prior for Autoregressive Image Generation

Longxiang Tang, Ruihang Chu, Xiang Wang, Yujin Han, Pingyu Wu, Chunming He, Yingya Zhang, Shiwei Zhang, Jiaya JiaarXiv 2025 · DOI

Abstract

Autoregressive (AR) models for image generation typically rely on discrete codebooks to represent visual information. However, standard training paradigms often treat these tokens as independent categories, ignoring the semantic relationships between them. While previous research utilized k-means clustering to group similar tokens, this approach is hindered by non-uniform token distributions and high-dimensional distance inaccuracies. We present the Discriminative Codebook Prior Extractor (DCPE), a density-aware clustering method that employs agglomerative merging and instance-based distances. DCPE significantly improves training efficiency—achieving up to a 42% speedup—and enhances generation quality across various model scales on the ImageNet-1K benchmark.

Introduction: The Challenge of Tokenized Image Generation

Modern image generation often follows an autoregressive paradigm, similar to Large Language Models (LLMs). An image is first "tokenized" into a grid of discrete indices using a pre-trained codebook. A Transformer then learns to predict these indices sequentially. A key challenge is that while the codebook contains rich feature vectors where semantically similar patches are proximal, the AR model usually only sees raw indices (e.g., "Token #42"), treating all tokens as equally distinct.

Recent attempts to incorporate semantic similarity used k-means clustering to group tokens. However, the authors demonstrate that k-means is ill-suited for codebook spaces due to two primary issues:

  1. Token Space Disparity: Codebook features are not uniformly distributed; dense regions of similar tokens are often incorrectly split, while unrelated sparse regions may be lumped together.
  2. Centroid Distance Inaccuracy: In high-dimensional spaces, the "average" (centroid) of a cluster often falls into a low-density region that does not represent any real image feature, making distance-based assignments unreliable.
Visualization of k-means failure modes: Token Space Disparity and Centroid Distance Inaccuracy.

Methodology: Discriminative Codebook Prior Extractor (DCPE)

The proposed DCPE method extracts the prior knowledge hidden in the codebook more effectively by moving away from the flaws of k-means. It introduces two key technical shifts:

  • Agglomerative (Bottom-Up) Merging: Instead of starting with random centroids, DCPE begins with every token in its own cluster and iteratively merges the most similar groups. This density-aware strategy preserves high-density regions of similar tokens.
  • Instance-Based Distance: Rather than calculating distances to a synthetic central point, DCPE calculates the average distance between all individual members of two clusters, respecting the complex underlying manifold of the feature space.

To ensure practical utility, the authors optimized the algorithm into a high-speed PyTorch implementation, reducing the processing time for a 16k-sized codebook from over 4 hours to just 39.6 seconds.

Integration of DCPE into the Causal Transformer pipeline, showing the mapping from token indices to cluster indices and the resulting improvement in generation quality (gFID).

Experimental Results

The authors evaluated DCPE on the ImageNet-1K dataset using the LlamaGen model family, ranging from Base (111M parameters) to XL (775M parameters). The quantitative improvements are substantial:

  • Training Speedup: On the LlamaGen-Base model, DCPE reached the baseline's best Fréchet Inception Distance (FID) 42% faster and its best Inception Score (IS) 55% faster.
  • Quality Boost: When trained for the same duration, DCPE improved the FID of LlamaGen-B from 5.29 to 4.83 and the IS from 185.7 to 198.8.
  • Scalability: These benefits were consistent across larger models (L and XL), where DCPE outperformed both vanilla baselines and k-means-based variants.

Discussion and Limitations

While highly effective, DCPE utilizes a "greedy" agglomerative strategy, which does not strictly guarantee a globally optimal clustering solution. Furthermore, because DCPE allows clusters to vary in size, it can lead to imbalanced gradients during training. The authors currently use a size-capping heuristic to mitigate this but suggest that more elegant balancing solutions could be developed. Future research will explore the application of these discriminative priors to more complex text-to-image tasks.

Summary updated

BibTeX
@misc{tang2025exploiting,
  author = {Longxiang Tang and Ruihang Chu and Xiang Wang and Yujin Han and Pingyu Wu and Chunming He and Yingya Zhang and Shiwei Zhang and Jiaya Jia},
  title = {{Exploiting Discriminative Codebook Prior for Autoregressive Image Generation}},
  year = {2025},
  eprint = {2508.10719},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.10719},
}
Figure