[论文翻译]VAR视觉自回归建模:通过下一尺度预测生成可扩展的图像


原文地址:https://arxiv.org/abs/2404.02905

代码地址:https://github.com/FoundationVision/VAR

Visual Autoregressive Modeling:  Scalable Image Generation via Next-Scale Prediction

Keyu Tian^1,2^ , Yi Jiang^2,†^ , Zehuan Yuan^2,∗^ , Bingyue Peng^2^ , Liwei Wang^1,^
^1^ Peking University   ^2^ Bytedance Inc
keyutian@stu.pku.edu.cn, jiangyi.enjoy@bytedance.com,
yuanzehuan@bytedance.com, bingyue.peng@bytedance.com, wanglw@pku.edu.cn
Try and explore our online demo at:   https://var.vision
Codes and models:   https://github.com/FoundationVision/VAR
Corresponding authors:  wanglw@pku.edu.cn, yuanzehuan@bytedance.com;  †: project lead

摘要

We present Visual AutoRegressive modeling (VAR), a new generation paradigm that redefines the autoregressive learning on images as coarse-to-fine “next-scale prediction” or “next-resolution prediction”, diverging from the standard raster-scan “next-token prediction”. This simple, intuitive methodology allows autoregressive (AR) transformers to learn visual distributions fast and can generalize well: VAR, for the first time, makes GPT-style AR models surpass diffusion transformers in image generation. On ImageNet 256×256 benchmark, VAR significantly improve AR baseline by improving Fréchet inception distance (FID) from 18.65 to 1.73, inception score (IS) from 80.4 to 350.2, with 20× faster inference speed. It is also empirically verified that VAR outperforms the Diffusion Transformer (DiT) in multiple dimensions including image quality, inference speed, data efficiency, and scalability. Scaling up VAR models exhibits clear power-law scaling laws similar to those observed in LLMs, with linear correlation coefficients near −0.998 as solid evidence. VAR further showcases zero-shot generalization ability in downstream tasks including image in-painting, out-painting, and editing. These results suggest VAR has initially emulated the two important properties of LLMs: Scaling Laws and zero-shot generalization. We have released all models and codes to promote the exploration of AR/VAR models for visual generation and unified learning.

我们提出了视觉自回归建模(VAR),这是一种新一代范式,它将图像的自回归学习重新定义为从粗到细的“下一个尺度预测”或“下一个分辨率预测”,与标准光栅扫描预测下一个Token 不同。 这种简单、直观的方法使自回归 (AR) 转换器能够快速学习视觉分布,并且可以很好地泛化:VAR第一次使 GPT 式 AR 模型在图像生成方面超越了扩散转换器。 在 ImageNet 256×256 基准测试中,VAR 通过将 Fréchet inception distance (FID) 从 18.65 提高到 1.73,inception score (IS) 从 80.4 提高到 350.2,显著提高了 AR 基线,推理速度提高了 20×倍。 实证还验证了 VAR 在图像质量、推理速度、数据效率和可扩展性等多个维度上均优于 Diffusion Transformer (DiT)。 放大 VAR 模型表现出与大语言模型中观察到的清晰的幂律缩放定律,其中线性相关系数接近−0.998作为确凿的证据。 VAR 进一步展示了零样本在图像修复、修复和编辑等下游任务中的泛化能力。 这些结果表明 VAR 初步模拟了大语言模型的两个重要特性:缩放定律和零样本泛化。 我们已经发布了所有模型和代码,以推动 AR/VAR 模型在视觉生成和统一学习方面的探索。

Refer to caption图 1:从在 ImageNet 上训练的视觉自回归 (VAR) 转换器生成的样本. 我们展示了 512×512 个样本(顶部)、256×256 个样本(中间)和零样本图像编辑结果(底部)。

Refer to caption

图 2: 标准自回归模型 (AR) 与 我们提出的视觉自回归模型 (VAR)。 (a) AR 应用于语言:从左到右、逐字生成顺序文本词符; (b) AR 应用于图像:以光栅扫描顺序从左到右、从上到下连续生成视觉词符; (c) 图像的 VAR:多尺度词符图是从粗到细尺度(从低到高分辨率)自回归生成的,每个尺度内并行生成词符。 VAR 需要多尺度 VQVAE 才能发挥作用。

1简介

The advent of GPT series [65, 66, 15, 62, 1] and more autoregressive (AR) large language models (LLMs) [22, 4, 38, 82, 83, 90, 78, 5, 79] has heralded a new epoch in the field of artificial intelligence. These models exhibit promising intelligence in generality and versatility that, despite issues like hallucinations [39], are still considered to take a solid step toward the general artificial intelligence (AGI). At the core of these models is a self-supervised learning strategy – predicting the next token in a sequence, a simple yet profound approach. Studies into the success of these large AR models have highlighted their scalability and generalizabilty: the former, as exemplified by scaling laws [43, 35], allows us to predict large model’s performance from smaller ones and thus guides better resource allocation, while the latter, as evidenced by zero-shot and few-shot learning [66, 15], underscores the unsupervised-trained models’ adaptability to diverse, unseen tasks. These properties reveal AR models’ potential in learning from vast unlabeled data, encapsulating the essence of “AGI”.

GPT 系列[65, 66, 15, 62, 1]以及更多自回归 (AR) 大语言模型 (LLM)[22, 4, 38, 82, 83, 90, 78, 5, 79]的出现,预示着人工智能领域一个新时代的到来。 这些模型在通用性和多功能性方面展现出令人鼓舞的智能,尽管存在诸如幻觉[39]等问题,但仍被认为朝着通用人工智能 (AGI)迈出了坚实的一步。 这些模型的核心是一种自监督学习策略——预测序列中的下一个符元,这是一种简单而深刻的方法。 对这些大型 AR 模型的成功的研究强调了它们的可扩展性和泛化能力:前者,正如缩放法则[43, 35]所例证的那样,允许我们根据较小的模型预测大型模型的性能,从而指导更好的资源分配;而后者,正如零样本和少样本学习[66, 15]所证明的那样,强调了无监督训练模型对不同未见任务的适应性。 这些特性揭示了 AR 模型从大量未标记数据中学习的潜力,概括了“AGI”的本质。

In parallel, the field of computer vision has been striving to develop large autoregressive or world models [58, 57, 6], aiming to emulate their impressive scalability and generalizability. Trailblazing efforts like VQGAN and DALL-E [30, 67] along with their successors [68, 92, 50, 99] have showcased the potential of AR models in image generation. These models utilize a visual tokenizer to discretize continuous images into grids of 2D tokens, which are then flattened to a 1D sequence for AR learning (Fig. 2 b), mirroring the process of sequential language modeling (Fig. 2 a). However, the scaling laws of these models remain underexplored, and more frustratingly, their performance significantly lags behind diffusion models [63, 3, 51], as shown in Fig. 3. In contrast to the remarkable achievements of LLMs, the power of autoregressive models in computer vision appears to be somewhat locked.

与此同时,计算机视觉领域一直在努力开发大型自回归或世界模型[58, 57, 6],旨在模仿其令人印象深刻的可扩展性和泛化能力。 VQGAN 和 DALL-E[30, 67]等开创性工作及其后续工作[68, 92, 50, 99]展示了 AR 模型在图像生成方面的潜力。 这些模型利用视觉标记器将连续图像离散化为 2D 符元的网格,然后将其展平为 1D 序列以进行 AR 学习(图2 b),这反映了顺序语言建模的过程(图2 a)。 然而,这些模型的缩放法则仍未得到充分探索,更令人沮丧的是,它们的性能明显落后于扩散模型[63, 3, 51],如图3所示。 与大语言模型的卓越成就相比,自回归模型在计算机视觉领域的威力似乎有些锁定。

Refer to caption图 3:缩放行为 不同模型族在 ImageNet 256×256 生成基准测试上的结果。 验证集的 FID 作为参考下限 (1.78)。 具有 20 亿参数的 VAR 达到了 1.73 的 FID,超过了具有 30 亿或 70 亿参数的 L-DiT。

