# FastComposer: Tuning-Free Multi-Subject Image Generation with Localized Attention

Guangxuan Xiao, Tianwei Yin, William T. Freeman, Frédo Durand, Song Han · arXiv · 2023-5-17

- **Problem** Personalizing a diffusion model to a new person usually means fine-tuning it for that person, which is costly, and multi-subject prompts make different people's features bleed into each other.
- **Method** Adds identity features from reference photos to the text embeddings of Stable Diffusion with a CLIP-based MLP, supervises cross-attention maps with subject masks during training, and switches on subject conditioning only after the early denoising steps.
- **Results** Reached 51.41% identity preservation on single-subject generation against 43.37% for Custom Diffusion, and 43.11% on multi-subject pairs against 13.52% for Textual-Inversion.

![Figure 3: Training and inference pipeline of FastComposer. Given a text description and images of multiple sub- jects, FastComposer uses an image encoder to ex…](https://refivu.com/papers/da96ee97-6c27-4d11-88b7-679762995493/figures/figure-7be4523b1f0e48b6ed6865bf4bd893e2.png?thumb=512)

**Figure 3** : Training and inference pipeline of FastComposer. Given a text description and images of multiple sub- jects, FastComposer uses an image encoder to extract the features of the subjects and augments the corresponding text tokens. The diffusion model is trained to generate multi-subject images with augmented conditioning. We use cross-attention localization (Sec. 4.2) to boost multi-subject generation quality, and delayed subject conditioning to avoid subject overﬁtting (Sec. 4.3).

[Original paper](https://arxiv.org/abs/2305.10431v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Guangxuan Xiao, Tianwei Yin, William T. Freeman, Frédo Durand, Song Han · FastComposer: Tuning-Free Multi-Subject Image Generation with Localized Attention · Original paper figure · Extracted the figure area from page 4 of the original PDF.

## Why personalization and multi-subject prompts are hard

Subject-driven generation adapts a text-to-image model to a person seen only in a few sample images. Most existing approaches reach their best fidelity by fine-tuning the model for each new subject. Fine-tuning needs backpropagation, which raises memory use and computation, so these methods cannot run comfortably on phones and are hard to scale in the cloud.

With several people in one prompt, the same model tends to mix their features, so one subject takes on traits of another. The authors call this identity blending. Figure 2 illustrates the failure: a generated Newton picks up features of Einstein, and in a second failure the model overfits the reference photo and ignores the edit requested in the text.

## How reference images enter the text embedding

FastComposer keeps Stable Diffusion as the backbone and changes only the conditioning. The embeddings of the words that name subjects are augmented with identity features from reference images, rather than the weights being tuned for each subject. The prompt and the reference subject images are encoded with the pre-trained CLIP text encoder ψ and image encoder φ.

The index list maps each reference subject to the word in the prompt it replaces in the conditioning.

Each subject word's embedding is concatenated with the image feature of its matched subject and passed through a multilayer perceptron. Words that are not matched to any subject keep their original embedding. Formally, the augmented embedding is defined as follows, where n is the number of prompt words and I is the set of subject indices.

\\\[ c'\_i = \\begin{cases} \\psi(P)\_i, & i \\notin I \\\\ \\mathrm{MLP}(\\psi(P)\_i \\,\\\|\\, \\varphi(s\_j)), & i = i\_j \\in I \\end{cases} \\\] Because the identity enters as a forward pass through the image encoder, a new subject needs no new weights. The abstract states that this requires zero extra storage for new subjects.

## Training data and training setup

The training pairs are built from FFHQ-wild. BLIP-2 generates a caption for each image, Mask2Former produces panoptic masks, and spaCy extracts the noun phrases from the captions. Noun phrases are matched to image segments greedily, using the product of an OpenCLIP image-text similarity and a Sentence-Transformer label-text similarity. A set of 1000 images is held out for validation and testing.

Backgrounds of the subjects are masked with random noise before encoding, so that natural photos can be used at inference without a separate background segmentation step.

Only segments labelled "person" are augmented, with at most 4 reference subjects per training example, and each subject has a 10% chance of being dropped. Some samples are trained text-only, and some with no condition, to keep text generation and classifier-free guidance working.

## Supervising cross-attention with subject masks

The authors identify this unregulated cross-attention as the main reason for identity blending: when two "person" tokens are present, each token's map covers both people rather than one.

The fix is to supervise each subject token's attention map with the segmentation mask of its reference subject. The loss compares the mean attention outside the mask with the mean attention inside it. \\\[ L\_{loc} = \\frac{1}{m}\\sum\_{j=1}^{m}\\left(\\mathrm{mean}(A\_{ij}\[\\bar{m}\_j\]) - \\mathrm{mean}(A\_{ij}\[m\_j\])\\right) \\\] Minimizing this term raises attention inside each subject's mask relative to the region outside it, which pushes the subjects toward non-overlapping regions.

The total objective adds this term to the denoising loss, \\\[ L = L\_{noise} + \\lambda L\_{loc}, \\\] with λ = 0.001. The loss is applied to the middle 5 blocks of the U-Net, which the authors chose because these blocks hold more semantic information. Segmentation masks and this regularization are used only in training, not at test time.

## Delaying subject conditioning during denoising

Applying the augmented embedding from the first step makes the image copy the reference face and drop the text instruction. The authors explain this by the layout forming in the early denoising steps, while premature subject features push it away from the prompt. The fix borrows the idea of Style Mixing: the layout is fixed with the text-only prompt first, and subject identity is added later.

The noise prediction uses the original embedding c while the timestep is above αT, and the augmented embedding c′ otherwise. \\\[ \\epsilon\_t = \\begin{cases} \\epsilon\_\\theta(z\_t,t,c) & \\text{if } t \> \\alpha T, \\\\ \\epsilon\_\\theta(z\_t,t,c') & \\text{otherwise} \\end{cases} \\\] Here α is the ratio of steps that use subject conditioning. The authors report that α between 0.6 and 0.8 gives a good balance between prompt consistency and identity preservation.

## Single-subject results against optimization baselines

The test set uses 15 subjects derived from Celeb-A, each with 30 prompts covering recontextualization, stylization, accessorization and actions. Identity preservation detects faces with MTCNN and scores pairs with FaceNet, while prompt consistency is the average CLIP-L/14 image-text similarity. The baselines use five images per subject, whereas FastComposer uses one randomly selected image.

FastComposer reached 51.41% identity preservation and 24.30% prompt consistency in Table 1. Custom Diffusion scored 43.37% and 23.29%, Textual-Inversion 29.26% and 21.91%, and DreamBooth 27.27% and 23.91%. Text-only Stable Diffusion, with no subject conditioning, scored 3.85% identity preservation and the highest prompt consistency at 26.79%.

The time column includes fine-tuning for the tuning-based methods, and FastComposer takes 2 s against 789 s to 2500 s for them. Peak memory is 6 GB for FastComposer against 17 GB, 40 GB and 29 GB for the baselines. The single-subject comparison reports a 300×-1200× speedup and a 2.8× reduction in memory usage. The abstract gives a wider 300×-2500× range for fine-tuning-based methods.

## Multi-subject results on subject pairs

In Table 2, FastComposer reached 43.11% identity preservation and 24.25% prompt consistency, with a total time of 2 s and 6 GB peak memory. Textual-Inversion reached 13.52% identity preservation and 21.08% prompt consistency at 4998 s, and Custom Diffusion reached 5.37% and 25.84% at 789 s. Table 2 has no DreamBooth row, and text-only Stable Diffusion reached 1.88% identity preservation.

The authors say the optimization baselines often produce generic images or blend the identities of different reference subjects, which the identity score reflects. They describe FastComposer's prompt consistency as on par with the tuning-based approaches Textual-Inversion and Custom Diffusion. Figure 1 gives qualitative comparisons, and three-subject examples appear in Figure 7.

## What the localization loss and the timestep ratio contribute

Table 3 compares the same training setting with and without the cross-attention localization loss. Only the localization term is removed, and the denoising loss is kept. Identity preservation is 43.11% with the loss and 37.66% without it. Prompt consistency is 24.25% with the loss and 25.03% without it.

The identity gain comes with a slightly lower prompt consistency in this comparison. The authors attribute the identity gain to the model focusing on particular reference subjects, which avoids identity blending.

Figure 5 varies the ratio of timesteps that use subject conditioning. As the ratio grows, identity preservation improves while editability falls, and a ratio between 0.6 and 0.8 gives the favorable tradeoff the authors chose.

## Limitations

The training set is FFHQ, which is small and mostly contains headshots of faces. Its long-tailed distribution of person counts limits generation to more than three subjects, according to the authors. Training allows up to 4 reference subjects, but the authors state that the dataset limits generation beyond three subjects.

The work is primarily human-centric because large-scale multi-subject datasets with other subjects, such as animals, are scarce. The authors expect a broader dataset to widen the range of actions and scenarios.

## Paper info

- **Authors**: Guangxuan Xiao, Tianwei Yin, William T. Freeman, Frédo Durand, Song Han
- **Venue**: arXiv · Preprint
- **First published**: 2023-5-17
- **Added**: 2026-11-6
- **Updated**: 2023-5-21
- **Version**: v2
- **arXiv**: 2305.10431
- **Category**: cs.CV
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2305.10431v2) · [PDF ↗](https://arxiv.org/pdf/2305.10431v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

Diffusion models excel at text-to-image generation, especially in subject-driven generation for personalized images. However, existing methods are inefficient due to the subject-specific fine-tuning, which is computationally intensive and hampers efficient deployment. Moreover, existing methods struggle with multi-subject generation as they often blend features among subjects. We present FastComposer which enables efficient, personalized, multi-subject text-to-image generation without fine-tuning. FastComposer uses subject embeddings extracted by an image encoder to augment the generic text conditioning in diffusion models, enabling personalized image generation based on subject images and textual instructions with only forward passes. To address the identity blending problem in the multi-subject generation, FastComposer proposes cross-attention localization supervision during training, enforcing the attention of reference subjects localized to the correct regions in the target images. Naively conditioning on subject embeddings results in subject overfitting. FastComposer proposes delayed subject conditioning in the denoising step to maintain both identity and editability in subject-driven image generation. FastComposer generates images of multiple unseen individuals with different styles, actions, and contexts. It achieves 300$\\times$-2500$\\times$ speedup compared to fine-tuning-based methods and requires zero extra storage for new subjects. FastComposer paves the way for efficient, personalized, and high-quality multi-subject image creation. Code, model, and dataset are available at https://github.com/mit-han-lab/fastcomposer.

## Quote from the paper

Guangxuan Xiao, Tianwei Yin, William T. Freeman, Frédo Durand, Song Han (2023). FastComposer: Tuning-Free Multi-Subject Image Generation with Localized Attention. arXiv:2305.10431v2. https://arxiv.org/abs/2305.10431v2

**BibTeX**

```
@misc{xiao2023fastcomposer,
  title = {{FastComposer: Tuning-Free Multi-Subject Image Generation with Localized Attention}},
  author = {Guangxuan Xiao and Tianwei Yin and William T. Freeman and Frédo Durand and Song Han},
  year = {2023},
  eprint = {2305.10431},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.10431v2}
}
```

## Other paper commentary

- [MagicAnimate: Temporally Consistent Human Image Animation using Diffusion Model](https://refivu.com/en/papers/d7e4c79d-ac46-4e0f-aef6-34e570d43e2f-magicanimate-temporally-consistent-human-image-animation.md)
- [Train for the Worst, Plan for the Best: Understanding Token Ordering in Masked Diffusions](https://refivu.com/en/papers/64d5ed83-79ac-4425-8629-7aff772bd0c4-train-for-the-worst-plan-for-the-best.md)
- [Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow](https://refivu.com/en/papers/a0c4439d-88d7-4d0f-be30-5509d158003e-flow-straight-and-fast-learning-to-generate-and.md)
- [Photorealistic Text-to-Image Diffusion Models with Deep Language Understanding](https://refivu.com/en/papers/eaa0c3ba-e0e4-4517-8ef7-d6ec6ba261b6-photorealistic-text-to-image-diffusion-models-with-deep.md)
- [Consistency Models](https://refivu.com/en/papers/f97e5129-1522-4b93-9b60-0a1f3af22d42-consistency-models.md)
- [Adding Conditional Control to Text-to-Image Diffusion Models](https://refivu.com/en/papers/071adc96-6d0d-4210-ac05-74ff8d4cb5aa-adding-conditional-control-to-text-to-image-diffusion.md)
- [Continuous online sequence learning with an unsupervised neural network model](https://refivu.com/en/papers/2850b462-149b-4637-8186-0e3a02a69df4-continuous-online-sequence-learning-with-an-unsupervised.md)
- [A Cost-Sensitive Deep Belief Network for Imbalanced Classification](https://refivu.com/en/papers/140fac18-43ea-4f02-a761-0549f84a0de3-a-cost-sensitive-deep-belief-network-for-imbalanced.md)
- [Multi-Temporal Land Cover Classification with Sequential Recurrent Encoders](https://refivu.com/en/papers/fbc752d9-1a2a-4b13-ac64-8967dd7bd971-multi-temporal-land-cover-classification-with-sequential.md)
- [StyleFlow: Attribute-conditioned Exploration of StyleGAN-Generated Images using Conditional Continuous Normalizing Flows](https://refivu.com/en/papers/49804159-5719-4639-92c6-0d48431420f2-styleflow-attribute-conditioned-exploration-of-stylegan.md)
- [Deep Reinforcement Learning for Stochastic Computation Offloading in Digital Twin Networks](https://refivu.com/en/papers/3abcd222-e3a8-4466-ab8d-04aeace1e847-deep-reinforcement-learning-for-stochastic-computation.md)
- [Federated Social Recommendation with Graph Neural Network](https://refivu.com/en/papers/ce54fcd7-f119-4f48-9809-3fe4f5cc05cd-federated-social-recommendation-with-graph-neural-network.md)

## Terms in this paper

- [CLIP](https://refivu.com/en/terms/b5b5b48d5f4e-clip)
- [Multilayer Perceptron](https://refivu.com/en/terms/0892ee9508d3-multilayer-perceptron)
- [Balanced L1 loss](https://refivu.com/en/terms/b5acbf241583-balanced-l1-loss)
- [cross-attention mechanism](https://refivu.com/en/terms/958dddc88dce-cross-attention-mechanism)
- [DreamBooth](https://refivu.com/en/terms/0469e4e7700d-dreambooth)
- [FaceNet](https://refivu.com/en/terms/bbc4f927d331-facenet)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/da96ee97-6c27-4d11-88b7-679762995493-fastcomposer-tuning-free-multi-subject-image-generation-with)
