All models

QFormer

A simplified Querying Transformer (Q-Former), the BLIP-2 module that links image encoders to language models.

Graphs and geometry · 40 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (45 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
1.3K
Operations
40
Framework
PyTorch
Recurrent
No
Published
ICML (arXiv 2023)
Cited by
12,961 (as of 30 November 2026)
Authors
Junnan Li, Dongxu Li, Silvio Savarese, Steven C. H. Hoi
License
MIT
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m2369
Graph hash
915c5059daca1fff814ba90e504f6c74e31fc142eaeb4b9cad93ffb389d6d3a3
Skeleton hash
01ae5d7b7f7d1635041a6db4b2b48ab94e4e378991f6c7701cbdb456f0e5edd0
Architecture hash
4a2762ae4b681fef4a1f84dbf9e666401f8f6c9562363cc4bf8bbfe54d83aac1
Diagram SHA-256
9a9b24752963d845918a7d2d52337041ed656deb68352c59c2b76a9e716ee11e
TorchLens version
2.35.3
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

How this diagram was made

torch_geometric.nn.QFormer(input_dim=8, hidden_dim=16, output_dim=4, num_heads=2, num_layers=1)

What it is

This is the Querying Transformer, or Q-Former, in the simplified version that the torch_geometric library provides. The Q-Former comes from the BLIP-2 paper, which proposes it as the trainable module that bridges the gap between a frozen image encoder and a frozen large language model.

In the paper, the Q-Former is a lightweight transformer that uses a set of learnable query vectors to extract visual features from the frozen image encoder. The queries interact with each other through self-attention layers and with the frozen image features through cross-attention layers. The Q-Former extracts a fixed number of output features from the image encoder, independent of the input image resolution. The paper describes this as an information bottleneck between the frozen image encoder and the frozen language model. The paper reports that its Q-Former contains 188M parameters. Its experiments use 32 queries, each with a dimension of 768.

The simplified version is configured by the number of input features, a hidden dimension, an output dimension, the number of attention heads and the number of encoder layers.

Key idea. BLIP-2 introduced the Q-Former, a lightweight transformer whose learnable query vectors extract visual features from a frozen image encoder for a frozen large language model.

  • Q-Former
  • QFormer
  • Querying Transformer
  • torch_geometric QFormer
  • learnable queries
  • query transformer
  • vision-language bridge
  • simplified Q-Former

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{li2023blip2bootstrappinglanguageimagepretraining,
      title={BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models}, 
      author={Junnan Li and Dongxu Li and Silvio Savarese and Steven Hoi},
      year={2023},
      eprint={2301.12597},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2301.12597}, 
}