Autoregressive modeling requires defining the order of data. Our work reconsiders how to “order” an image: Humans typically perceive or create images in a hierachical manner, first capturing the global structure and then local details. This multi-scale, coarse-to-fine nature suggests an “order” for images. Also inspired by the widespread multi-scale designs [54, 52, 81, 44], we define autoregressive learning for images as “next-scale prediction” in Fig. 2 (c), diverging from the conventional “next-token prediction” in Fig. 2 (b). Our approach begins by encoding an image into multi-scale token maps. The autoregressive process is then started from the 1×1 token map, and progressively expands in resolution: at each step, the transformer predicts the next higher-resolution token map conditioned on all previous ones. We refer to this methodology as Visual AutoRegressive (VAR) modeling.

自回归建模需要定义数据的顺序。 我们的工作重新考虑了如何“排序”图像:人类通常以分层的方式感知或创建图像,首先捕捉全局结构,然后捕捉局部细节。 这多尺度、从粗到细的特性暗示了图像的“顺序”。 同样受广泛应用的多尺度设计[54, 52, 81, 44]的启发,我们在图2 (c)中将图像的自回归学习定义为“下一尺度预测”,这与图2 (b)中的传统“下一个符元预测”不同。 我们的方法首先将图像编码为多尺度词符图。 然后,自回归过程从 1×1 词符图开始,并逐步扩展分辨率:在每一步,Transformer 都会以所有先前的词符图为条件来预测下一个更高分辨率的词符图。 我们将此方法称为视觉自回归 (VAR) 建模。

VAR directly leverages GPT-2-like transformer architecture [66] for visual autoregressive learning. On the ImageNet 256×256 benchmark, VAR significantly improves its AR baseline, achieving a Fréchet inception distance (FID) of 1.73 and an inception score (IS) of 350.2, with inference speed 20× faster (see Sec. 7 for details). Notably, VAR surpasses the Diffusion Transformer (DiT) – the foundation of leading diffusion systems like Stable Diffusion 3.0 and SORA [29, 14] – in FID/IS, data efficiency, inference speed, and scalability. VAR models also exhibit scaling laws akin to those witnessed in LLMs. Lastly, we showcase VAR’s zero-shot generalization capabilities in tasks like image in-painting, out-painting, and editing. In summary, our contributions to the community include:

VAR 直接利用类似 GPT-2 的 Transformer 架构[66]进行视觉自回归学习。 在 ImageNet 256×256 基准测试中,VAR 显著提升了其自回归基线,实现了 1.73 的 Fréchet 起始距离(FID)和 350.2 的起始分数(IS),推理速度快了 20×倍(详情见第7节)。 值得注意的是,VAR 在 FID/IS、数据效率、推理速度和可扩展性方面均超越了扩散 Transformer (DiT)——这是 Stable Diffusion 3.0 和 SORA[29, 14]等领先扩散系统的基础。 VAR 模型还表现出类似于大语言模型中所见的缩放定律。 最后,我们展示了 VAR 在图像修复、修复和编辑等任务中的零样本泛化能力。 总而言之,我们对社区的贡献包括:

  1. A new visual generative framework using a multi-scale autoregressive paradigm with next-scale prediction, offering new insights in autoregressive algorithm design for computer vision.
  2. An empirical validation of VAR models’ Scaling Laws and zero-shot generalization potential, which initially emulates the appealing properties of large language models (LLMs).
  3. A breakthrough in visual autoregressive model performance, making GPT-style autoregressive methods surpass strong diffusion models in image synthesis for the first time^1^ ^1^ A related work [95] named “language model beats diffusion” belongs to BERT-style masked-prediction model..
  4. A comprehensive open-source code suite, including both VQ tokenizer and autoregressive model training pipelines, to help propel the advancement of visual autoregressive learning.

一种新的视觉生成框架,使用具有下一尺度预测的多尺度自回归范例,为计算机视觉的自回归算法设计提供了新的见解。

对 VAR 模型的缩放定律和零样本泛化潜力的实证验证,初步模拟了大语言模型(大语言模型)的吸引人的特性。

视觉自回归模型性能的突破,使得 GPT 式自回归方法在图像合成方面超越强扩散模型 首次^1^.

全面的开源代码套件,包括 VQ 分词器和自回归模型训练管道,有助于推动视觉自回归学习的进步。

2相关工作

2.1大型自回归语言模型的属性 Properties of large autoregressive language models

Scaling laws  are found and studied in autoregressive language models [43, 35], which describe a power-law relationship between the scale of model (or dataset, computation, etc.) and the cross-entropy loss value on the test set. Scaling laws allow us to directly predict the performance of a larger model from smaller ones [1], thus guiding better resource allocation. More pleasingly, they show that the performance of LLMs can scale well with the growth of model, data, and computation and never saturate, which is considered a key factor in the success of [15, 82, 83, 98, 90, 38]. The success brought by scaling laws has inspired the vision community to explore more similar methods for multimodality understanding and generation [53, 2, 88, 27, 96, 77, 21, 23, 41, 31, 32, 80, 87].

在自回归语言模型[43, 35]中发现了并研究了缩放定律,这些定律描述了模型规模(或数据集、计算等)与测试集上的交叉熵损失值之间的幂律关系。 缩放定律使我们能够直接根据较小的模型预测较大模型的性能[1],从而指导更好的资源分配。 更令人欣喜的是,它们表明 LLM 的性能可以随着模型、数据和计算的增长而很好地扩展,并且不会饱和,这被认为是[15, 82, 83, 98, 90, 38]成功的关键因素。 缩放定律带来的成功启发了计算机视觉领域探索更多类似的方法,用于多模态理解和生成[53, 2, 88, 27, 96, 77, 21, 23, 41, 31, 32, 80, 87]。

Zero-shot generalization.  Zero-shot generalization [72] refers to the ability of a model, particularly a Large Language Model, to perform tasks that it has not been explicitly trained on. Within the realm of the computer vision, there is a burgeoning interest in the zero-shot and in-context learning abilities of foundation models, CLIP [64], SAM [48], Dinov2 [61]. Innovations like Painter [89] and LVM [6] extend visual prompters [40, 11] to achieve in-context learning in vision.

零样本生成。  零样本泛化[72]是指模型,特别是大型语言模型,执行其未明确训练过的任务的能力。 在计算机视觉领域,人们对基础模型 CLIP[64]、SAM[48]、Dinov2[61]的零样本和上下文学习能力越来越感兴趣。 像 Painter[89]和 LVM[6]这样的创新将视觉提示符[40, 11]扩展到在视觉中实现上下文学习。

2.2视觉生成 Visual generation

Raster-scan autoregressive models  for visual generation necessitate the encoding of 2D images into 1D token sequences. Early endeavors [20, 84] have shown the ability to generate RGB (or grouped) pixels in the standard row-by-row, raster-scan manner. [69] extends [84] by using multiple independent trainable networks to do super-resolution repeatedly. VQGAN [30] advances [20, 84] by doing autoregressive learning in the latent space of VQVAE [85]. It employs GPT-2 decoder-only transformer to generate tokens in the raster-scan order, like how ViT [28] serializes 2D images into 1D patches. VQVAE-2 [68] and RQ-Transformer [50] also follow this raster-scan manner but use extra scales or stacked codes. Parti [93], based on the architecture of ViT-VQGAN [92], scales the transformer to 20B parameters and works well in text-to-image synthesis.

光栅扫描自回归模型用于视觉生成,需要将二维图像编码为一维符元序列。 早期的尝试[20, 84]已经展示了以标准的行扫描方式生成 RGB(或分组)像素的能力。 [69]通过使用多个独立的可训练网络重复进行超分辨率来扩展[84]。 VQGAN[30]通过在 VQVAE[85]的潜在空间中进行自回归学习来改进[20, 84]。 它采用 GPT-2 解码器仅有的 Transformer 以光栅扫描顺序生成符元,就像 ViT[28]将二维图像序列化为一维块一样。 VQVAE-2 [68]和 RQ-Transformer [50]也遵循这种光栅扫描方式,但使用了额外的尺度或堆叠代码。 Parti [93]基于 ViT-VQGAN [92]的架构,将 Transformer 的规模扩展到 200 亿个参数,并在文本到图像的合成中表现良好。

Masked-prediction model.  MaskGIT [17] employs a VQ autoencoder and a masked prediction transformer similar to BERT [25, 10, 34] to generate VQ tokens through a greedy algorithm. MagViT [94] adapts this approach to videos, and MagViT-2 [95] enhances [17, 94] by introducing an improved VQVAE for both images and videos. MUSE [16] further scales MaskGIT to 3B parameters.

