Back to Tony'Log返回 Tony'Log

Generation · VAR · Efficient Inference

FastVAR: Pushing Visual Autoregressive Generation Toward Near-Linear High-Resolution InferenceFastVAR: 用缓存 token 剪枝把视觉自回归推向近线性高分辨率生成

arXiv · PDF · Code

FastVAR is a training-free acceleration method for Visual Autoregressive Modeling. Its central observation is simple: high-resolution VAR spends most of its latency in the late, large-scale steps, yet many low-frequency tokens have already stabilized by then. The remaining useful computation mostly lies in high-frequency tokens around edges, textures, and local details. Instead of forwarding the full token map through the Transformer at every scale, FastVAR keeps only pivotal high-frequency tokens and restores the pruned positions from cached outputs of the previous scale.

The method is plug-and-play. It does not retrain a smaller model and does not rely on attention maps, so it can be stacked with FlashAttention. On Infinity and HART, FastVAR gives substantial speedups with little quality loss; for Infinity it reports 2.7x acceleration while GenEval drops only from 0.73 to 0.72, and it enables 2K generation on a single RTX 3090 with roughly 15GB memory.

Background

  • Classic visual AR predicts next tokens. Images are discretized into tokens and generated sequentially. This is general but slow at high resolution.
  • VAR changes the unit from token to scale. Visual Autoregressive Modeling generates token maps from coarse to fine: first layout, then details.
  • Fewer steps do not mean cheap steps. Each late scale contains a full high-resolution token map, so attention and memory still grow quickly.
  • High-resolution VAR models hit latency and memory limits. Infinity and HART can produce strong 1024 x 1024 images, but 2K generation exposes the bottleneck.

Problem

  • Late scales dominate runtime. The paper profiles that the last two large-scale steps take about 60% of total time even with FlashAttention.
  • Naive token pruning breaks the grid. The decoder still needs a complete 2D token map, so removed positions must be reconstructed.
  • Early scales are fragile. They define global layout and contain few tokens, so pruning them gives little speed and can propagate structural errors.
  • The useful late-stage work is uneven. Flat regions change little, while edges, textures, and local details still need model computation.

Core Idea

  • Split generation into structure construction and texture filling. FastVAR leaves the early coarse scales untouched and only modifies late large scales.
  • Forward only pivotal high-frequency tokens. A token is important if it deviates strongly from the global average token.
  • Restore pruned tokens from cache. Previous-scale cached features are interpolated to the current scale, then the newly computed pivotal tokens are scattered back.
  • Avoid attention-map dependency. Importance is computed from token features, preserving compatibility with FlashAttention.

Method

1. Choose the late scales. Among K scales, the final N scales are treated as texture filling. Earlier scales run the original VAR and provide layer-wise caches.

2. Select pivotal tokens. For the current input token map, FastVAR computes a global average token and scores each token by its L2 distance to that average. Top-scoring tokens are retained.

3. Run Transformer layers only on retained tokens. Attention and FFN see a much smaller token set, reducing both computation and KV memory.

4. Restore the full grid. Cached token maps from the previous scale are interpolated to the current resolution, and computed pivotal tokens overwrite their corresponding positions.

5. Increase pruning at later scales. Later scales are more tolerant of pruning; the paper uses aggressive schedules such as {40%, 50%, 100%, 100%} for Infinity.

Results

  • Infinity: latency drops from 2.61s to 0.95s on 1024 x 1024 GenEval, with total score 0.73 to 0.72.
  • HART: latency drops from 0.95s to 0.63s while GenEval remains 0.51.
  • Memory improves too. Infinity with FlashAttention uses 16.1GB; adding FastVAR lowers it to 11.9GB.
  • High-resolution extrapolation becomes practical. The paper demonstrates 2K image generation on a single RTX 3090.
  • Better than a direct ToMe replacement. FastVAR preserves quality more reliably because it respects the VAR coarse-to-fine structure.

Limitations

  • The benefit is resolution-dependent. At 256 x 256, token maps are small and there is less to prune.
  • The pruning schedule is backbone-specific. Infinity tolerates more aggressive skipping than HART.
  • The selection rule is still heuristic. Future work may need adaptive layer-wise pruning ratios.
  • Very large scale gaps still hurt quality. The method works best when resolution is extended moderately.

My Take

