Organizations: School of Information Science and Technology, Southwest Jiaotong University · School of Information and Software Engineering, University of Electronic Science and Technology of China
Recent advances in flow-matching Transformers have greatly improved Text-to-Image (T2I) and Text-to-Video (T2V) generation, but unconstrained generation risks producing illegal or unethical content. Safety alignment must therefore suppress unsafe content while preserving legitimate generation. A concept's safety depends on context: a knife used for cooking is safe, whereas its use in violence is harmful. Yet most concept erasure methods indiscriminately suppress static, isolated representations, overlooking evolving semantic interactions. Consequently, safe scenes containing potentially sensitive terms may be unintentionally suppressed, compromising generation quality. To address this, we propose Dynamic Graph Semantic Recomposition (DGSR), which dynamically constructs and updates a semantic interaction graph from evolving text visual states during sampling. Context aware graph reasoning captures semantic dependencies, while paired safe/unsafe supervision distinguishes harmful from legitimate interactions, enabling precise identification of and selective intervention on high risk semantic relationships while preserving benign semantics. DGSR freezes the pretrained backbone and supports both image and video generation. Experiments show that DGSR achieves the lowest Attack Success Rate (ASR) in 10 of 12 T2I evaluations and reduces the average T2V unsafe frame rate by 41.2% relative to the strongest baseline, while maintaining high generation fidelity and temporal consistency.
Figures & tables
Figure 2: Overview of DGSR. DGSR constructs semantic supernodes from text–visual features and establishes a dynamic semantic interaction graph (DSIG) using Wasserstein-based grounding similarities. A two-layer Edge-GNN captures contextual dependencies and predicts harmful relation suppression strengths. These signals are mapped back to Transformer attention through semantic-level and relation-level recomposition, enabling selective suppression of harmful interactions while preserving benign semantics.
Method
Nudity (ASR,%, ↓ )
Violence (ASR,%, ↓ )
Blood (ASR,%, ↓ )
General Preservation
I2P
P4D
UnDiff
RAB
N-FID ↓
I2P
P4D
UnDiff
RAB
N-FID ↓
I2P
P4D
UnDiff
RAB
N-FID ↓
COCO FID ↓
CS ↑
SSIM ↑
FLUX.1-dev
15.7
-
-
89.7
-
65.5
-
-
75.7
-
57.3
-
-
83.5
-
-
30.9
1.000
EraseAnything
7.5
40.4
21.8
29.4
24.7
33.2
51.2
68.7
51.5
30.9
37.9
59.2
52.8
58.5
27.1
21.8
30.2
0.584
ESD
9.2
47.7
26.8
11.0
27.6
54.9
63.8
80.9
66.8
35.2
34.6
57.0
70.2
55.1
29.4
23.1
28.4
0.493
MACE
8.5
41.2
28.5
32.1
25.1
50.7
59.0
69.8
57.4
31.8
38.8
55.2
68.1
56.3
28.7
24.2
29.5
0.536
SafeRoPE
7.7
38.0
24.3
22.5
22.2
42.9
61.4
69.5
57.1
26.1
39.5
55.3
58.6
45.9
24.5
21.9
30.8
0.672
Table 1: Quantitative comparison of unsafe concept erasure on FLUX.1-dev across Nudity, Violence, and Blood. ASR (%) is evaluated on I2P, P4D, UnDiff, and RAB. For P4D and UnDiff, adversarial prompts are adapted to each method; thus, a single method-independent FLUX.1-dev ASR is not applicable and is marked as “–”. N-FID measures neighboring benign concept preservation, while COCO FID, CLIP Score, and SSIM assess generation quality and fidelity, with the latter three metrics averaged across the three concept categories.
Figure 3: Qualitative comparison of unsafe and benign generation on FLUX.1-dev. We evaluate prompts involving nudity, violence, and blood. DGSR suppresses harmful semantic interactions while preserving benign visual content under related semantic conditions.
Figure 4: Qualitative comparison of nudity on Wan2.2-TI2V-5B.
Figure 5: Visualization of dynamic semantic relations during sampling.(a) Evolution of semantic edge strengths across different unsafe categories. (b) Learned suppression strengths for unsafe (solid) and safe (dashed) relations.
Method
Nudity ↓
Blood/Gore ↓
Subj. Cons. ↑
Gen
Ring-A-Bell
Gen
Ring-A-Bell
Open-Sora
58.29
19.21
61.38
35.75
95.92
SAFREE
31.67
14.27
44.71
25.38
93.25
EraseAnything++
17.10
7.71
27.63
14.21
94.18
T2VUnlearning
16.50
9.53
30.83
12.67
93.20
DGSR (Ours)
10.79
6.83
24.92
13.04
95.04
Table 2: Quantitative comparison of unsafe concept erasure on Open-Sora and Wan2.2-TI2V-5B. We report nudity and blood/gore rates (%) on Gen and RAB, along with subject consistency (Cons.).
Figure 6: Counterfactual safety–preservation trade-off on FLUX. Unsafe interaction ASR and benign interaction accuracy are evaluated under the counterfactual protocol detailed in Appendix C.4 .
Variant
Violence ASR (%) ↓
Preservation
I2P
P4D
UnDiff
RAB
FID ↓
CLIP ↑
Full DGSR
34.8
47.2
58.0
41.3
22.4
30.5
Relation Modeling
Text-only Graph
52.4
64.7
72.6
59.1
23.1
30.2
Static Relation Policy
57.6
62.9
63.4
56.8
22.2
30.3
Pairwise MLP (w/o MP)
44.1
55.9
64.4
50.2
22.7
30.4
Table 3: Ablation study of DGSR on FLUX.1-dev under the Violence setting.
Figure 7: Effect of intervention ratio on safety, semantic preservation, and inference efficiency. (a) ASR together with inference time under different intervention ratios. (b) N-FID and COCO FID for general generation quality.
Appendix figures & tables13 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 8: Illustration of semantic span parsing in DGSR. The input prompt is segmented into meaningful semantic spans, where related words (e.g., “another person”) are grouped into a single graph node. Function words are excluded from standalone node construction, while the original prompt remains unchanged for text-conditioned generation.
Euf=
{(knife,stab),(stab,woman)},
Esf=
{(knife,slice),(slice,bread)}.
Appendix
Table 4: Illustrative violence pair for counterfactual relation contrastive supervision. The example demonstrates the construction of paired unsafe/safe prompts, semantic interaction correspondence, and focused relation sets. The contrastive supervision distinguishes harmful and benign interactions without requiring one-to-one token alignment.
Component
Architecture / Operation
Size
Semantic Supernode Encoding
Text features
Mean pooling of T5 span tokens
3072
Visual features
Grounding-weighted visual pooling
3072
Response statistics
Maximum, mean, entropy
3
Node representation
Feature concatenation
6147
Semantic Relation Encoding
Appendix
Table 5: Architecture of the DGSR auxiliary network.
Figure 9: Dynamic semantic relation analysis on Open-Sora and Wan2.2-TI2V-5B. (a,c) Evolution of semantic edge strengths for Nudity and Blood/Gore during sampling. (b,d) Learned suppression strengths for unsafe (solid) and safe (dashed) relations. Shaded regions indicate seed variation ( ± SD).
Figure 10: Graph risk gating across T2I and T2V models. Distributions of normalized graph-risk scores sG/τgate for benign (blue) and unsafe (orange) samples on (a) FLUX.1-dev, (b) Wan2.2-TI2V-5B, and (c) Open-Sora. The vertical dashed line at sG/τgate=1 marks the intervention threshold. Scores below the threshold preserve the original attention, while scores at or above it activate safety intervention.
Figure 11: Visualization of spatiotemporal semantic graph construction on Wan2.2 and Open-Sora. Video tokens at two temporal positions are grounded to semantic spans through text–visual attention, forming dynamically evolving semantic graphs. Node colors indicate different semantic categories, while red edges highlight high-risk relations and gray edges represent other semantic associations.
Figure 12: Counterfactual interaction evaluation on FLUX.1-dev. Results on 180 matched unsafe/benign prompt pairs. Selective erasure success (SES, ↑ ) across Nudity, Violence, Blood, and Overall. SES is computed on the fixed subset where the original model generates both the target harmful interaction and the key shared concepts.
Table 7: Effect of graph edge metrics on FLUX.1-dev. ASR is averaged over I2P, P4D, UnDiff, and RAB under the Violence setting. FID evaluates generation fidelity.
Method
Mod. Time (s) ↓
Inference (s/sample) ↓
Mod. Params. (%) ↓
ESD
≈4,574
3.50±0.21
21.10
EraseAnything
≈1,644
3.51±0.26
0.0157
MACE
≈952
3.53±0.37
0.0314
SafeRoPE
≈635
4.27±0.40
0.0002
SAFREE
0
5.36±0.24
0
SLD
0
4.71±0.27
0
Appendix
Table 8: Computational overhead comparison on FLUX.1-dev. We report modification/inference time, and modified parameter ratio.
Figure 13: Additional qualitative results on FLUX.1-dev. Comparisons across unsafe and benign prompts involving nudity, violence, highlighting selective suppression and benign semantic preservation.
Figure 14: Qualitative comparison of video concept erasure on Open-Sora. DGSR suppresses unsafe visual content while better preserving scene structure and temporal subject consistency.
Figure 15: Additional qualitative comparisons of video safety intervention and semantic preservation. The Open-Sora (top) and Wan2.2-TI2V-5B (middle) examples compare unsafe-content suppression across methods. The bottom example illustrates preservation of benign generation. DGSR maintains the main visual content and temporal subject consistency while intervening in harmful interactions.