掩模预测模型。  MaskGIT [17]采用 VQ 自动编码器和类似于 BERT [25, 10, 34]的掩码预测 Transformer,通过贪婪算法生成 VQ 符元。 MagViT [94]将这种方法应用于视频,而 MagViT-2 [95]通过引入改进的 VQVAE 来增强图像和视频的[17, 94]。 MUSE [16]进一步将 MaskGIT 的规模扩展到 30 亿个参数。

Diffusion models ’ progress has centered around improved learning or sampling [76, 75, 55, 56, 7], guidance [37, 60], latent learning [70], and architectures [36, 63, 71, 91]. DiT and U-ViT [63, 8] replaces or integrates the U-Net with transformer, and inspires recent image [19, 18] or video synthesis systems [12, 33] including Stable Diffusion 3.0 [29], SORA [14], and Vidu [9].

扩散模型的进展主要集中在改进学习或采样[76, 75, 55, 56, 7]、引导[37, 60]、潜在学习[70]和架构[36, 63, 71, 91]方面。 DiT 和 U-ViT [63, 8]用 Transformer 替换或集成 U-Net,并启发了最近的图像[19, 18]或视频合成系统[12, 33],包括 Stable Diffusion 3.0 [29]、SORA [14]和 Vidu [9]。

3方法

3.1初步:通过下一个标记预测进行自回归建模 Preliminary: autoregressive modeling via next-token prediction

Formulation.  Consider a sequence of discrete tokens x=(x1,x2,…,xT), where xt∈[V] is an integer from a vocabulary of size V. The next-token autoregressive posits the probability of observing the current token xt depends only on its prefix (x1,x2,…,xt−1). This unidirectional token dependency assumption allows for the factorization of the sequence x’s likelihood:

公式化。   考虑一个离散符元序列x=(x1,x2,…,xT),其中xt∈[V]是从大小为V的词汇表中选择的整数。下一个符元的自回归假设观察到当前符元xt的概率仅取决于其前缀(x1,x2,…,xt−1)。 这种单向符元依赖性假设允许对序列x的似然进行因式分解:

p⁢(x1,x2,…,xT)=∏t=1Tp⁢(xt∣x1,x2,…,xt−1). (1)

Training an autoregressive model pθ involves optimizing pθ⁢(xt∣x1,x2,…,xt−1) over a dataset. This is known as the “next-token prediction”, and the trained pθ can generate new sequences.

训练自回归模型pθ涉及在一个数据集上优化pθ⁢(xt∣x1,x2,…,xt−1)。 这被称为“下一个符元预测”,训练好的pθ可以生成新的序列。

Tokenization.  Images are inherently 2D continuous signals. To apply autoregressive modeling to images via next-token prediction, we must:  1) tokenize an image into several discrete tokens, and  2) define a 1D order of tokens for unidirectional modeling.  For 1), a quantized autoencoder such as [30] is often used to convert the image feature map f∈ℝh×w×C to discrete tokens q∈[V]h×w:

标记化。  图像本质上是二维连续信号。 要通过下一个标记预测将自回归建模应用于图像,我们必须:1)将图像标记为多个离散标记,2)为单向定义标记的一维顺序造型。  对于 1),通常使用量化的自动编码器,例如[30],将图像特征图f∈ℝh×w×C转换为离散符元q∈[V]h×w:

f=ℰ⁢(i⁢m),q=𝒬⁢(f), (2)

where i⁢m denotes the raw image, ℰ⁢(⋅) a encoder, and 𝒬⁢(⋅) a quantizer. The quantizer typically includes a learnable codebook Z∈ℝV×C containing V vectors. The quantization process q=𝒬⁢(f) will map each feature vector f(i,j) to the code index q(i,j) of its nearest code in the Euclidean sense:

其中 i⁢m 表示原始图像,ℰ⁢(⋅) 表示编码器,𝒬⁢(⋅) 表示量化器。 量化器通常包括可学习的码本Z∈ℝV×C,其中包含V向量。 量化过程 q=𝒬⁢(f) 会将每个特征向量 f(i,j) 映射到欧几里德意义上最接近的代码的代码索引 q(i,j):

q(i,j)=(arg⁢minv∈[V]⁡‖lookup⁢(Z,v)−f(i,j)‖2)∈[V], (3)

其中lookup⁢(Z,v)表示取码本Z中的第v向量。 为了训练量化自动编码器,每个 q(i,j) 都会查找 Z 以获得 f^,即原始 f 的近似值。然后使用给定 f^ 的解码器 𝒟⁢(⋅) 重建新图像 i⁢m^,并最小化复合损失 ℒ:

f^ =lookup⁢(Z,q),i⁢m^=𝒟⁢(f^), (4)
=‖i⁢m−i⁢m^‖2+‖f−f^‖2+λP⁢ℒP⁢(i⁢m^)+λG⁢ℒG⁢(i⁢m^), (5)
- - - - -

where ℒP⁢(⋅) is a perceptual loss such as LPIPS [97], ℒG⁢(⋅) a discriminative loss like StyleGAN’s discriminator loss [46], and λP, λG are loss weights. Once the autoencoder {ℰ,𝒬,𝒟} is fully trained, it will be used to tokenize images for subsequent training of a unidirectional autoregressive model.

The image tokens in q∈[V]h×w are arranged in a 2D grid. Unlike natural language sentences with an inherent left-to-right ordering, the order of image tokens must be explicitly defined for unidirectional autoregressive learning. Previous AR methods [30, 92, 50] flatten the 2D grid of q into a 1D sequence x=(x1,…,xh×w) using some strategy such as row-major raster scan, spiral, or z-curve order. Once flattened, they can extract a set of sequences x from the dataset, and then train an autoregressive model to maximize the likelihood in (1) via next-token prediction.
其中ℒP⁢(⋅)是感知损失,例如 LPIPS [97],ℒG⁢(⋅)是判别损失,例如 StyleGAN 的判别器损失[46],而λP,λG是损失权重。 一旦自动编码器{ℰ,𝒬,𝒟}完全训练完毕,它将用于对图像进行标记,以便随后训练单向自回归模型。

q∈[V]h×w中的图像符元排列在一个二维网格中。 与具有固有的从左到右排序的自然语言句子不同,必须为单向自回归学习明确定义图像标记的顺序。 之前的自动回归方法[30, 92, 50]使用某种策略(例如行主扫描、螺旋形或 Z 曲线顺序)将q二维网格展平为一维序列x=(x1,…,xh×w)。 展平后,它们可以从数据集中提取一组序列x,然后训练一个自回归模型,以通过下一个符元预测来最大化(1)中的似然性。

Discussion on the weakness of vanilla autoregressive models.  The above approach of tokenizing and flattening enable next-token autoregressive learning on images, but introduces several issues:

    Mathematical premise violation.  In quantized autoencoders (VQVAEs), the encoder typically produces an image feature map f with inter-dependent feature vectors f(i,j) for all i,j. So after quantization and flattening, the token sequence (x1,x2,…,xh×w) retains bidirectional correlations. This contradicts the unidirectional dependency assumption of autoregressive models, which dictates that each token xt should only depend on its prefix (x1,x2,…,xt−1).

    Inability to perform some zero-shot generalization.  Similar to issue 1), The unidirectional nature of image autoregressive modeling restricts their generalizability in tasks requiring bidirectional reasoning. E.g., it cannot predict the top part of an image given the bottom part.

    Structural degradation.  The flattening disrupts the spatial locality inherent in image feature maps. For example, the token q(i,j) and its 4 immediate neighbors q(i±1,j), q(i,j±1) are closely correlated due to their proximity. This spatial relationship is compromised in the linear sequence x, where unidirectional constraints diminish these correlations.

    Inefficiency.  Generating an image token sequence x=(x1,x2,…,xn×n) with a conventional self-attention transformer incurs 𝒪⁢(n2) autoregressive steps and 𝒪⁢(n6) computational cost.

Issues 2) and 3) are evident (see examples above). Regarding issue 1), we present empirical evidence in Appendix A. The proof of issue 3) is detailed in Appendix B. These theoretical and practical limitations call for a rethinking of autoregressive models in the context of image generation.

