Transformer2DModel
Diffusers' generic 2D transformer block for image-like data, traced in its continuous latent-diffusion form.
Diffusion and generative · 36 operations Checked
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
- 32.6M
- Operations
- 36
- Framework
- PyTorch
- Recurrent
- No
- Published
- CVPR 2022
- Cited by
- 734 (as of 19 October 2026)
- Authors
- Robin Rombach, Andreas Blattmann, Dominik Lorenz and others
- Source
- diffusers 0.38.0
- License
- Apache-2.0
- Checked
- Passed: the trace was replayed operation by operation and matched the model's own output for this input.
Files
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
Details
- Stable ID
- m3192
- Graph hash
- 2f086f896cad1780af7165ec2dc150878fd8aaae20025d0a2fcbb10001f4c595
- Skeleton hash
- cb319c2fada6e613c7189418b0f9925b5dcb7eb962a13114c9532f16554ee037
- Architecture hash
- 53a3966729e8af3f0313c0b3c13bb1d067c00eca75f4298774584461fc811fee
- Diagram SHA-256
- c52812d806c34e06ca481b6ef1cd943842eefabf18c60ce63fbfbfa0d2dadb91
- TorchLens version
- 2.36.0
- 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
diffusers.Transformer2DModel(in_channels=320)
What it is
Transformer2DModel is the general transformer block that the diffusers library uses for image-like data. The documentation describes it as a Transformer model for image-like data from CompVis, based on the Vision Transformer that Dosovitskiy and colleagues introduced. It accepts two kinds of input, discrete (classes of vector embeddings) or continuous (actual embeddings), and the member traced here runs the continuous path.
On that path the input is projected and reshaped to (batch_size, sequence_length, feature_dimension), the Transformer blocks are applied in the standard way, and the result is reshaped back to an image. The traced member is built with in_channels set, which the documentation says to specify if the input is continuous. What comes out is the hidden states output conditioned on the encoder_hidden_states input. If no encoder hidden states are given, cross-attention defaults to self-attention.
The block's home is the CompVis latent-diffusion repository, released alongside the paper High-Resolution Image Synthesis with Latent Diffusion Models. That repository's own notes say the implementation of the transformer encoder is from x-transformers by lucidrains. In diffusers the class defaults to a single layer of Transformer blocks, so the traced graph is one block deep.
Key idea. One transformer block for image-like data that accepts either discrete (classes of vector embeddings) or continuous (actual embeddings) inputs.
- Transformer2DModel
- SpatialTransformer
- spatial transformer
- diffusers
- latent diffusion
- LDM
- CompVis
- transformer block
- image-like data
- cross attention
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
Cite the paper
@misc{rombach2022highresolutionimagesynthesislatent,
title={High-Resolution Image Synthesis with Latent Diffusion Models},
author={Robin Rombach and Andreas Blattmann and Dominik Lorenz and Patrick Esser and Björn Ommer},
year={2022},
eprint={2112.10752},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2112.10752},
}