Frozen Transformers in Language Models Are Effective Visual Encoder Layers

Ziqi Pang, Ziyang Xie, Yunze Man, Yu-Xiong Wang

Abstract

This paper reveals that large language models (LLMs), despite being trained solely on textual data, are surprisingly strong encoders for purely visual tasks in the absence of language. Even more intriguingly, this can be achieved by a simple yet previously overlooked strategy -- employing a frozen transformer block from pre-trained LLMs as a constituent encoder layer to directly process visual tokens. Our work pushes the boundaries of leveraging LLMs for computer vision tasks, significantly departing from conventional practices that typically necessitate a multi-modal vision-language setup with associated language prompts, inputs, or outputs. We demonstrate that our approach consistently enhances performance across a diverse range of tasks, encompassing pure 2D and 3D visual recognition tasks (e.g., image and point cloud classification), temporal modeling tasks (e.g., action recognition), non-semantic tasks (e.g., motion forecasting), and multi-modal tasks (e.g., 2D/3D visual question answering and image-text retrieval). Such improvements are a general phenomenon, applicable to various types of LLMs (e.g., LLaMA and OPT) and different LLM transformer blocks. We additionally propose the information filtering hypothesis to explain the effectiveness of pre-trained LLMs in visual encoding -- the pre-trained LLM transformer blocks discern informative visual tokens and further amplify their effect. This hypothesis is empirically supported by the observation that the feature activation, after training with LLM transformer blocks, exhibits a stronger focus on relevant regions.

Introduction

Large Language Models (LLMs) like LLaMA and GPT have demonstrated remarkable "world knowledge" derived from massive textual corpora. Traditionally, utilizing this knowledge for computer vision has involved building Vision-Language Models (VLMs) that project images into visual tokens and feed them to the LLM alongside text prompts. However, this research explores a more fundamental question: Can the internal architecture of an LLM benefit purely visual tasks where no language is involved?

The authors demonstrate that a single, frozen transformer block from a pre-trained LLM can act as a powerful "information filter" for visual tasks. By integrating a LLaMA or OPT block into standard vision pipelines, they achieve consistent performance gains across 2D images, 3D point clouds, video, and motion forecasting—all without any textual input or output.

Architecture and Methodology

The proposed strategy is elegantly simple. Instead of complex multi-modal alignment, the researchers insert a single transformer block from a pre-trained, frozen LLM (e.g., LLaMA-7B) into a standard visual encoder pipeline, such as a Vision Transformer (ViT) or Point-BERT.

The architecture (a) inserts a frozen LLM transformer block between two trainable linear layers to process visual tokens, as shown in the pseudo-code (b).

As illustrated in Figure 1, the setup involves:

  1. Insertion: Extracting a transformer block from an LLM and appending it to the visual encoder.
  2. Alignment: Adding two small, trainable linear layers—one before the LLM block to project visual tokens into the LLM's dimension, and one after to return them to the original visual feature space.
  3. Modifications: Stripping away text-specific components like positional embeddings and causal attention masks, as visual tokens do not follow a strict sequential order.
  4. Freezing: Keeping the LLM block completely frozen during training. Only the original vision backbone, the linear projection layers, and the task-specific head are updated.

The Information Filtering Hypothesis

To explain why a text-trained block helps with vision, the authors propose the Information Filtering Hypothesis. They argue that LLM blocks act as a filter that distinguishes informative visual tokens (the object of interest) from background noise.

Visualizations of feature activations (a) and attention scores (b) show that models with LLM blocks focus more sharply on foreground objects compared to standard ViT baselines.

As seen in Figure 3, visual tokens passing through the frozen LLM block exhibit "emergent segmentation." The feature activations naturally focus on foreground objects, effectively performing object segmentation as a side effect of the patterns learned during text pre-training. Interestingly, keeping the LLM block frozen was found to be critical; fine-tuning actually hurt performance, likely due to overfitting on smaller vision datasets.

Experimental Results

The "plug-and-play" method was evaluated across a wide variety of benchmarks:

  • 2D Image Classification: On ImageNet-1k, adding a LLaMA block to a ViT-Tiny improved accuracy from 72.1% to 73.2%. For ViT-Base, it increased from 80.6% to 81.7%. The models also showed increased resilience to image corruptions in robustness benchmarks.
  • 3D Point Cloud Classification: On ScanObjectNN, the LLaMA block boosted performance across all splits (e.g., from 83.1% to 83.8% on the T50 split).
  • Action Recognition (Video): Performance on the Something-Something-v2 (SSv2) dataset jumped from 64.71% to 65.89% for ViT-Small.
  • Motion Forecasting: Gains were also observed in non-semantic tasks like predicting trajectories in the Argoverse dataset.

The benefits appear to be a function of scale, with significant gains emerging from blocks of 1.3B or 7B parameter models, while smaller models like OPT-125M sometimes underperformed the baseline.

Discussion and Conclusion

This work demonstrates that the "intelligence" within LLMs is remarkably versatile, acting as a high-quality lens that enhances visual encoding. While the "Information Filtering" hypothesis provides a compelling explanation supported by visualization, the exact mechanism of how text-based pre-training translates to visual foreground detection remains an area for further study. Additionally, the computational overhead of billion-parameter frozen blocks is a practical consideration for inference. Future research may explore the use of multiple interleaved blocks or more efficient ways to harness these emergent visual capabilities.

Summary updated

BibTeX
@inproceedings{pang2024frozen,
  author = {Ziqi Pang and Ziyang Xie and Yunze Man and Yu-Xiong Wang},
  title = {{Frozen Transformers in Language Models Are Effective Visual Encoder Layers}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=t0FI3Q66K5},
}
Figure