关于普通自回归模型缺点的讨论。  以上的符元化和平展方法能够在图像上进行下一个符元的自回归学习,但是会引入几个问题:

  1. 1)
    违反数学前提。  在量化自动编码器(VQVAEs)中,编码器通常会生成一个图像特征图f,其中包含所有i,j相互依赖的特征向量f(i,j)。 因此,在量化和平展之后,符元序列(x1,x2,…,xh×w)保留了双向相关性。 这与自回归模型的单向依赖假设相矛盾,该假设规定每个词符xt应该仅依赖于其前缀(x1,x2,…,xt−1)。

  2. 2)
    无法进行某些零样本泛化。  与问题 1)类似,图像自回归建模的单向特性限制了其在需要双向推理的任务中的泛化能力。 例如,它无法根据图像底部预测图像顶部。

  3. 3)
    结构退化。  扁平化破坏了图像特征图固有的空间局部性。 例如,符元q(i,j)及其 4 个直接邻居q(i±1,j)、q(i,j±1)由于它们之间的接近性而密切相关。 在线性序列x中,这种空间关系受到损害,其中单向约束会削弱这些相关性。

    低效。   使用传统的自注意力 Transformer 生成图像符元序列x=(x1,x2,…,xn×n)会产生𝒪⁢(n2)自回归步骤和𝒪⁢(n6)计算成本。

问题 2)和 3)是显而易见的(见上面的例子)。 关于问题 1),我们在附录A中提供了经验证据。 问题 3)的证明详见附录B。 这些理论和实践的局限性要求在图像生成的背景下重新思考自回归模型。

Refer to caption
图 4: VAR 包含两个独立的训练阶段。 阶段 1: 一个多尺度矢量量化自动编码器将图像编码成K符元映射R=(r1,r2,…,rK),并通过复合损失进行训练(5)。 关于“多尺度量化”和“嵌入”的详细信息,请查看算法12。   阶段 2: 一个 VAR Transformer 通过下一尺度预测进行训练(6):它以([s],r1,r2,…,rK−1)作为输入来预测(r1,r2,r3,…,rK)。 注意力掩码用于训练,以确保每个rk只能关注r≤k。 使用标准交叉熵损失。

3.2通过下一尺度预测进行视觉自回归建模 Visual autoregressive modeling via next-scale prediction

Reformulation.  We reconceptualize the autoregressive modeling on images by shifting from “next-token prediction” to “next-scale prediction” strategy. Here, the autoregressive unit is an entire token map, rather than a single token. We start by quantizing a feature map f∈ℝh×w×C into K multi-scale token maps (r1,r2,…,rK), each at a increasingly higher resolution hk×wk, culminating in rK matches the original feature map’s resolution h×w. The autoregressive likelihood is formulated as:

重新制定。  我们通过从“下一个 Token 预测”策略转变为“下一个尺度预测”策略,重新概念化了图像的自回归模型。 这里,自回归单元是整个词符图,而不是单个词符。 我们首先将特征图f∈ℝh×w×C量化为K多尺度词符图(r1,r2,…,rK),每个图的分辨率越来越高hk×wk,最终 rK 与原始特征图的分辨率 h×w 匹配。 自回归可能性的公式为:

p⁢(r1,r2,…,rK)=∏k=1Kp⁢(rk∣r1,r2,…,rk−1), (6)

where each autoregressive unit rk∈[V]hk×wk is the token map at scale k containing hk×wk tokens, and the sequence (r1,r2,…,rk−1) serves as the the “prefix” for rk. During the k-th autoregressive step, all distributions over the hk×wk tokens in rk will be generated in parallel, conditioned on rk’s prefix and associated k-th position embedding map. This “next-scale prediction” methodology is what we define as visual autoregressive modeling (VAR), depicted on the right side of Fig. 4. Note that in the training of VAR, a block-wise causal attention mask is used to ensure that each rk can only attend to its prefix r≤k. During inference, kv-caching can be used and no mask is needed.

其中每个自回归单元rk∈[V]hk×wk是尺度为k的符元映射,包含hk×wk个符元,序列(r1,r2,…,rk−1)作为rk的“前缀”。 在第k个自回归步骤中,rk中所有关于hk×wk个符元的分布将并行生成,以rk的前缀和相关的k位置嵌入映射为条件。 我们将这种“下一尺度预测”方法定义为视觉自回归建模(VAR),如图4右侧所示。 请注意,在 VAR 的训练中,使用分块因果注意力掩码来确保每个rk只能关注其前缀r≤k。 在推理过程中,可以使用 kv 缓存,不需要掩码。

Discussion.  VAR addresses the previously mentioned three issues as follows:

    The mathematical premise is satisfied if we constrain each rk to depend only on its prefix, that is, the process of getting rk is solely related to r≤k. This constraint is acceptable as it aligns with the natural, coarse-to-fine progression characteristics like human visual perception and artistic drawing (as we discussed in Sec. 1). Further details are provided in the Tokenization below.

    The spatial locality is preserved as (i) there is no flattening operation in VAR, and (ii) tokens in each rk are fully correlated. The multi-scale design additionally reinforces the spatial structure.

    The complexity for generating an image with n×n latent is significantly reduced to 𝒪⁢(n4), see Appendix for proof. This efficiency gain arises from the parallel token generation in each rk.

讨论。   VAR 解决了前面提到的三个问题:

  1. 1)
    如果我们将每个rk限制为仅依赖其前缀,即获取rk的过程仅与r≤k相关,则满足数学前提。 此约束是可以接受的,因为它与自然的、从粗到细的渐进式特征一致,例如人类的视觉感知和艺术绘画(正如我们在第1节中所讨论的)。 下面的标记化中提供了更多详细信息。
  2. 2)
    空间局部性得以保留,因为 (i) VAR 中没有展平操作,并且 (ii) 每个 rk 中的标记完全相关。 多尺度的设计进一步强化了空间结构。
  3. 3)
    生成具有n×n潜在图像的复杂度显着降低到𝒪⁢(n4),请参阅附录的证明。 这种效率增益来自于每个rk中的并行词符生成。

Tokenization.  We develope a new multi-scale quantization autoencoder to encode an image to K multi-scale discrete token maps R=(r1,r2,…,rK) necessary for VAR learning (6). We employ the same architecture as VQGAN [30] but with a modified multi-scale quantization layer. The encoding and decoding procedures with residual design on f or f^ are detailed in algorithms 1 and 2. We empirically find this residual-style design, akin to [50], can perform better than independent interpolation. Algorithm 1 shows that each rk would depend only on its prefix (r1,r2,…,rk−1). Note that a shared codebook Z is utilized across all scales, ensuring that each rk’s tokens belong to the same vocabulary [V]. To address the information loss in upscaling zk to hK×wK, we use K extra convolution layers {ϕk}k=1K. No convolution is used after downsampling f to hk×wk.

符元化。   我们开发了一种新的多尺度量化自编码器,用于将图像编码为K用于 VAR 学习的多尺度离散符元映射R=(r1,r2,…,rK)(6)。 我们采用与 VQGAN[30]相同的架构,但使用了改进的多尺度量化层。 算法12详细介绍了f或f^上具有残差设计的编码和解码过程。 我们凭经验发现这种类似于[50]的残差式设计,其性能优于独立插值。 算法1显示每个rk仅依赖于其前缀(r1,r2,…,rk−1)。 请注意,所有尺度都使用共享码本Z,确保每个rk的符元属于相同的词汇表[V]。 为了解决在将zk上采样到hK×wK时产生的信息丢失问题,我们使用了K额外的卷积层{ϕk}k=1K。 在将f下采样到hk×wk之后,不使用卷积。

1 Inputs: raw image i⁢m;

2 Hyperparameters: steps K, resolutions (hk,wk)k=1K;

3 f=ℰ⁢(i⁢m), R=[];

4 for k=1,⋯,K do

5 rk=𝒬⁢(interpolate⁢(f,hk,wk));

6 R=queue_push⁢(R,rk);

7 zk=lookup⁢(Z,rk);

8 zk=interpolate⁢(zk,hK,wK);

9 f=f−ϕk⁢(zk);

10

11Return: multi-scale tokens R;

Algorithm 1 Multi-scale VQVAE Encoding

1 Inputs: multi-scale token maps R;

2 Hyperparameters: steps K, resolutions (hk,wk)k=1K;

3 f^=0;

4 for k=1,⋯,K do

5 rk=queue_pop⁢(R);

6 zk=lookup⁢(Z,rk);

7 zk=interpolate⁢(zk,hK,wK);

8 f^=f^+ϕk⁢(zk);

9

10i⁢m^=𝒟⁢(f^);

11 Return: reconstructed image i⁢m^;

