Safe Autoregressive Image Generation with Iterative Self-Improving Codebooks

Yunqi Xue, Zhijiang Li, Philip Torr, Jindong Gu

Introduction

Researchers have developed a novel approach to make autoregressive image models significantly safer without relying on human-labeled data. By leveraging a model's own ability to understand and evaluate its outputs, the "Safe-CB" (Safe Codebook) method iteratively identifies harmful visual representations within the model's discrete codebook. It then "scrubs" these representations out while preserving overall image generation quality.

The Challenge of Discrete Codebooks

Most recent breakthroughs in AI safety for image generation have focused on diffusion models, such as Stable Diffusion, which operate in continuous latent spaces. However, a new class of "unified" multimodal models—including Janus, Emu3, and LlamaGen—is rapidly gaining traction. These models are autoregressive; they treat images as sequences of discrete tokens pulled from a "codebook," functioning much like Large Language Models (LLMs) do with text.

The primary challenge is that existing safety techniques designed for diffusion models, which typically involve guiding noise or fine-tuning continuous weights, do not translate well to discrete, token-based systems. Furthermore, standard safety datasets rely heavily on expensive human annotations. This research addresses two critical gaps: how to systematically eliminate harmful content from discrete codebooks, and how to achieve this autonomously using the model’s internal judgment.

The Safe-CB Framework

To solve these challenges, the authors introduce Safe-CB, a two-step iterative framework that allows the model to self-correct.

1. Projecting into Harmless Space

First, the model is prompted to generate images from potentially harmful text prompts. It then uses its own multimodal understanding capabilities to "self-diagnose" which generated images are actually unsafe. This creates pairs of harmful and safe image-text representations. By calculating the difference between these embeddings and applying Singular Value Decomposition (SVD), the researchers isolate a "Harmful Space"—a mathematical vector representing unsafe concepts like violence or nudity. The codebook is then projected away from this space, effectively deleting the model's capacity to generate those specific harmful patterns.

2. Adaptive Fine-Tuning in the Null Space

Simply deleting information from the codebook can degrade overall image quality, resulting in blurry or distorted outputs. To counteract this, the authors fine-tune the codebook using safe image-text pairs. Crucially, this fine-tuning is restricted to the "null space"—a mathematical region strictly orthogonal to the Harmful Space. This constraint ensures that while the model recovers its artistic fidelity, it is mathematically prevented from accidentally re-learning the harmful concepts it just discarded.

This two-step process is repeated iteratively. As the model becomes safer, its ability to judge its own remaining flaws improves, creating a powerful self-improving cycle.

Key Insights

  • The Model as its Own Critic: Unified models, which inherently possess both vision and generation capabilities, are surprisingly adept at identifying their own harmful outputs. This eliminates the traditional "human-in-the-loop" bottleneck for safety training.
  • Iteration Beats One-Shot Removal: Removing harmful concepts in multiple small steps proves more effective than a single, large surgical removal. Each iteration refines the boundaries of what the model considers harmful.
  • Orthogonality is Safety: By constraining updates to the null space, the researchers demonstrate that it is possible to improve a model's performance (such as FID scores) without re-introducing mitigated risks.

Experimental Results

The study evaluates Safe-CB across a comprehensive suite of safety and fidelity benchmarks, yielding impressive results:

  • Significant Safety Gains: On the I2P (Inappropriate Image Prompts) benchmark, the generation of sexual content dropped from 0.12 to 0.04, and "shocking" content dropped from 0.53 to 0.32.
  • Cross-Model Applicability: The method successfully enhanced five different architectures, including Janus-pro (1B and 7B), VILA-U, Emu3, LlamaGen, and OmniMamba, demonstrating broad applicability.
  • Preserved Performance: Unlike traditional weight-modification methods that often degrade prompt adherence, Safe-CB maintained near-original scores on the MMMU reasoning benchmark (29.1 vs. 29.0) and Geneval (0.64 vs. 0.62).
  • Out-of-Distribution Robustness: A codebook trained specifically to avoid "violence" also exhibited improved safety on related but unseen categories, such as "cruelty" and "weapons."

Limitations and Future Directions

While highly effective for overt harms like nudity or gore, the model struggles with more abstract or "pragmatic" harms, such as hate speech or fraud, where human labels still provide a slight edge. Additionally, there is a risk of self-labeling bias: if the base model harbors deep-seated biases, its self-judgment might lead to an over-sensitive filter or miss culturally specific harms.

Future work will explore "combined" risks, where a text prompt and an image are individually benign but become harmful when generated together. Overall, Safe-CB represents a significant step forward in scalable, autonomous alignment for the next generation of autoregressive visual models.

Summary updated

BibTeX
@inproceedings{xue2026safe,
  author = {Yunqi Xue and Zhijiang Li and Philip Torr and Jindong Gu},
  title = {{Safe Autoregressive Image Generation with Iterative Self-Improving Codebooks}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=hASSCnNDOl},
}
Figure