# Poster 28808

- Kind: Poster
- Talk page and recording: https://iclr.cc/virtual/2025/poster/28808

> Transcript of the talk's recording (session_asr), made by speech recognition or taken from the host's captions. It may contain errors. The words are the speakers'; listen to the recording on the talk's page before quoting it.

Hi all! It's our great pleasure to present the worked precise parameter localization for textual generation in diffusion models. It's a joint work of myself, Łukasz Staniszewski and Bartosz Tywiński as leading project contributors with invaluable guidance and mentoring from Francisca Banisz, Camille Dea and Adam Dzierżic.
In two sentences: thanks to the activation patching technique, which is presented on the animation below, we find that less than 1% of all diffusion model parameters determine the textual content on generated images. Next, we propose a new approach to a robust diffusion model fine -tuning, image-to-image text addition, and preventing the generation of harmful text.
Recent advances in image generation have enabled diffusion models to produce visually plausible text that aligns with user prompts. Motivated by studies demonstrating that modifying embeddings in cross-attention layers can control the generation of concepts such as styles or objects, we investigate which attention layers are responsible for textual content generation. First, we localize layers in unit-based diffusion models, such as stable diffusion or deepfloid IF.
In these models, each cross-attention layer receives the prompt in the form of embeddings produced by the text encoder. Thanks to that, instead of passing the prompt describing the image background, which we denote as source prompt, to each cross-attention layer, we can inject the target prompt describing desired text to a single layer. Finally, if the output image contains the target text, it indicates that the injected layer controls the content of the generated text.
However, this approach is impractical for transformer-based diffusion architectures, such as stable diffusion-free or flux, where the prompt embedding is modified as it passes through successive attention layers. Here, we leverage the activation patching method. First, we input a prompt describing the text into the diffusion model and cache key and value attention activations.
In the second stage we input the prompt describing the image and patch a single layer with the cached activations, what results in the image with only the text changed. By searching for the layers with our localization methods we identify three layers in Stable Diffusion XL as well as only one layer in DeepFloyd IF and Stable Diffusion Free. Those layers, when patched, produce text that closely matches the text in the target prompt. We measure this alignment using the OCRF1 score.
Most notably, localized layers account for less than 1% of all the Mototan model parameters. Usual Lora-based fine-tuning procedures target all attention layers within diffusion models. As the first application for our localization insights, we propose to fine-tune the localized layers only. This significantly improves the text generation capabilities of diffusion model, which we measure by OCR and clip text image alignment.
This enhancement is achieved without compromising output quality, measured using precision, and diversity as measured by recall. By focusing solely on localized layers, our approach is efficient in terms of both computation and memory. Next, we use the localized layers to edit textual content in generated images while keeping the rest of the image unchanged. We provide additional examples for stable diffusion Excel.
Deep Learning, as well as Stateful Diffusion-Free. Additionally, we are performing the prompt-to-prompt method in text editing tasks by generating higher quality text while preserving the rest of the visual content. Moreover, our approach is significantly faster.
Finally, we observe that diffusion models, even the ones equipped with safeguards against generating not safe for work content, tend to simply copy and paste the harmful text from the props to the images. Compared to other methods, our addition entirely removes toxic text from the images while keeping other visual attributes unchanged. Such removal is possible with a single pass through the diffusion denoising process without imposing any additional computational costs.
And that's all. Thank you for listening to this presentation. If you find our work interesting, please visit the official project page for more valuable insights. If you have any questions, don't hesitate to reach out to the authors.