The most useful part of FastVAR is not token pruning by itself, but the way it matches the generative structure of VAR. Early scales are sketches; late scales are refinement. If low-frequency layout is already stable, spending full Transformer computation on every late token is wasteful.

Viewed as a coarse-to-fine generation program, FastVAR is close to redrawing only complex regions during the refinement stage while copying stable flat regions from the previous pass. That structural prior is why the method can be training-free, attention-map-free, and still compatible with FlashAttention.

这篇论文提出 FastVAR:一个面向 Visual Autoregressive Modeling 的训练后加速方法。它的核心判断很直接:VAR 在高分辨率生成时最贵的不是早期“搭结构”的小尺度步骤,而是后期大尺度步骤;但后期大多数低频 token 其实已经收敛,只剩边缘、纹理、细节这类高频 token 还值得继续算。因此,与其每个尺度都把整张 token map 丢进 Transformer,不如只前向关键高频 token,再用前一尺度缓存把被剪掉的位置补回来。

这不是重新训练一个小模型,也不是依赖 attention map 的复杂动态路由,而是一个 plug-and-play 的推理加速 recipe。论文在 Infinity 和 HART 两个 VAR 文生图模型上验证:FastVAR 可以叠加在 FlashAttention 之上继续提速,在 Infinity 上达到 2.7x 加速,GenEval 总分只从 0.73 降到 0.72;更吸引人的结果是,它可以在单张 RTX 3090 上用约 15GB 显存生成 2K 图像。

背景铺垫

  • 传统视觉 AR 是 next-token prediction。 图像被离散成 token 后按顺序逐个生成,优点是统一,缺点是解码步数太多,高分辨率尤其慢。
  • VAR 把单位从 token 换成 scale。 Visual Autoregressive Modeling 不再一个 token 一个 token 预测,而是按尺度生成 token map:先低分辨率结构,再逐步补细节。
  • VAR 减少了步数,但单步变重。 第 k 个尺度要处理完整的 h_k x w_k token map;分辨率升高后,token 数按面积增长,attention 复杂度会更快膨胀。
  • Infinity 和 HART 代表了更强的 VAR 文生图模型。 它们能做到 1024 x 1024 生成,但继续往 2K 扩展时会遇到显存和延迟瓶颈。

问题是什么

  • 大尺度步骤占主要延迟。 论文 profiling 发现,即使用 FlashAttention,最后两个大尺度步骤也占总运行时间约 60%。
  • 高分辨率下 VAR 不是线性扩展。 next-scale 的每一步都要吞完整 token map,导致分辨率越高,单步 token 数和 attention 成本越难控制。
  • 直接剪 token 会破坏二维结构。 图像生成最后仍需要完整的空间网格;如果只输出部分 token,就必须把被剪位置合理补回去。
  • 早期尺度不能乱剪。 小尺度负责主体轮廓和布局,剪错会把结构错误传递到后续尺度;而且小尺度 token 本来少,剪了也不省多少。

核心想法

  • 把生成过程拆成两个阶段。 早期是 Structure Construction,保留完整 VAR;后期是 Texture Filling,只在大尺度步骤上做 FastVAR。
  • 只算关键高频 token。 后期低频结构基本已经定型,真正需要模型继续优化的是边缘、纹理和局部细节。
  • 用缓存恢复被剪 token。 被剪位置不用重新算,而是从上一个缓存尺度插值到当前尺度,再把前向得到的关键 token scatter 回去。
  • 不依赖 attention map。 token 重要性来自输入 token 与全局平均 token 的差异,因此可以和 FlashAttention 兼容。

方法怎么做

1. 选择在哪些尺度启用 FastVAR。 设总共有 K 个尺度,后 N 个大尺度属于 Texture Filling。前 K - N 个尺度完全照常运行,并把第 K - N 个尺度在每层的输出存成 cache。Infinity 中 N = 4,HART 中 N = 2。

2. Pivotal Token Selection。 对当前层输入 x_k,先用 global average pooling 得到一个低频近似 x_bar_k。然后计算每个 token 的高频分数 s_k = ||x_k - x_bar_k||_2,按分数保留 Top-K token。直觉上,离全局平均越远的 token 越可能是边缘、纹理、局部细节。

