Context-Aware Autoregressive Models for Multi-Conditional Image Generation

Yixiao Chen, Zhiyuan Ma, Guoli Jia, Che Jiang, Jianjun Li, Bowen Zhou

TL;DR

ContextAR is a flexible autoregressive framework that unifies text prompts, spatial layouts (like edges, depth maps, and poses), and subject conditions into a single token sequence for multi-conditional image generation. By introducing hybrid positional encodings and an optimized attention mechanism, it achieves state-of-the-art controllability and image quality without requiring any fine-tuning for arbitrary condition combinations.

What Problem Does This Paper Address?

Generating images based on multiple simultaneous conditions—such as a text description combined with a specific human pose, a depth map, and a Canny edge layout—is highly desirable for precise AI image editing.

Currently, diffusion models (like ControlNet) dominate this space. However, they typically require complex, task-specific architectural modifications or external adapters to fuse these heterogeneous conditions, which compromises scalability.

Transformer-based autoregressive (AR) models offer a natural alternative because they can treat text, images, and conditions as a single, unified token stream. Yet, existing AR approaches for conditional generation either naively prepend condition tokens (leading to poor control) or use separate adapters that break the unified sequence paradigm. Furthermore, stacking multiple spatial conditions in an AR model introduces two major hurdles: it causes spatial ambiguity (the model struggles to distinguish between different condition types occupying the same coordinates) and it triggers a quadratic explosion in computational complexity.

Methods

ContextAR solves these challenges by embedding all conditions directly into a unified sequence and introducing two key architectural innovations:

1. Spatially Overlapped Unified Sequence & Hybrid Positional Encodings

The framework flattens multiple visual conditions, text prompts, and target image tokens into a single sequence: $$S = [c_1, c_2, \dots, c_m, c_T, q]$$

To ensure the model can align these conditions spatially while still distinguishing between them, the authors propose a hybrid positional encoding scheme:

  • 2D RoPE (Rotary Position Embedding): Applied to all visual conditions using the same spatial coordinates as the target image to guarantee exact pixel-level alignment.
  • LPE (Learnable Positional Embedding): A condition-specific learned offset added on top of RoPE. This gives each modality (e.g., Canny vs. Depth) a unique signature, preventing the model from confusing them.
Overview of the ContextAR framework showing unified sequence processing and hybrid positional embeddings.

2. Conditional Context-Aware Attention

To keep the computational footprint manageable, the authors redesign the self-attention mechanism with two components:

  • Cross-Condition Perception Restriction (CCPR): This masks the attention dot-products between different condition types. Because conditions do not need to look at each other to guide the image, this restriction drops the attention complexity from quadratic ($O(m^2N^2)$) to linear ($O(mN^2)$) relative to the number of conditions ($m$).
  • Intra-Condition Bidirectional Perception (ICBP): Instead of using strict causal masking for the condition tokens during the prefill stage, ICBP allows bidirectional attention within each condition sequence, significantly improving the model's spatial understanding.
Visualization of the CCPR and ICBP attention mechanisms.

Datasets

The authors evaluated ContextAR on two primary datasets:

  • MultiGen-20M: A large-scale dataset used to test compositional, spatially-aligned conditions including Canny edges, depth maps, HED maps, and human poses.
  • SubjectSpatial200K: Used to validate the model's ability to mix subject-driven conditions (image prompts for identity consistency) with spatial conditions (subject-canny and subject-depth).

Key Insights and Ideas

  • Solving the Identity Crisis of Overlapped Tokens: When multiple spatial maps are fed into a transformer, they share identical 2D coordinates. Fusing RoPE with LPE elegantly solves this "identity crisis," allowing the transformer to know where an edge is, and what kind of condition it belongs to simultaneously.
  • Linearizing Multimodal Attention: CCPR proves that cross-modality interaction among conditions is redundant. Masking these interactions makes training on many conditions computationally practical without losing generation fidelity.
  • Visual Prefill Doesn't Need Causality: Standard autoregressive models inherit strict causal masking from text LLMs. ContextAR leverages the fact that condition images are fully available upfront, using bidirectional attention during prefill to boost spatial awareness.

Key Results

ContextAR was evaluated against leading diffusion and autoregressive baselines using LlamaGen-XL as its base model:

  • Superior Controllability: On the MultiGen-20M dataset (using all conditions), ContextAR achieved a structural similarity (SSIM) score of 53.47, representing a 21.55% relative improvement over the state-of-the-art diffusion framework PixelPonder (43.99), which is based on the 12-billion-parameter FLUX.1-dev.
  • High Image Quality: It achieved the top FID score of 10.42 on MultiGen-20M, outperforming all diffusion baselines despite utilizing significantly fewer parameters (775M vs. FLUX's 12B).
  • Zero-Shot Flexibility: Due to an independent condition-dropping strategy during training, ContextAR can dynamically accept any subset of conditions at inference time without any fine-tuning, outperforming specialized single-condition models like ControlAR.

Limitations and Future Work

  • Quantization Artifacts: ContextAR relies on a discrete VQ-VAE tokenizer to convert images into tokens. This discrete quantization can sometimes introduce minor visual artifacts compared to continuous tokenizers or diffusion latents.
  • Inference Speed: As an autoregressive model, the decoding phase generates images token-by-token, which can be slower than fast-sampling diffusion models.

The authors suggest that future iterations could integrate ContextAR with continuous tokenizers or next-scale prediction paradigms (like Visual Autoregressive models, or VAR) to further accelerate generation speeds and enhance fine-grained details.

Summary updated

BibTeX
@misc{chen2025context,
  author = {Yixiao Chen and Zhiyuan Ma and Guoli Jia and Che Jiang and Jianjun Li and Bowen Zhou},
  title = {{Context-Aware Autoregressive Models for Multi-Conditional Image Generation}},
  year = {2025},
  eprint = {2505.12274},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.12274},
}
Figure