Algorithm 2 Multi-scale VQVAE Reconstruction

4实现细节 Implementation details

VAR tokenizer.  As aforementioned, we use the vanilla VQVAE architecture [30] and a multi-scale quantization scheme with K extra convolutions (0.03M extra parameters). We use a shared codebook for all scales with V=4096. Following the baseline [30], our tokenizer is also trained on OpenImages [49] with the compound loss (5) and a spatial downsample ratio of 16×.

VAR transformer.  Our main focus is on VAR algorithm so we keep a simple model architecture design. We adopt the architecture of standard decoder-only transformers akin to GPT-2 and VQGAN [66, 30] with adaptive normalization (AdaLN), which has widespread adoption and proven effectiveness in many visual generative models [46, 47, 45, 74, 73, 42, 63, 19]. For class-conditional synthesis, we use the class embedding as the start token [s] and also the condition of AdaLN. We found normalizing q⁢u⁢e⁢r⁢i⁢e⁢s and k⁢e⁢y⁢s to unit vectors before attention can stablize the training. We do not use advanced techniques in large language models, such as rotary position embedding (RoPE), SwiGLU MLP, or RMS Norm [82, 83]. Our model shape follows a simple rule like [43] that the width w, head counts h, and drop rate d⁢r are linearly scaled with the depth d as follows:

VAR 分词器。  如前所述,我们使用 vanilla VQVAE 架构[30]和具有K额外卷积(0.03M 额外参数)的多尺度量化方案。 我们对所有尺度使用共享码本V=4096。 遵循基线[30],我们的分词器也在 OpenImages[49]上使用复合损失(5)和空间下采样比率16×进行训练。

VAR Transformer 。  我们主要关注 VAR 算法,因此我们保持简单的模型架构设计。 我们采用了类似于 GPT-2 和 VQGAN[66, 30]的标准解码器 Transformer 架构,并使用了自适应归一化(AdaLN),它在许多视觉生成模型中得到了广泛应用并证明了其有效性[46, 47, 45, 74, 73, 42, 63, 19]。 对于类条件合成,我们使用类嵌入作为起始符元[s],也作为 AdaLN 的条件。 我们发现,在注意力之前将q⁢u⁢e⁢r⁢i⁢e⁢s和k⁢e⁢y⁢s归一化为单位向量可以稳定训练。 我们没有使用大语言模型中的高级技术,例如旋转位置嵌入 (RoPE)、SwiGLU MLP 或 RMS Norm [82, 83]。 我们的模型结构遵循类似于[43]的简单规则,其中宽度w、头数h和丢弃率d⁢r与深度d线性缩放,如下所示:

w=64⁢d,h=d,d⁢r=0.1⋅d/24. (7)

因此,深度为d的 VAR Transformer 的主要参数数量N由下式给出:^2^:

N⁢(d)=d⋅4⁢w2⏟self-attention+d⋅8⁢w2⏟feed-forward+d⋅6⁢w2⏟adaptive layernorm=18⁢d⁢w2=73728⁢d3. (8)

所有模型都使用相似的设置进行训练:每个 256 批大小的基础学习率为10−4,使用β1=0.9、β2=0.95、decay=0.05的 AdamW 优化器,批大小从 768 到 1024,训练轮数从 200 到 350(取决于模型大小)。 第5节中的评估表明,这种简单的模型设计能够很好地扩展和泛化。

5 实验结果 Empirical Results

This section first compares VAR with other image generative model families in Sec. 5.1. Evaluations on the scalability and generalizability of VAR models are presented in Sec. 5.2 and Appendix 6. For implementation details and ablation study, please see Appendix 4 and Appendix 7.

本节首先在第5.1节中将 VAR 与其他图像生成模型族进行比较。 VAR 模型的可扩展性和泛化性评估结果在第5.2节和附录6中给出。 有关实现细节和消融研究,请参见附录4和附录7

表格 1:在类条件 ImageNet 256×256 上的生成模型族比较。 “↓”或“↑”表示较低或较高值更好。 指标包括 Fréchet 起始距离 (FID)、起始分数 (IS)、精度 (Pre) 和召回率 (rec)。 “#Step”:生成图像所需的模型运行次数。 报告相对于 VAR 的挂钟推理时间。 带有后缀“-re”的模型使用拒绝采样。 †:取自 MaskGIT [17]。

Type Model FID↓ IS↑ Pre↑ Rec↑ #Para #Step Time
GAN BigGAN [13] 6.95 224.5 0.89 0.38 112M 1
GAN GigaGAN [42] 3.45 225.5 0.84 0.61 569M 1
GAN StyleGan-XL [74] 2.30 265.1 0.78 0.53 166M 1 0.3 [74]
Diff. ADM [26] 10.94 101.0 0.69 0.63 554M 250 168 [74]
Diff. CDM [36] 4.88 158.7 8100
Diff. LDM-4-G [70] 3.60 247.7 400M 250
Diff. DiT-L/2 [63] 5.02 167.2 0.75 0.57 458M 250 31
Diff. DiT-XL/2 [63] 2.27 278.2 0.83 0.57 675M 250 45
Diff. L-DiT-3B [3] 2.10 304.4 0.82 0.60 3.0B 250 >45
Diff. L-DiT-7B [3] 2.28 316.2 0.83 0.58 7.0B 250 >45
Mask. MaskGIT [17] 6.18 182.1 0.80 0.51 227M 8 0.5 [17]
Mask. RCG (cond.) [51] 3.49 215.5 502M 20 1.9 [51]
AR VQVAE-2^†^ [68] 31.11 ∼45 0.36 0.57 13.5B 5120
AR VQGAN^†^ [30] 18.65 80.4 0.78 0.26 227M 256 19 [17]
AR VQGAN [30] 15.78 74.3 1.4B 256 24
AR VQGAN-re [30] 5.20 280.3 1.4B 256 24
AR ViTVQ [92] 4.17 175.1 1.7B 1024 >24
AR ViTVQ-re [92] 3.04 227.4 1.7B 1024 >24
AR RQTran. [50] 7.55 134.0 3.8B 68 21
AR RQTran.-re [50] 3.80 323.7 3.8B 68 21
VAR VAR-d⁢16 3.30 274.4 0.84 0.51 310M 10 0.4
VAR VAR-d⁢20 2.57 302.6 0.83 0.56 600M 10 0.5
VAR VAR-d⁢24 2.09 312.9 0.82 0.59 1.0B 10 0.6
VAR VAR-d⁢30 1.92 323.1 0.82 0.59 2.0B 10 1
VAR VAR-d⁢30-re 1.73 350.2 0.82 0.60 2.0B 10 1
(validation data) 1.78 236.9 0.75 0.67

5.1 最先进的图像生成方法 State-of-the-art image generation

Setup.  We test VAR models with depths 16, 20, 24, and 30 on ImageNet 256×256 and 512×512 conditional generation benchmarks and compare them with the state-of-the-art image generation model families. Among all VQVAE-based AR or VAR models, VQGAN [30] and ours use the same architecture (CNN) and training data (OpenImages [49]) for VQVAE, while ViT-VQGAN [92] uses a ViT autoencoder, and both it and RQTransformer [50] trains the VQVAE directly on ImageNet. The results are summaried in Tab. 1 and Tab. 2.

设置。  我们在 ImageNet 256×256 和 512×512 条件生成基准上测试了深度为 16、20、24 和 30 的 VAR 模型,并将它们与最先进的图像生成模型族进行了比较。 在所有基于 VQVAE 的 AR 或 VAR 模型中,VQGAN[30] 和我们的模型使用相同的架构 (CNN) 和训练数据 (OpenImages [49]) 用于 VQVAE,而 ViT-VQGAN [92] 使用 ViT 自编码器,它和 RQTransformer [50] 都直接在 ImageNet 上训练 VQVAE。 结果总结于表1和表2

Overall comparison.  In comparison with existing generative approaches including generative adversarial networks (GAN), diffusion models (Diff.), BERT-style masked-prediction models (Mask.), and GPT-style autoregressive models (AR), our visual autoregressive (VAR) establishes a new model class. As shown in Tab. 1, VAR not only achieves the best FID/IS but also demonstrates remarkable speed in image generation. VAR also maintains decent precision and recall, confirming its semantic consistency. These advantages hold true on the 512×512 synthesis benchmark, as detailed in Tab. 2. Notably, VAR significantly advances traditional AR capabilities. To our knowledge, this is the first time of autoregressive models outperforming Diffusion transformers, a milestone made possible by VAR’s resolution of AR limitations discussed in Section 3.

