Unified Safe Contextual Image Generation in Multimodal Diffusion Transformers via Restricting Unsafe Information FlowUnified Safe In-context Image Generation in Multimodal Diffusion Transformers via Restricting Unsafe Information Flows
The authors propose a training-free framework, UVR, which locates and suppresses unsafe patches on the MM-Attn information flow of MM-DiT; the authors claim erasure rates of 91% and 77% for T2I and I2I, respectively.
Users perform T2I generation with harmful prompts, or I2I editing with harmful reference images plus arbitrary editing instructions, causing open-source MM-DiTs (FLUX.1-dev, FLUX.1-kontext) to generate NSFW, IP character, or inappropriate object content; the defense intervenes at inference time without fine-tuning the model.
- MM-Attn-based DiTs (such as the FLUX series) still generate NSFW and other unsafe content in T2I and I2I; the authors state that existing methods are mostly designed for U-Net or only T2I, and can be bypassed when editing unsafe reference images.
- The authors analyze MM-Attn information flow and propose the training-free UVR: use pre-collected unsafe anchors to localize unsafe regions on output patches, then block unsafe information flow through attention modulation and early noise injection, with T2I and I2I sharing the same mechanism.
- On FLUX.1-dev/FLUX.1-kontext, UVR has 40/854 T2I nudity erasure failures on I2P, and 97/1039 for T2I and 151/1039 for I2I on Unsafe-1K, all fewer than the five baselines; the authors state that quality metrics are largely maintained.
- The authors state that the method is suitable for context-insensitive risk concepts, and context-dependent safety judgments require human supervision; Grounded-SAM may be unreliable for abstract concepts; experiments cover only three models in the FLUX series and a limited concept set.
- Evaluated models
- FLUX.1-devFLUX.1-Kontext-devFLUX.1-schnell
- Benchmarks
- I2PUnsafe-1KMS-COCOImagenHubRing-A-Bell (RAB)Prompt4Debugging (P4D)MMDT
- Metrics
- Erasure rateHarmful rateNudeNet unsafe detectionsFIDCLIPVQAAccFPRGroup Unfairness
The researchers propose UVR, a training-free safe generation framework that intercepts harmful content in multimodal Diffusion Transformer (DiT) image generation by restricting unsafe information flow in multimodal attention. Based on an information-flow analysis of MM-Attn attention dynamics, the framework identifies a task-irrelevant initiation stage, in which unsafe semantics in output patches emerge rapidly and can be accurately localized, followed by a task-relevant semantic amplification and interference stage; accordingly, UVR applies a unified targeted attention modulation to unsafe output patches, explicitly restricting the flow of harmful information. In experiments across multiple concepts, UVR achieves erasure rates of 91% and 77% on image synthesis and editing tasks, respectively, with only slight degradation in visual quality and fidelity. Code is open-sourced at https://github.com/deng12yx/UVR。
Paper analysis
What problem does this paper attempt to solve?
How to design a unified safety mitigation method for MM-Attn-based DiTs that covers both T2I and I2I editing.
Core problem: how to design a unified safety mitigation strategy for MM-Attn-based DiTs that is effective for both T2I synthesis and I2I editing.
- Scenario and importance: MM-DiTs such as SD3, FLUX.1, and FLUX.1-kontext rely on weakly filtered large-scale training data, which the authors state introduces NSFW generation risks; in the I2I scenario, instruction editing further amplifies the risk, and although open-source DiTs undergo safety alignment before release, users can still exploit harmful reference content to generate inappropriate images.
- Shortcomings of existing methods: The authors state that existing safety mechanisms mainly target U-Net architectures or only T2I synthesis, performing text-centric concept erasure and relying on curated prompt datasets; as shown in Figure 1, even if the "nude" concept is removed from the T2I information flow, users can still generate unsafe content by editing unsafe reference images, and such defenses can be bypassed.
- Core observation: The authors analyze MM-Attn attention dynamics and state that there is a task-agnostic semantic priming stage—unsafe semantics are injected into output patches in the first few reverse diffusion steps and can be accurately localized, then propagate through task-specific amplification and interference stages (Figure 3).
- Proposed approach: A training-free, task-agnostic Unified Visual Safety Regulator (UVR) is proposed, which localizes unsafe patches in Oimg during generation and prevents unsafe content generation through attention modulation and explicit restriction of harmful information flow.
- Threat model:
- Attacker goal: Use harmful prompts (T2I) or harmful reference images plus arbitrary editing instructions (I2I) to make the model generate nudity, IP characters, inappropriate objects, etc.
- Knowledge and capability: Uses open-source MM-DiTs (FLUX series), can construct jailbreak prompts (Unsafe-1K based on modifier-driven jailbreak methods).
- Victim systems: FLUX.1-dev (T2I) and FLUX.1-Kontext-dev (I2I).
- Defense setting: Inference-time intervention, no model parameter fine-tuning (training-free).
What related research exists?
Related work falls into three groups: MM-DiT architecture, diffusion model concept erasure, and MM-DiT interpretability; baselines are ESD, SLD, UCE, DES, and EraseAnything.
Multimodal diffusion Transformers (MM-DiT)
- FLUX series (Labs et al., 2025; Shin et al., 2025; Yuan et al., 2025; Zheng et al., 2025) and SD3 series (Esser et al., 2024)—use MM-DiT to generate images corresponding to inputs from noise, performing joint self-attention over concatenated image and text tokens; FLUX.1-kontext appends reference image tokens to output image tokens and distinguishes them with 3-dimensional RoPE position vectors.
Concept erasure in diffusion models
- Early approaches: safety guidance (Schramowski et al., 2023) and post-hoc safety checkers (Rando et al., 2022), which the authors state rely on pretrained detectors or handcrafted guidance prompts.
- Fine-tuning erasure: ESD (Gandikota et al., 2023), UCE (Gandikota et al., 2024), DES (Ahn & Jung, 2026), etc., which erase concepts by realigning conditional noise prediction, modifying text projections, or text embeddings; EraseAnything (Gao et al., 2025a) combines fine-tuning with attention modulation and extends it to FLUX.
- The paper points out: existing FLUX safety methods do not fully exploit the rich representations of MM-Attn, and there is currently no effective method for MM-DiT editing tasks, where I2I editing easily generates unsafe content.
MM-DiT interpretability
- ConceptAttention (Helbling et al., 2025)—uses linear projections to analyze attention outputs, obtaining sharper saliency maps than standard cross-attention; ICEdit (Zhang et al., 2025b) uses value injection for identity-preserving editing; Fluxspace (Dalva et al., 2025) performs fine-grained editing; FreeFlux (Wei et al., 2025) uses RoPE manipulation for automated probing; Stable Flow (Avrahami et al., 2025) identifies key layers usable for inversion.
- The paper points out: these methods are mostly task- or layer-specific and do not provide a unified view of how attention dynamics evolve across diffusion steps and how this relates to safety failures.
Baselines and benchmarks: Comparison baselines are ESD, SLD, UCE, DES, and EraseAnything; evaluation benchmarks include I2P, Unsafe-1K, MS-COCO, ImagenHub, Ring-A-Bell, P4D, and MMDT.
The authors position this paper as: targeting the MM-DiT architecture, uniformly handling safety mitigation for T2I synthesis and instruction-driven editing by analyzing and modulating unsafe information flow in output patch representations and multimodal attention dynamics.
How does the paper address this problem?
UVR first uses unsafe anchors to localize unsafe regions on output patches, then performs attention modulation and early noise injection to block unsafe information flow.
Overall approach: first analyze the attention dynamics of MM-Attn to find the timing and location of unsafe semantic injection, then perform two-stage intervention during generation—visual safety localization and targeted safety modulation—fully training-free.
Attention dynamics analysis (motivation)
- Inter-layer dynamics (task-agnostic): Dblocks have high attention within the same group of tokens (extracting modality-specific information), while Sblocks distribute a large amount of attention across groups (e.g., Itxt→Oimg for T2I, Rimg→Oimg for I2I), responsible for injecting conditional semantics (Figure 3).
- Step-level dynamics (task-specific): In T2I, the first three sampling steps are dominated by Itxt→Oimg (semantic priming stage), then shift to Oimg-Oimg-dominated denoising; in I2I, Rimg→Oimg continues to dominate for most reverse steps, forming a prolonged interference stage.
- Key property: The authors state that in both tasks unsafe information is injected from contextual conditions early, so unsafe patches in Oimg can be reliably localized early without tracing the semantic source.
Visual safety localization
- Unsafe anchor construction: Using generated unsafe images, cache the attention output patch embeddings at corresponding spatial positions in the final diffusion step as the anchor set Ou = { Ot=0(h,w) ∣ (h,w) ∈ Mu }, i.e., the set of patch embeddings extracted from the unsafe mask region; the unsafe mask can be automatically annotated with Grounded-SAM.
- Localization during generation: At each diffusion step, compute the average similarity between the current output patch embeddings and the anchors; those exceeding threshold τ are judged unsafe, yielding a binary mask Mt (Equation 3); localization is performed in the same block as the anchors (written as sblock 10 in the appendix).
- Mask refinement: Keep connected components whose aggregated confidence exceeds threshold ρ to obtain the core mask M̃t, then dilate by radius δ to obtain the final intervention mask M̂t covering surrounding context.
Unified safety modulation
- Modulation formula: For tokens judged unsafe, recompute embeddings as Ot(i) = (1−αt)∑j S(λt(i,j)· at(i,j)) Vt(j) + αt ϵ, where λt attenuates inter-group information flow and αt controls the Gaussian noise injection strength.
- Adaptive modulation: In the core unsafe region (i ∈ M̃t), inter-group flow is strongly suppressed with λ; in the dilated region (i ∈ M̂t \ M̃t), λ weakly suppresses (0 < λ < λ < 1);对 i ∈ M̂t 且 j 为安全图像 token 的组内流设 λo > 1 to enhance benign information.
- Noise injection timing: αt = α · I[i ∈ M̃t] · I[t ≤ t0], injected only during the priming stage; the authors state that later Oimg-Oimg-dominated denoising treats perturbed patches as noise and repairs them.
Key parameters and implementation
- Threshold selection: τ is automatically determined by the probing strategy in Algorithm 3 (∆=0.05, ϵclip=0.4, ϵhr=6); actual values: Nude 0.6, Pikachu 0.35, Blood 0.5, Weapon 0.3.
- Task parameters: T2I sets ρ=0.3, δ=0; I2I sets ρ=0.8, δ=6; α=0.999; for editing, λ=0.2, λ=0.4, λo=1.05.
- Generation settings: 1 image per prompt or reference image, 28 sampling steps, resolution 1024×1024; anchors are built from 2 images by default (29 anchors).
What experiments did the paper conduct?
Evaluated on FLUX.1-dev/kontext for nudity, IP character, and object erasure, UVR has fewer unsafe generations than the five baselines, and robustness, ablation, and transfer experiments were conducted.
Experimental setup
- Models tested: FLUX.1-dev (T2I), FLUX.1-Kontext-dev (I2I); FLUX.1-schnell is used for cross-model transfer.
- Datasets: I2P (854 sexual prompts), Unsafe-1K (1,039 modifier-driven jailbreak prompts), 1,000 MS-COCO captions (generation), 100 instruction-image pairs from ImagenHub (editing); 99 GPT-5-generated prompts per IP/object concept; unsafe reference images for I2I are generated by FLUX.1-dev from I2P and Unsafe-1K.
- Baselines: ESD, SLD, UCE, DES, EraseAnything.
- Metrics and judging: nudity is detected with NudeNet (confidence >0.65 judged as nudity), reporting the number of unsafe images; Harmful rate = unsafe count/total, Erasure rate = 1 − Harmful rate; quality is measured with FID, CLIP, VQA; IP/object is judged by CLIP similarity (thresholds Pikachu 0.28, Blood 0.24, Weapon 0.25).
- Efficiency evaluation: 3×RTX 4090, 1024×1024, 28 steps.
Main results
According to Table 1 (number of unsafe images on I2P / Unsafe-1K, lower is better; quality metrics are VQA/CLIP/FID):
Swipe horizontally to read the table
Method VQA↑ CLIP↑ FID↓ I2P T Unsafe-1K T UCE 87.41 31.31 76.83 53 239 DES 87.31 31.30 76.86 81 242 ESD 86.17 31.09 76.62 48 193 SLD 87.57 31.32 76.58 46 220 EA 86.52 31.17 76.53 86 265 UVR (Ours) 87.44 31.32 76.76 40 97 FLUX.1-dev 87.48 31.31 76.82 207 449 I2I part (same table): UVR has 46 unsafe images on I2P reference images (baselines 69–115, FLUX.1-kontext 175), and 151 on Unsafe-1K reference images (baselines 319–400, FLUX.1-kontext 402); UVR's VQA(u) is 88.42, higher than the second-best ESD's 84.80.
- The authors report that UVR fails on only 40/854 (4.68%) on I2P, with CLIP 0.01% higher than FLUX.1-dev and lower FID.
- The authors report that on Unsafe-1K, UVR is unsafe on only 97/1039 (9.33%), whereas on I2P, due to FLUX's own safety, the highest failure rate among methods is only 86/854 (10.07%).
- The authors report that in I2I, UVR converts 131 images (207−46) into safe outputs while remaining consistent with the reference image content.
IP character and object erasure
- Results: according to Table 2, after I2I erasure of Blood, CLIP(s) rises from 22.34 for FLUX.1-kontext to 24.80, and the safety failure rate drops from 65.9% to 1.1%; in T2I, Harm for each concept drops from 43.2–100% to 9.3–40%.
- Authors' interpretation: the authors state that UVR can effectively erase IP characters and inappropriate objects while preserving the overall appearance of the original image (Figure 6).
Robustness and localization
- P4D/RAB: according to Table 6, on P4D (107 prompts) UVR has 16 unsafe detections (FLUX.1-dev: 80), and on RAB (272 prompts) 24 (FLUX.1-dev: 96); the authors state that the method remains effective under adversarial or stress-test conditions.
- Localization accuracy: according to Table 7, visual patch localization has Acc 0.88–0.99 and FPR 0.01–0.18, comparable to text localization (Text-Attn); the authors state that visual localization can successfully identify the target concept.
Other ablations and analyses
- Core components (Table 2): removing spatial connectivity (w/o Conn) raises T2I Nude Harm from 9.3% to 19.9%; removing feature perturbation (w/o FP) gives T2I Pikachu Harm 100%; in I2I, removing attention decay (w/o Attn) gives Nude Harm 6.9% but lowers CLIP(u) to 20.55–22.53.
- Threshold τ (Figure 7): quality is stable for τ ∈ [0.3, 0.65], and harm rate decreases monotonically as τ decreases; the authors state that UVR is insensitive to τ.
- Number of anchors (Table 4): 2 images already reduce Harm from 43.2% to 9.3%, and 8 images yield only marginal improvement (Harm 8.9%).
- Efficiency (Table 3): UVR adds about 3 MB of GPU memory and takes 25s (unsafe) / 21s (safe), compared with 31s for SLD and 19s for the other baselines.
- Fairness extension (Table 9): on MMDT, Group Unfairness drops from −0.429/−0.556 to −0.048/−0.071, with CLIP 31.31→31.21.
- Cross-model transfer (Table 10): applying FLUX.1-dev anchors directly to FLUX.1-schnell reduces Harm from 42.89% to 14.69%, with CLIP 31.50→31.51.
- Additional concepts (Table 8): Harm for Van Gogh/Taylor Swift drops from 68.49/79.59 to 25.61/27.08.
What are some points that can be further explored?
The authors state that the method is suitable for context-insensitive concepts, context-dependent judgments require human supervision; future work can learn content-aware intervention scheduling.
Limitations and future directions noted by the authors
- Scope of applicability: The authors state that this intervention is best suited to mitigating risk concepts that are relatively insensitive to context (explicit nudity, violent imagery, unauthorized proprietary characters); for safety judgments that depend on context, intent, cultural background, or downstream use (educational, medical, artistic, journalistic depiction), it should be paired with context-aware moderation or human oversight rather than serving as a standalone ethical decision mechanism (Impact Statement).
- Bias issues: The authors state that their analysis found latent biases inherited by pretrained models (e.g., a higher proportion of female nudity in unsafe generations), and that it is necessary to evaluate whether safety interventions preserve or amplify dataset and model biases (Impact Statement).
- Anchor tool limitations: The authors state that Grounded-SAM may be unreliable for highly abstract or open-vocabulary concepts, because it mainly relies on region-level vision-language alignment; this limitation only affects the offline anchor collection stage (Appendix B.2).
- Future directions: Learning content-aware adaptive intervention scheduling, jointly optimizing localization precision and modulation strength, to achieve finer-grained and more robust safety control (Conclusion, stated by the authors as future work).
Experimental coverage
- The models tested are FLUX.1-dev, FLUX.1-Kontext-dev, and FLUX.1-schnell, 3 in total, all belonging to the FLUX series (5.1, Appendix D.2).
- Evaluation concepts cover nudity, Pikachu, Weapon, and Blood; extended experiments include Van Gogh, Taylor Swift, and gender fairness (5.2–5.3, Appendix D.2).
- Robustness evaluation includes Unsafe-1K (1,039 entries), P4D (107 entries), and RAB (272 entries), all targeting NSFW (5.2, Appendix D.1).
- 1 image is generated per prompt or reference image, with 28 sampling steps; the paper does not report multiple repetitions or variance (Appendix C.1).
- Nudity determination uses NudeNet (threshold 0.65), and IP/object uses a CLIP similarity threshold; the paper does not report the agreement between these automatic determinations and human evaluation (5.1, Appendix C.1).
Summarize the main content of the paper
UVR uniformly handles safe generation for T2I and I2I by localizing and suppressing unsafe information flow on MM-DiT output patches; the authors state an erasure rate of 91%/77%.
An inference-time safety defense paper for multimodal diffusion Transformers (MM-DiT), aiming to have T2I synthesis and I2I editing share a single safety mechanism.
- Problem: The authors state that existing concept erasure methods mostly target U-Net or only T2I, are text-centric, and can be bypassed when editing unsafe reference images; effective means for I2I safety mitigation are lacking.
- Method: The authors analyze MM-Attn information flow and state that unsafe semantics are injected into output patches in the first few diffusion steps and can be localized early; based on this they propose the training-free UVR—using pre-collected unsafe anchors (2 images by default) to localize unsafe regions on output patches, then performing adaptive attention modulation (strong suppression in core regions, weak suppression in surrounding regions, enhancement of benign flow) and injecting Gaussian noise during the priming stage.
- Main results: On FLUX.1-dev, 40/854 nudity erasure failures on I2P and 97/1039 on Unsafe-1K, both fewer than the five baselines ESD, SLD, UCE, DES, and EraseAnything (Table 1); on I2I, the unsafe count on Unsafe-1K is 151, versus at least 319 for the baselines (Table 1).
- Other results: For I2I, the Blood erasure failure rate drops from 65.9% to 1.1% (Table 2); unsafe detections on P4D/RAB are 16/107 and 24/272 (Table 6); after directly transferring dev anchors to schnell, Harm drops from 42.89% to 14.69% (Table 10); about 3 MB extra GPU memory and 25s time cost (Table 3).
- Authors' conclusion: The authors state that UVR achieves strong safety performance while maintaining generation quality and editing fidelity, and is suitable for context-insensitive risk concepts; context-dependent judgments require human supervision, and future work can learn content-aware intervention scheduling.