3. 只前向保留下来的 token。 attention 和 FFN 都只处理被选中的 pivotal tokens。因为输入 token 数减少,KV cache 也相应变小,既省计算也省显存。

4. Cached Token Restoration。 对每层输出,先把缓存尺度的 token map 插值到当前尺度大小,作为完整网格的近似;再把当前层真正前向得到的 pivotal token scatter 回对应位置。这样每层结束后 token 数恢复,后续模块仍看到完整二维结构。

5. 渐进式剪枝比例。 越靠后的尺度越能承受更强剪枝。论文中 Infinity 用 {40%, 50%, 100%, 100%},HART 用 {50%, 75%}。这里的 100% 表示对应尺度直接跳过,用插值结果补到目标分辨率;但论文也强调这个极端设置并不适用于所有 backbone。

为什么这个方法成立

  • 频谱分析支持“低频已收敛”。 论文观察到大尺度步骤中低频成分变化很小,高频成分仍在明显优化。
  • 可视化支持“后期补纹理”。 中间输出显示,早期尺度已经形成主体轮廓,后期主要补细节、边缘、材质。
  • 跨尺度 attention 有对角稀疏性。 当前尺度 token 不只看同尺度邻域,也和前一尺度对应位置强相关,这让“用前一尺度缓存补当前位置”变得合理。
  • 大尺度对剪枝更鲁棒。 ablation 显示,剪 48/64 这类后期尺度比剪 16/21 早期尺度更快,质量也更稳。

结果速览

  • Infinity + FastVAR: 在 1024 x 1024 GenEval 上,延迟从 2.61s 降到 0.95s,速度 2.7x;GenEval 总分从 0.73 到 0.72。
  • HART + FastVAR: 延迟从 0.95s 降到 0.63s,速度 1.5x;GenEval 总分保持 0.51。
  • 显存也下降。 在 Infinity 设置中,FlashAttention only 为 16.1GB,FlashAttention + FastVAR 降到 11.9GB。
  • 能继续扩展分辨率。 论文展示了 zero-shot 更高分辨率生成,单张 2K 图可以在 RTX 3090 上约 15GB 显存、1.5s 生成。
  • 优于直接 ToMe 替换。 ToMe 在 VAR 上能提速但质量更容易掉;FastVAR 在 HART 上 1.70x 仍比 ToMe 1.36x 有更好的 FID 和 GenEval。

和其他加速思路的区别

  • 不是小模型 ensemble。 CoDe 依赖不同尺寸模型协同,而 FastVAR 只改推理 token 流,不要求额外训练或额外模型。
  • 不是 attention-based token pruning。 它不需要取 attention map,所以不破坏 FlashAttention 的使用场景。
  • 不是扩散模型 cache 的直接搬运。 VAR 的 next-scale 结构让“跨尺度缓存 + 当前尺度关键 token”更自然。
  • 不是全局无差别剪枝。 它明确避开结构构建阶段,只对后期纹理填充阶段动刀。

局限与开放问题

  • 主要收益来自高分辨率。 256 x 256 ImageNet 中最大 token map 很小,剪枝空间有限,FastVAR 的优势没有 1024/2K 明显。
  • 剪枝比例依赖 backbone。 Infinity 可以接受后两个尺度 100% 跳过,但 HART 使用 {50%, 100%} 会出现明显质量下降。
  • 当前策略仍是启发式。 高频分数简单有效,但未来可能需要 layer-wise 或 adaptive pruning ratio 来进一步提高速度和稳定性。
  • 超高分辨率仍有质量间隙。 论文选择“适度扩展”的尺度,因为尺度 gap 过大时会出现质量下降。

我的理解

FastVAR 最值得借鉴的地方不是“剪 token”本身,而是它很准确地利用了 VAR 的生成结构:早期尺度负责布局,后期尺度负责纹理;后期 token 多、耗时重、但低频已经稳定。这种结构性先验比通用 token pruning 更干净,也解释了为什么它可以不用训练、不看 attention map,还能和 FlashAttention 叠加。

如果把 VAR 看成一种 coarse-to-fine 的图像生成程序,FastVAR 做的事情有点像:草图阶段不要省,细化阶段只重画复杂区域,平坦区域直接沿用上一步的结果。这个思路对未来高分辨率视觉生成很有启发,尤其适合那些空间结构明确、尺度递进明显的 autoregressive 或 masked generation 模型。