整体比较。  与现有的生成方法(包括生成对抗网络(GAN)、扩散模型(Diff.),BERT 风格的掩模预测模型(Mask.),以及 GPT 式自回归模型(AR),我们的视觉自回归(VAR)建立了一个新的模型类。 如表1所示,VAR 不仅实现了最佳的 FID/IS 值,还在图像生成速度方面表现出色。 VAR 还保持了不错的精确度和召回率,证实了其语义一致性。 这些优势在 512×512 合成基准测试中同样成立,详情见表2。 值得注意的是,VAR 显着提升了传统 AR 功能。 据我们所知,这是首次自回归模型超越扩散 Transformer,这一里程碑式的成就得益于 VAR 解决了第3节中讨论的自回归模型的局限性。

表 2: ImageNet 512×512 条件生成。 †:摘自 MaskGIT[17]。 “-s”:由于资源限制,使用单个共享 AdaLN 层。

Type Model FID↓ IS↑ Time
GAN BigGAN [13] 8.43 177.9
Diff. ADM [26] 23.24 101.0
Diff. DiT-XL/2 [63] 3.04 240.8 81
Mask. MaskGIT [17] 7.32 156.0 0.5^†^
AR VQGAN [30] 26.52 66.8 25^†^
VAR VAR-d⁢36-s 2.63 303.2 1

Efficiency comparison.  Conventional autoregressive (AR) models [30, 68, 92, 50] suffer a lot from the high computational cost, as the number of image tokens is quadratic to the image resolution. A full autoregressive generation of n2 tokens requires 𝒪⁢(n2) decoding iterations and 𝒪⁢(n6) total computations. In contrast, VAR only requires 𝒪⁢(log⁡(n)) iterations and 𝒪⁢(n4) total computations. The wall-clock time reported in Tab. 1 also provides empirical evidence that VAR is around 20 times faster than VQGAN and ViT-VQGAN even with more model parameters, reaching the speed of efficient GAN models which only require 1 step to generate an image.

Compared with popular diffusion transformer.  The VAR model surpasses the recently popular diffusion models Diffusion Transformer (DiT), which serves as the precursor to the latest Stable-Diffusion 3 [29] and SORA [14], in multiple dimensions: 1) In image generation diversity and quality (FID and IS), VAR with 2B parameters consistently performs better than DiT-XL/2 [63], L-DiT-3B, and L-DiT-7B [3]. VAR also maintains comparable precision and recall. 2) For inference speed, the DiT-XL/2 requires 45× the wall-clock time compared to VAR, while 3B and 7B models [3] would cost much more. 3) VAR is considered more data-efficient, as it requires only 350 training epochs compared to DiT-XL/2’s 1400. 4) For scalability, Fig. 3 and Tab. 1 show that DiT only obtains marginal or even negative gains beyond 675M parameters. In contrast, the FID and IS of VAR are consistently improved, aligning with the scaling law study in Sec. 5.2. These results establish VAR as potentially a more efficient and scalable model for image generation than models like DiT.

效率比较。  常规的自回归(AR)模型[30, 68, 92, 50]由于图像符元的数量与图像分辨率的平方成正比,因此计算成本很高。 一个完整的自回归生成n2符元需要𝒪⁢(n2)次解码迭代和𝒪⁢(n6)次总计算。 相反,VAR 只需要𝒪⁢(log⁡(n))次迭代和𝒪⁢(n4)次总计算。 表1中报告的实际运行时间也提供了经验证据,证明即使模型参数更多,VAR 的速度也比 VQGAN 和 ViT-VQGAN 快约 20 倍,达到了仅需一步即可生成图像的高效 GAN 模型的速度。

与流行的扩散 Transformer 相比。  VAR 模型在多个维度上都超越了最近流行的扩散模型 Diffusion Transformer (DiT),DiT 是最新 Stable-Diffusion 3[29]和 SORA[14]的前身: 1) 在图像生成的丰富性和质量(FID 和 IS)方面,具有 20 亿参数的 VAR 始终优于 DiT-XL/2[63]、L-DiT-3B 和 L-DiT-7B[3]。 VAR 还保持了相当的精确度和召回率。 2) 在推理速度方面,DiT-XL/2 需要的实际运行时间是 VAR 的 45×倍,而 30 亿和 70 亿参数的模型[3]则会花费更多时间。 3) VAR 被认为更具数据效率,因为与 DiT-XL/2 的 1400 个训练周期相比,它只需要 350 个训练周期。 4) 在可扩展性方面,图3和表1显示,DiT 在参数超过 6.75 亿后,只能获得微不足道的甚至负面的收益。 相反,VAR 的 FID 和 IS 值持续改进,这与第5.2节中的缩放定律研究结果一致。 这些结果表明VAR 可能比 DiT 等模型更有效、更可扩展的图像生成模型。

Refer to caption图 5: 基于 VAR Transformer 大小的缩放定律N,具有幂律拟合(虚线)和方程(图例中)。 指数接近于零的小值α表明,当扩展 VAR Transformer 时,测试损失L和符元错误率E⁢r⁢r都会平稳下降。 轴均采用对数刻度。 皮尔逊相关系数接近−0.998表示l⁢o⁢g⁢(N)与vs.l⁢o⁢g⁢(L)或l⁢o⁢g⁢(N)与vs.l⁢o⁢g⁢(E⁢r⁢r)之间存在很强的线性关系。

5.2幂律缩放定律

背景。  先前的研究[43, 35, 38, 1]已经确定,扩大自回归 (AR) 大语言模型 (LLM) 的规模会导致测试损失L可预测地降低。这一趋势与参数数量N、训练符元T和最佳训练计算量Cmin相关,遵循幂律:

L=(β⋅X)α, (9)

其中X可以是N、T或Cmin中的任何一个。 指数α反映了幂律的平滑度,而L表示通过不可约损失L∞归一化的可约损失。 [35]^3^. 对L和X进行对数变换将揭示log⁡(L)和log⁡(X)之间的线性关系:

log⁡(L)=α⁢log⁡(X)+α⁢log⁡β. (10)

一个引人注目的现象是,[43]和[35]都没有观察到在X高端偏离这些线性关系的情况,尽管随着损失接近零,平坦化是不可避免的。

这些观察到的缩放定律[43, 35, 38, 1]不仅验证了 LLM 的可扩展性,而且还作为 AR 建模的预测工具,它有助于根据较小的模型估计较大 AR 模型的性能,从而通过大型模型性能预测节省资源使用。 鉴于大语言模型带来的缩放定律的这些吸引人的特性,它们在计算机视觉中的复制因此引起了人们的极大兴趣。

设置缩放 VAR 模型。  遵循[43, 35, 38, 1]中的协议,我们检查我们的 VAR 模型是否符合类似的缩放定律。 我们在 ImageNet 训练集[24]上训练了 12 个不同大小的模型,参数数量从 1800 万到 20 亿不等,每个时期包含 128 万张图像(或根据我们的 VQVAE 有 8700 亿个图像符元)。 对于不同规模的模型,训练跨越 200 到 350 个 epoch,最大 Token 数量达到 3050 亿个。 下面我们关注在给定足够的符元数量T的情况下,模型参数N和最佳训练计算量Cmin的缩放定律。

模型参数的缩放定律N。  我们首先研究随着 VAR 模型大小的增加,测试损失趋势。 深度为d的 VAR Transformer 的参数数量N⁢(d)=73728⁢d3在(8)中指定。 我们将d从6变为30,从而产生了 12 个参数量从 1850 万到 20 亿不等的模型。 我们在包含 50,000 张图像的 ImageNet 验证集[24]上评估了最终测试的交叉熵损失L和符元预测错误率E⁢r⁢r。 我们计算了最后尺度(在最后一个下个尺度自回归步骤)以及全局平均值的L和E⁢r⁢r。 结果绘制在图5中,其中我们

Refer to caption图 6: 具有最佳训练计算量的缩放规律Cmin。 线条颜色表示不同的模型尺寸。 红色虚线是与图例中的方程的幂律拟合。 轴采用对数刻度。 接近−0.99的皮尔逊系数表明log⁡(Cmin)与log⁡(L)或log⁡(Cmin)与log⁡(E⁢r⁢r)之间存在很强的线性关系。观察到L作为N的函数呈现清晰的幂律缩放趋势,这与[43, 35, 38, 1]一致。 幂律缩放定律可以表示为:

Llast=(2.0⋅N)−0.23andLavg=(2.5⋅N)−0.20. (11)

虽然缩放规律主要是在测试损失上进行研究的,但我们也凭经验观察到符元错误率E⁢r⁢r具有类似的幂律趋势:

E⁢r⁢rlast=(4.9⋅102⁢N)−0.016andE⁢r⁢ravg=(6.5⋅102⁢N)−0.010. (12)

这些结果验证了 VAR 强大的可扩展性,通过扩大 VAR Transformer 可以不断提高模型的测试性能。

具有最佳训练计算量的缩放规律Cmin。  然后,我们检查了在增加训练计算量C时 VAR Transformer 的缩放行为。对于这 12 个模型中的每一个,我们追踪了训练期间以 PFlops(1015每秒浮点运算)表示的测试损失L和符元错误率E⁢r⁢r作为C的函数。 结果绘制在图6中。 在这里,我们绘制L和E⁢r⁢r的帕累托前沿,以突出达到特定损失或错误值所需的最佳训练计算量Cmin。

L和E⁢r⁢r作为Cmin函数的拟合幂律缩放规律为:

Llast=(2.2⋅10−5⁢Cmin)−0.13 (13)
Lavg=(1.5⋅10−5⁢Cmin)−0.16, (14)
- - - -
E⁢r⁢rlast=(8.1⋅10−2⁢Cmin)−0.0067 (15)
- - - -
E⁢r⁢ravg=(4.4⋅10−2⁢Cmin)−0.011. (16)
- - - -

这些关系(1416)在Cmin的 6 个数量级上成立,我们的发现与[43, 35]中的发现一致:当使用足够的数据进行训练时,更大的 VAR Transformer 更具计算效率,因为它们可以用更少的计算达到相同的性能水平。

5.3缩放效应的可视化 Visualization of scaling effect

To better understand how VAR models are learning when scaled up, we compare some generated 256×256 samples from VAR models of 4 different sizes (depth 6, 16, 26, 30) and 3 different training stages (20%, 60%, 100% of total training tokens) in Fig. 7. To keep the content consistent, a same random seed and teacher-forced initial tokens are used. The observed improvements in visual fidelity and soundness are consistent with the scaling laws, as larger transformers are thought able to learn more complex and fine-grained image distributions.

为了更好地理解在扩展 VAR 模型时它们的学习方式,我们比较了图7中来自 4 个不同大小(深度 6、16、26、30)的 VAR 模型和 3 个不同训练阶段(总训练符元的 20%、60%、100%)的一些生成的256×256样本。 为了保持内容一致,使用相同的随机种子和教师强制的初始标记。 观察到的视觉保真度和健全性的改进与缩放定律一致,因为较大的变换器被认为能够学习更复杂和更细粒度的图像分布。

Refer to caption图 7: 扩大模型规模N和训练计算量C可以提高视觉保真度和健全性。 放大以获得更好的视图。 样本是从 4 个不同规模和 3 个不同训练阶段的 VAR 模型中抽取的。 9 个类别标签(从左到右,从上到下)分别是:火烈鸟130、北极狼270、金刚鹦鹉88、暹罗猫284、示波器688、哈士奇250、海燕146、火山980和双体船484。Refer to caption图 8:下游任务中的零样本评估 包含内绘画、外绘画和类条件编辑。 结果表明,VAR 可以推广到新的下游任务,无需特殊设计和微调。 放大以获得更好的视图。

6零样本任务泛化 Zero-shot task generalization

Image in-painting and out-painting.  VAR-d30 is tested. For in- and out-painting, we teacher-force ground truth tokens outside the mask and let the model only generate tokens within the mask. No class label information is injected into the model. The results are visualized in Fig. 8. Without modifications to the network architecture or tuning parameters, VAR has achieved decent results on these downstream tasks, substantiating the generalization ability of VAR.

图像内画和外画。  对 VAR-d30 进行了测试。 对于内绘制和外绘制,我们在掩码之外强制使用真实标记,并让模型仅在掩码内生成标记。 没有类标签信息被注入到模型中。 结果如图8所示。 在不修改网络架构或调整参数的情况下,VAR 在这些下游任务上取得了不错的结果,证实了 VAR 的泛化能力。

Class-conditional image editing.  Following MaskGIT [17] we also tested VAR on the class-conditional image editing task. Similar to the case of in-painting, the model is forced to generate tokens only in the bounding box conditional on some class label. Fig. 8 shows the model can produce plausible content that fuses well into the surrounding contexts, again verifying the generality of VAR.

类条件图像编辑。  遵循 MaskGIT[17],我们还在类条件图像编辑任务上测试了 VAR。 与修复的情况类似,模型被迫仅在某些类标签条件下的边界框中生成标记。 图8显示该模型可以生成合理的、与周围环境融合良好的内容,再次验证了 VAR 的通用性。

Table 3:Ablation study of VAR. The first two rows compare GPT-2-style transformers trained under AR or VAR algorithm without any bells and whistles. Subsequent lines show the influence of VAR enhancements. “AdaLN”: adaptive layernorm. “CFG”: classifier-free guidance. “Attn. Norm.”: normalizing q and k to unit vectors before attention. “Cost”: inference cost relative to the baseline. “Δ”: FID reduction to the baseline.

表 3:VAR 消融研究。 前两行比较了在 AR 或 VAR 算法下训练的 GPT-2 风格的 Transformer,没有任何额外的功能。 随后的几行显示了 VAR 增强的影响。 “AdaLN”:自适应层规范。 “CFG”:无分类器指导。 “注意。 Norm.”:在注意力机制之前将q和k归一化为单位向量。 “成本”:相对于基线的推理成本。 “Δ”:FID 相对于基线的降低值。

Description Para. Model AdaLN Top-k CFG Cost FID↓ Δ
1 AR [30] 227M AR 1 18.65    0.00
2 AR to VAR 207M VAR-d16 0.013 5.22 −13.43
3 +AdaLN 310M VAR-d16 0.016 4.95 −13.70
4 +Top-k 310M VAR-d16 600 0.016 4.64 −14.01
5 +CFG 310M VAR-d16 600 2.0 0.022 3.60 −15.05
5 +Attn. Norm. 310M VAR-d16 600 2.0 0.022 3.30 −15.35
6 +Scale up 2.0B VAR-d30 600 2.0 0.052 1.73 −16.85

7消融研究 Ablation Study

In this study, we aim to verify the effectiveness and efficiency of our proposed VAR framework. Results are reported in Tab. 3.

Effectiveness and efficiency of VAR.  Starting from the vanilla AR transformer baseline implemented by [17], we replace its methodology with our VAR and keep other settings unchanged to get row 2. VAR achieves a way more better FID (18.65 vs. 5.22) with only 0.013× inference wall-clock cost than the AR model, which demonstrates a leap in visual AR model’s performance and efficiency.

Component-wise ablation.  We further test some key components in VAR. By replacing the standard Layer Normalization (LN) with Adaptive Layer Normalization (AdaLN), VAR starts yielding better FID than baseline. By using the top-k sampling similar to the baseline, VAR’s FID is further improved. By using the classifier-free guidance (CFG) with ratio 2.0 and normalizing q and k to unit vectors before attention, we reach the FID of 3.30, which is 15.35 lower to the baseline, and its inference speed is still 45 times faster. We finally scale up VAR size to 2.0B and achieve an FID of 1.73. This is 16.85 better than the baseline FID.

在本研究中,我们旨在验证我们提出的 VAR 框架的有效性和效率。 结果报告在表3中。

VAR 的有效性和效率。  从[17]实现的原始 AR Transformer 基线开始,我们将其方法替换为我们的 VAR,并保持其他设置不变以获得第2行。 VAR 实现了更好的 FID(18.65vs.5.22),推理时钟成本仅为 AR 模型的 0.013×,这展示了视觉 AR 模型性能和效率的飞跃。

逐组件消融。  我们进一步测试了 VAR 中的一些关键组件。 通过用自适应层标准化 (AdaLN) 替换标准层标准化 (LN),VAR 开始产生比基线更好的 FID。 通过使用与基线类似的 top-k采样,VAR 的 FID 得到了进一步的改进。 通过使用比例为2.0的无分类器引导(CFG),并在注意力机制之前将q和k归一化为单位向量,我们达到了 3.30 的 FID 值,比基线低 15.35,并且其推理速度仍然快 45 倍。 我们最终将 VAR 的大小扩展到 20 亿,并实现了 1.73 的 FID 值。 这比基线 FID 好 16.85。

