TL;DR
A text-to-image diffusion model draws what a text prompt describes, but words are a poor way to describe a face, a painting style or a particular object. An image prompt says it directly. IP-Adapter adds image prompting to a frozen model by inserting one small extra attention layer beside each existing text attention layer. Only the new layers are trained, about 22 million parameters, and the result works with text prompts too.
Builds on: Latent Diffusion Model, Classifier-Free Guidance, Attention Mechanism, Adapter Tuning, Decoupled Cross-Attention · Leads to: image-prompted generation that combines with structure controls such as ControlNet.
Why it mattered
The paper's target is the family of open text-to-image models built on Stable Diffusion, which the authors used as their base (version 1.5). Many people share fine-tuned checkpoints of that base, each with its own style, and a user of a checkpoint may want to say "make it look like this picture" without writing a long description. Before this paper, the two easy routes both had costs. Fine-tuning the whole model on image prompts needs large compute, and the resulting model loses the ability to follow text. Simple adapters, which feed image features into the existing text layers, reached far less quality than fully fine-tuned models.
IP-Adapter showed that a small adapter could reach the quality of a fully fine-tuned image-prompt model, and that the same adapter could be reused on other fine-tuned models from the same base. The paper also shows that it can be combined with ControlNet-style structure maps, so one prompt can give content and another can give the layout.
The problem
A diffusion model generates an image by repeatedly removing noise. At each step, its U-Net has attention layers that look up the conditioning, which for a text-to-image model is the vectors of the text prompt. Those layers were trained only to read text. Consider the simple way to add an image: encode it with a CLIP image encoder (see Learning Transferable Visual Models From Natural Language Supervision (CLIP)), map those features to a sequence of vectors, and concatenate them with the text vectors so the same frozen layers read both. The authors argue that the frozen key and value weights were learned for text, so image features forced into them get aligned with text, and image-specific detail is lost. That explains why earlier adapters fell short of fully fine-tuned image-prompt models.
The fix is to give image features their own attention layer, with its own weights, while keeping the text path exactly as it was.
How it works
Here is the pipeline in the order it runs, followed by one tiny layer traced by hand.
flowchart LR R["Reference image"] --> E["Frozen CLIP image encoder"] E --> P["Trainable projection: one embedding to 4 tokens"] P --> A["Image attention layer, new and trained"] T["Text prompt"] --> B["Frozen text attention layer"] Q["Image being denoised"] --> B Q --> A B --> S["Sum of the two outputs"] A --> S S --> N["Next layer of the u-net"]
-
Encode the reference image. A frozen CLIP image encoder turns the reference picture into one global embedding. The paper uses the global embedding because it captures the content and style of the picture. Check: one picture gives one vector here.
-
Project the embedding into a short sequence. A small trainable network, a linear layer followed by layer normalization, turns that one vector into 4 vectors with the same width as the text tokens. Check: the output has 4 rows, the width the text path expects.
-
Run the original text attention. For each spatial position of the image being drawn, the frozen layer looks up the text tokens and returns a weighted mix of their values. This output does not change from the base model.
-
Run the new image attention with the same query. The layer uses the same query vectors as step 3. It builds a new key and a new value from the 4 image tokens, with two new weight matrices. It then does the usual attention mix over those image values. Check: only two matrices are new per layer, because the query is shared.
-
Add the two outputs. The image output is added to the text output. Check: if the image output were zero, the sum would equal the base model's text output exactly.
-
Repeat for every cross-attention layer. The base model has 16 such layers, and each one gets its own image layer. The sum then flows on to the next block of the u-net.
-
Train only the new parts. During training the base model is frozen. Only the projection network and the image key and value matrices are updated. Check: the trainable parameters, about 22 million in total, are a small fraction of the model.
To see the arithmetic, take one query position with head width d = 4, so the scale 1/sqrt(d) is 1/2. Let the query be q = (2, 0, 0, 0). The two text tokens have keys (1, 0, 0, 0) and (0, 1, 0, 0), and values (1, 0) and (0, 1). The scores are q times k divided by 2, giving 1 and 0. The softmax of (1, 0) is about (0.731, 0.269), so the text output is about (0.731, 0.269).
Now the two image tokens have keys (2, 0, 0, 0) and (0, 0, 0, 0), so their scores are 2 and 0. The softmax of (2, 0) is about (0.881, 0.119). With values (1, 0) and (0, 1), the image output is about (0.881, 0.119). Check: the two weights in each softmax add to 1.
Adding the outputs with weight 1 gives about (1.612, 0.388). With weight 0 for the image output the result is the base model's (0.731, 0.269). The weight is the knob that the paper later uses to balance image and text prompts.
The math
In a layer with query matrix Z W_q, text features c_t and image features c_i, the layer output is the text attention plus a separate image attention with the same query. Write Q for the shared queries, and let K and V come from the text, while K' and V' come from the image. Then the output is Softmax(Q K^T / sqrt(d)) V plus Softmax(Q K'^T / sqrt(d)) V', where d is the width of the keys.
Step 2 in symbols: the image tokens
Let c_i be the image sequence made by the projection network from the CLIP embedding. It has N = 4 vectors, each the same width as the text features. Nothing else about the image enters the attention.
Steps 3 to 5 in symbols: the two attention outputs
The text output is Z' = Softmax(Q K^T / sqrt(d)) V, with K = c_t W_k and V = c_t W_v. The image output is Z'' = Softmax(Q K'^T / sqrt(d)) V', with K' = c_i W'_k and V' = c_i W'_v. The shared query Q = Z W_q is the same in both. The paper initializes W'_k and W'_v from W_k and W_v to speed up training, so the new layer starts close to the path the base model already has.
The combined output is Z_new = Z' + Z''. The paper also writes the general form Z_new = Attention(Q, K, V) + lambda times Attention(Q, K', V'), where lambda is a weight. Setting lambda = 0 gives back the original text-to-image model, which is why the weight can balance the two prompts at inference time.
Step 7 in symbols: the training objective
The model is trained with the same noise-prediction loss as the base diffusion model. The predicted noise depends on the noisy latent x_t, the text c_t, the image c_i and the time step t. The loss is the squared distance between the true noise epsilon and the predicted noise, averaged over examples. Only the new parameters receive gradients.
During training the image condition is sometimes dropped, by replacing the CLIP embedding with zeros. This lets the model learn an unconditional path, which classifier-free guidance needs at inference time. The paper writes the guided prediction as w times the conditional prediction plus (1 minus w) times the unconditional prediction. Here w is the guidance scale: it sets how strongly the output follows the condition.
Results
- Comparison with fine-tuned and trained-from-scratch models. On 5,000 COCO validation captions, each with 4 generated images, the paper reports CLIP-T and CLIP-I scores. IP-Adapter scores 0.588 and 0.828, against 0.584 and 0.810 for SD unCLIP, which is fully fine-tuned. Open unCLIP scores higher, at 0.608 and 0.858, but it is trained from scratch with about 893 million parameters.
- Comparison with other adapters. Uni-ControlNet's global controller, with 47 million parameters, scores 0.506 and 0.736. T2I-Adapter's style adapter, with 39 million, scores 0.485 and 0.648. ControlNet Shuffle, with 361 million, scores 0.421 and 0.616. The paper's adapter is clearly ahead of these.
- Reuse. An adapter trained once on SD v1.5 works on community checkpoints fine-tuned from it, including Realistic Vision V4.0 and Anything v4, and mixes their styles.
- Multimodal prompts. Adjusting the image weight lets a text prompt edit attributes or the scene around the image subject.
- Ablation: decoupled attention matters. A simple adapter that concatenates image and text features, trained for the same 200,000 steps, gives lower quality and less consistent images than the decoupled version.
- Ablation: global versus fine-grained features. A variant with 16 learnable query tokens over grid features keeps more of the reference picture, but it also learns spatial structure from the reference, which the paper says can reduce diversity.
- Scale. Training used about 10 million text-image pairs from LAION-2B and COYO-700M, for 1 million steps on 8 V100 GPUs with batch 8 per GPU, using AdamW with learning rate 0.0001.
- Limits. The paper says the adapter reproduces the content and style of a reference image, but cannot match the subject as closely as DreamBooth or Textual Inversion, which fine-tune per subject. Reuse was tested only on models fine-tuned from SD v1.5 (and applied to SD v1.4), so reuse on other base models is not shown.
Reading guide
The paper is short, and most of its value is in Section 3. Read it in this order.
- Section 1, Introduction. Needs Diffusion Model for the basic generator and Learning Transferable Visual Models From Natural Language Supervision (CLIP) for the image encoder. Figure 1 shows the range of tasks.
- Section 2, Related work. Covers Adding Conditional Control to Text-to-Image Diffusion Models (ControlNet) and other adapters. Read it for the contrast with fine-tuning, and with adapters that concatenate features.
- Section 3.1, Preliminaries. Needs Diffusion Model, Latent Diffusion Model, U-Net and Classifier-Free Guidance. The loss is the simplified variational objective; the guidance formula is in the paper's notation.
- Section 3.2.1, Image encoder. Needs Learning Transferable Visual Models From Natural Language Supervision (CLIP) and Layer Normalization for the projection network.
- Section 3.2.2, Decoupled cross-attention. Needs Attention Mechanism and Softmax. This is the core idea; work through the two equations and the final sum, and check that setting the image weight to zero recovers the base model.
- Section 3.2.3, Training and inference. Needs Adapter Tuning for the general idea of training small inserted parts, and Classifier-Free Guidance for dropping the image condition. The weight lambda is introduced here.
- Section 4, Experiments. Mostly tables and figures. Read the setup in 4.1 and the table in 4.2.1. The later subsections are qualitative.
- Section 4.4, Ablations. The decoupled-versus-simple comparison and the fine-grained variant are the two results that test the design.
Check yourself
QuestionWhy does IP-Adapter give image features their own attention layer instead of concatenating them with the text tokens inside the frozen text layer?Show answer
The frozen key and value weights were learned to read text. Concatenated image features are pushed through those weights, so they are aligned toward text and image-specific detail is lost. A separate layer with its own key and value weights can learn to read image features directly, while the text path stays as it was.
QuestionIn the worked trace, the text output is about (0.731, 0.269) and the image output is about (0.881, 0.119). What is the output with image weight 1, and with image weight 0?Show answer
With weight 1 the output is the sum, about (1.612, 0.388). With weight 0 the image term disappears, so the output is the base model's text output, about (0.731, 0.269).
QuestionA base model has 16 cross-attention layers. Each layer gets an image layer that adds two new matrices, and the query is shared with the text layer. How many new matrices does the adapter add, not counting the projection network?Show answer
Two matrices per layer, times 16 layers, gives 32 new matrices. The shared query means no new query matrix is needed.
QuestionWhy is the paper's reuse result on community checkpoints a useful property, and what condition does it depend on?Show answer
A community checkpoint fine-tuned from the same base shares its attention structure, so an adapter trained on the base can be plugged into it without retraining. The condition is that the checkpoint shares the base's architecture and cross-attention layers; the paper's claim is for models fine-tuned from SD v1.5.
QuestionThe paper says IP-Adapter cannot match DreamBooth on subject consistency. Why would a method that trains once for all subjects have that limit?Show answer
It learns a general mapping from any reference image to the attention layers, from one training run on a large dataset. A method like DreamBooth fine-tunes on a few images of one subject. The paper does not analyze the gap in detail, but a plausible reason is that a general adapter spends its capacity on covering many images, not on memorizing one subject.