Abstract
Text-to-image diffusion models excel at translating language prompts into photorealistic images by implicitly grounding textual concepts through their cross-modal attention mechanisms. Recent multi-modal diffusion transformers (MM-DiT) extend this by introducing joint self-attention over concatenated image and text tokens, enabling richer and more scalable cross-modal alignment. However, a detailed understanding of how and where these attention maps contribute to image generation remains limited. In this paper, we introduce Seg4Diff (Segmentation for Diffusion), a systematic framework for analyzing the attention structures of MM-DiT, with a focus on how specific layers propagate semantic information from text to image. Through comprehensive analysis, we identify a semantic grounding expert layer, a specific MM-DiT block that consistently aligns text tokens with spatially coherent image regions, naturally producing high-quality semantic segmentation masks. We further demonstrate that applying a lightweight fine-tuning scheme with mask-annotated image data enhances the semantic grouping capabilities of these layers and thereby improves both segmentation performance and generated image fidelity. Our findings demonstrate that semantic grouping is an emergent property of diffusion transformers and can be selectively amplified to advance both segmentation and generation performance, paving the way for unified models that bridge visual perception and generation.
Introduction
The evolution of text-to-image (T2I) diffusion models has seen a significant shift from traditional U-Net architectures to Diffusion Transformers (DiTs). Models like Stable Diffusion 3 (SD3) and Flux utilize Multi-modal DiTs (MM-DiTs), where image and text tokens are processed simultaneously within joint self-attention layers. While U-Nets offered relatively interpretable cross-attention maps for "training-free" segmentation, MM-DiTs present a "black box" challenge. The internal mechanisms of semantic grounding—how the model associates specific pixels with textual concepts—remain poorly understood in these newer architectures.
The Seg4Diff Framework
Seg4Diff is a framework designed to analyze and leverage the internal representations of MM-DiTs for dense perception tasks. By investigating the layer-wise behavior of models like SD3, we identified that semantic grounding is not a uniform process. Instead, it is an emergent property that peaks in specific "semantic grounding expert" layers.
Identifying the Expert Layer
Through PCA and norm analysis, we found that Layer 9 in SD3 and Layers 12 and 17 in Flux act as "experts" for semantic grounding. In these layers, the Image-to-Text (I2T) attention maps are remarkably clean and spatially coherent. While Text-to-Image (T2I) attention updates text tokens, it is the I2T attention that injects semantic information into image tokens, making it the primary driver for segmentation.
Zero-Shot and Unsupervised Segmentation
By extracting and averaging I2T attention across heads in these expert layers, Seg4Diff can produce high-quality segmentation masks without additional training. Interestingly, even "padding" tokens in unconditional generation act as anchors, specializing in different semantic regions to help the model organize the visual space.
MAGNET: Boosting Segmentation and Generation
To further enhance these capabilities, we propose MAGNET (Mask Alignment for Segmentation and Generation). This lightweight fine-tuning strategy uses Low-Rank Adaptation (LoRA) to optimize two objectives: the standard flow-matching loss to maintain image fidelity, and a new mask loss ($L_{mask}$). The mask loss uses bipartite matching to align internal attention maps with ground-truth masks.
This dual optimization "teaches" the expert layers to be more precise, leading to a synergistic improvement where better perception (segmentation) directly translates to better generation (structural coherence).
Experimental Results
We evaluated Seg4Diff across multiple benchmarks, including Pascal VOC, COCO, and ADE20K.
- Segmentation Performance: Seg4Diff achieves state-of-the-art results for open-vocabulary segmentation, reaching 89.2 mIoU on Pascal VOC, significantly outperforming previous diffusion-based methods like iSeg (82.9) and DiffSegmenter (66.4).
- Generation Quality: MAGNET improves the CLIPScore across datasets and shows substantial gains in compositional accuracy (e.g., attribute binding) on T2I-CompBench++.
- Structural Coherence: Qualitative results demonstrate that MAGNET-trained models produce fewer structural errors, such as incorrect object counts or misplaced limbs, by enforcing stronger spatial grounding.
Conclusion and Future Work
Seg4Diff reveals that semantic grouping is an inherent, emergent property of MM-DiTs. By identifying and amplifying these "expert" layers, we can bridge the gap between visual perception and generation. Future work will focus on scaling these models to handle smaller objects more effectively and extending the framework to high-level reasoning tasks beyond dense perception.
Summary updated