8局限性和未来工作 Limitations and Future Work

In this work, we mainly focus on the design of learning paradigm and keep the VQVAE architecture and training unchanged from the baseline [30] to better justify VAR framework’s effectiveness. We expect advancing VQVAE tokenizer [99, 59, 95] as another promising way to enhance autoregressive generative models, which is orthogonal to our work. We believe iterating VAR by advanced tokenizer or sampling techniques in these latest work can further improve VAR’s performance or speed.

Text-prompt generation  is an ongoing direction of our research. Given that our model is fundamentally similar to modern LLMs, it can easily be integrated with them to perform text-to-image generation through either an encoder-decoder or in-context manner. This is currently in our high priority for exploration.

Video generation  is not implemented in this work, but it can be naturally extended. By considering multi-scale video features as 3D pyramids, we can formulate a similar “3D next-scale prediction” to generate videos via VAR. Compared to diffusion-based generators like SORA [14], our method has inherent advantages in temporal consistency or integration with LLMs, thus can potentially handle longer temporal dependencies. This makes VAR competitive in the video generation field, because traditional AR models can be too inefficient for video generation due to their extremely high computational complexity and slow inference speed: it is becoming prohibitively expensive to generate high-resolution videos with traditional AR models, while VAR is capable to solve this. We therefore foresee a promising future for exploiting VAR models in the realm of video generation.

在这项工作中,我们主要关注学习范式的设计,并将 VQVAE 架构和训练保持不变,与基线[30]一致,以更好地证明 VAR 框架的有效性。 我们期待改进 VQVAE 分词器 [99, 59, 95]作为增强自回归生成模型的另一种有前景的方法,这与我们的工作是正交的。 我们相信在这些最新工作中通过先进的分词器或采样技术迭代 VAR 可以进一步提高 VAR 的性能或速度。

文本提示生成是我们研究的一个持续方向。 鉴于我们的模型基本上与现代大语言模型相似,因此它可以轻松地与它们集成,通过编码器-解码器或上下文方式执行文本到图像的生成。 这是我们目前探索的首要任务。

视频生成在这项工作中未实现,但可以自然地扩展。 通过将多尺度视频特征视为3D 金字塔,我们可以制定类似的“3D 下一尺度预测”来通过 VAR 生成视频。 与基于扩散的生成器(如 SORA [14])相比,我们的方法在时间一致性或与 LLM 集成方面具有固有优势,因此可以潜在地处理更长的时序依赖关系。 这使得 VAR 在视频生成领域具有竞争力,因为传统 AR 模型由于其极高的计算复杂度和缓慢的推理速度,对于视频生成来说效率太低:使用传统 AR 模型生成高分辨率视频变得非常昂贵,而 VAR 能够解决这个问题。 因此,我们预见到在视频生成领域利用 VAR 模型有着广阔的前景。

9结论 Conclusion

We introduced a new visual generative framework named Visual AutoRegressive modeling (VAR) that 1) theoretically addresses some issues inherent in standard image autoregressive (AR) models, and 2) makes language-model-based AR models first surpass strong diffusion models in terms of image quality, diversity, data efficiency, and inference speed. Upon scaling VAR to 2 billion parameters, we observed a clear power-law relationship between test performance and model parameters or training compute, with Pearson coefficients nearing −0.998, indicating a robust framework for performance prediction. These scaling laws and the possibility for zero-shot task generalization, as hallmarks of LLMs, have now been initially verified in our VAR transformer models. We hope our findings and open sources can facilitate a more seamless integration of the substantial successes from the natural language processing domain into computer vision, ultimately contributing to the advancement of powerful multi-modal intelligence.

我们引入了一种名为视觉自回归建模 (VAR) 的新视觉生成框架,该框架 1) 理论上解决了标准图像自回归 (AR) 模型固有的一些问题,2) 使基于语言模型的 AR 模型在以下方面首次超越了强扩散模型:图像质量、多样性、数据效率和推理速度。 在将 VAR 扩展到 20 亿参数后,我们观察到测试性能与模型参数或训练计算之间存在清晰的幂律关系,皮尔逊系数接近−0.998,表明这是一个强大的性能预测框架。 这些缩放定律和零样本任务泛化的可能性,作为大语言模型的标志,现已在我们的 VAR Transformer 模型中得到初步验证。 我们希望我们的发现和开源能够促进将自然语言处理领域的实质性成功更无缝地集成到计算机视觉中,最终促进强大的多模式智能的进步。

Refer to caption图 9:绘制了词符依赖关系。 VQGAN 编码器最后一个自注意力层中注意力分数的归一化热图被可视化。 使用了来自 ImageNet 验证集的 4 张随机的 256×256 图像。

附录 A VQVAE 中的 Token 依赖项

为了检查 VQVAE [30]中的符元依赖性,我们检查了矢量量化模块之前的自注意力层中的注意力分数。 我们从 ImageNet 验证集中随机抽取 4 256×256 个图像进行分析。 请注意,[30]中的自注意力层只有一个头,因此对于每个图像,我们只绘制一个注意力图。 图9中的热力图显示了每个符元对所有其他符元的注意力分数,这表明所有符元之间存在强烈的双向依赖关系。 这并不奇怪,因为经过训练来重建图像的 VQVAE 模型利用自注意力层,而无需任何注意力掩模。 有些工作[86]已经在视频 VAE 的自注意力层中使用了因果注意力,但我们没有发现任何图像 VAE 工作使用因果自注意力。

附录 B AR 和 VAR 生成的时间复杂度

我们证明了 AR 和 VAR 生成的时间复杂度。

Lemma B.1.

对于标准的自注意力 Transformer,AR 生成的计算复杂度为𝒪⁢(n6),其中h=w=n和h,w分别代表 VQ 码图的高度和宽度。

证明。

Token 总数为h×w=n2。 对于第i(1≤i≤n2)次自回归迭代,需要计算每个词符与所有其他标记之间的注意力分数,这需要𝒪⁢(i2)时间。 所以总时间复杂度为:

∑i=1n2i2=16⁢n2⁢(n2+1)⁢(2⁢n2+1), (17)

这相当于𝒪⁢(n6)基本计算。 ∎

对于 VAR,需要我们定义自回归生成的解析序列(h1,w1,h2,w2,…,hK,wK),其中hi,wi是 VQ 码图在i处的高度和宽度-第 3 个自回归步骤,hK=h,wK=w 达到最终分辨率。 为了简单起见,假设所有 1≤k≤K 和 n=h=w 都是 nk=hk=wk。 我们将分辨率设置为 nk=a(k−1),其中 a>1 是一个常量,使得 a(K−1)=n 成立。

Lemma B.2.

对于标准的自注意力 Transformer 以及给定的超参数a>1,VAR 生成的计算复杂度为𝒪⁢(n4),其中h=w=n和h,w分别代表最后一个(最大)VQ 码图的高度和宽度。

证明。

考虑第 k (1≤k≤K) 自回归生成。 当前所有词符图(r1,r2,…,rk)的 token 总数为:

∑i=1kni2=∑i=1ka2⋅(k−1)=a2⁢k−1a2−1. (18)

因此,第 k 个自回归生成的时间复杂度为:

(a2⁢k−1a2−1)2. (19)

通过总结所有自回归代,我们有:

∑k=1loga⁡(n)+1(a2⁢k−1a2−1)2 (20)
=(a4−1)⁢log⁡n+(a8⁢n4−2⁢a6⁢n2−2⁢a4⁢(n2−1)+2⁢a2−1)⁢log⁡a(a2−1)3⁢(a2+1)⁢log⁡a (21)
- - - -
∼𝒪⁢(n4). (22)
- - - -

这样就完成了证明。 ∎

Refer to caption图 10: 基于 ImageNet 256×256 基准的模型比较。 通过 VAR 生成的更多 512×512 样本可以在提交的补充材料 zip 文件中找到。Refer to caption图 11: 一些通过在 ImageNet 上训练的 VAR 生成的 256×256 样本。 通过 VAR 生成的更多 512×512 样本可以在提交的补充材料 zip 文件中找到。

阅读全文(20积分)