Robust Concept Erasure Using Task Vectors

Minh Pham, Kelly O. Marshall, Chinmay Hegde, and Niv Cohen
New York Univeristy
{mp5847,km3888,chinmay.h,nc3468}@nyu.edu
Abstract

With the rapid growth of text-to-image models, a variety of techniques have been suggested to prevent undesirable image generations. Yet, these methods often only protect against specific user prompts and have been shown to allow unsafe generations with other inputs. Here we focus on unconditionally erasing a concept from a text-to-image model rather than conditioning the erasure on the user’s prompt. We first show that compared to input-dependent erasure methods, concept erasure that uses Task Vectors (TV) is more robust to unexpected user inputs, not seen during training. However, TV-based erasure can also affect the core performance of the edited model, particularly when the required edit strength is unknown. To this end, we propose a method called Diverse Inversion, which we use to estimate the required strength of the TV edit. Diverse Inversion finds within the model input space a large set of word embeddings, each of which induces the generation of the target concept. We find that encouraging diversity in the set makes our estimation more robust to unexpected prompts. Finally, we show that Diverse Inversion enables us to apply a TV edit only to a subset of the model weights, enhancing the erasure capabilities while better maintaining the core functionality of the model.

{tblr}

width = colspec = Q[20]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80], columneven = c, columnodd = c, rowsep=1pt, colsep=1pt, vline12=1-4, & [-1.0,-0.8] [-0.8,-0.6] [-0.6,-0.4] [-0.4,-0.2] [-0.2,0.0] [0.0,0.2] [0.2,0.4] [0.4,0.6] [0.6,0.8] [0.95, 0.98] “Van Gogh”
ESD Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption
SD 1.4 Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption

Figure 1: Concept erasure methods often filter out only a tiny volume in input space. Top row: Erased Stable Diffusion (with the “Van Gogh” concept erased); bottom row: SD 1.4. We plot generations using various adversarially optimized prompt embeddings, located at different Cosine similarities from the embedding of the prompt “Van Gogh”. Values in square brackets represent cosine similarities in embedding space with the prompt “Van Gogh” and are ordered from left (input is far away from the concept name) to right (closer to the concept name). ESD continues to produce “Van Gogh” concepts when the input prompt is far away from the original concept name.

1 Introduction

The capacity of text-to-image (T2I) generative models to produce high-quality images has improved significantly over time. Consequently, growing concerns surround their potential for generating undesirable content. Such concerns include: ability to “deepfake” images of real people; ability to synthesize copyrighted materials; and production of Not-Safe-For-Work (NSFW) content. A direct approach to mitigate these would be to perform data filtering, i.e., removing all images depicting undesired concepts from the model’s training set. However, automatically web-scraped, massive datasets are extremely hard to filter, and imperfect filtering often compromises the safety or the legal compliance of the resulting generative models. Additionally, even if filtering were feasible, retraining already existing models from scratch due to changes in regulations is often impractical due to high costs. For brevity, we refer here to all kinds of undesirable generations as ‘unsafe’.

Refer to caption
Figure 2: Input-independent vs. Input-dependent concept erasure. Illustration of the probability distribution to generate the target concept “Van Gogh” across the input space. Images featuring the “Van Gogh” concept are framed in red, other images are framed in green. Input-dependent concept erasure leaves high probability areas of generating the target concept, while input-independent erasure methods erase the target concept across the entire input space. (Top) In generative T2I models, the probability of generating a specific concept is high for prompt embeddings close to the concept name, but high generation probability is possible also for prompts embedding in a significant distance from it. (Middle) Input-dependent concept-erasure attenuates the generation probability within a small environment of the given prompt but leaves a high probability of generating the erased concept further away from the prompt embedding. (Bottom) Input-independent erasure attenuates the probability of generating the target concept more consistently across the input space.

Several recently proposed methods claim to “sanitize” unsafe concepts from T2I generative models [16, 9, 8, 3, 28, 11, 39]. Yet, when evaluated on unexpected inputs, these methods exhibit significant vulnerabilities, and bypassing these methods is relatively easy for adversarial methods [34, 24]. More specifically, most existing model sanitization approaches excel at averting the production of unsafe content, conditioned on a specific input prompt, or sequence of tokens. However, T2I models end up learning a many-to-many map** from prompts to image space, and a sufficiently motivated adversary — with fairly modest compute effort — can discover other input prompts that trigger a target unsafe concepts.

In this paper, we make further contributions towards the challenge of eliminating unsafe concepts from T2I models. Provably perfect erasure is beyond the scope of this paper, and we address a humbler challenge. Our goal is to develop an unconditional version of concept erasure — namely, a method that can effectively implement concept erasure in a way that is agnostic to the choice of specific user prompts.

Our core idea is based on a recently emergent technique known as Task Vectors [14]. At a high level, a task vector (TV) represents a displacement in the model’s weight space that is a result of fine-tuning;  [14] shows that TVs can be flexibly used via arithmetic operations to enable editing of large models. Crucially, TV-based editing is independent of any specific user input, and therefore we showcase its ability to supply unconditional safety to T2I models. To apply TV-based concept erasure, we first finetune the model to generate a specific concept or style, and refer to the obtained weight difference as our TV. Next, we subtract the TV (possibly multiplied by a scalar α𝛼\alphaitalic_α) from the original model, thereby erasing the unsafe concept.

In Sec. 3 we define a criterion we term unconditional safety, measuring the performance of input-independent concept erasure on a model. We hypothesize that for some models, given a long enough prompt, an effective adversarial input might always be possible [35]. As such, we limit the prompt to a maximal fixed length when measuring a method’s ability to sanitize the generations. Although evaluating large models with our criterion is impractical, we can use it to show that TVs supply unconditional safety on toy models.

Following the strong performance of TV edits for unconditional concept erasure on toy models, we investigate whether they can be applied to large T2I models without compromising the model’s core functionality. Namely, we wish to apply TV edits while optimizing the trade-off between the erasure of unsafe concepts and the preservation of the model functionality. We characterize this trade-off by a parameter defining the edit strength, which is a scalar multiplying the vector magnitude. To tune the value of this parameter without relying on any given prompt, we propose a method called Diverse Inversion. Diverse Inversion finds a large set of token embeddings in dense space, all aimed at generating the same concept we wish to delete. We optimize in parallel many token embeddings, each of which should induce the generation of the target concept we wish to delete in the T2I model.

Our optimization process contains two constraints: (i) Limiting the minimal pair-wise similarity between every pair of embeddings, to ensure diversity in the obtained set of prompts. (ii) Limiting the similarity between each embedding and the embedding of the natural language description of the concept name embedding. Diverse Inversion allows us to tune the value of α𝛼\alphaitalic_α in a manner that better generalizes to prompts compared to using a single input prompt.

Finally, we investigate what value of the strength parameter α𝛼\alphaitalic_α should be used for adjusting weights in the task vector. We find that our Diverse Inversion technique allows us to find a good value of α𝛼\alphaitalic_α. Additionally, it allows us to select a subset of model weights to edit, achieving a better tradeoff between concept erasure and control task performance.

Summary of our contributions. (i) Showing that the vulnerability of current concept erasure methods is caused by their dependence on specific input prompts (Sec. 3.2) (ii) Demonstrating TV-based editing as an efficient method for input-independent concept erasure (Sec. 3.3) (iii) Proposing Diverse Inversion, an algorithm to find a diverse set of dense prompts corresponding to a target concept, and utilizing it to allow a better trade-off between concept-erasure and model performance (Sec. 4).

2 Related Work

Denoising Diffusion Models. Diffusion models are a class of generative models that iteratively refine a distribution through a Markov-based denoising process [12, 33]. The process starts with a noise vector, xTsubscript𝑥𝑇x_{T}italic_x start_POSTSUBSCRIPT italic_T end_POSTSUBSCRIPT, and progressively denoises it over T𝑇Titalic_T steps to reconstruct the original data x0subscript𝑥0x_{0}italic_x start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT. In practice, the model is trained to predict the noise, ϵtsubscriptitalic-ϵ𝑡\epsilon_{t}italic_ϵ start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT, at each timestep, t𝑡titalic_t, which is used to progressively denoise the image, xtsubscript𝑥𝑡x_{t}italic_x start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT. Latent diffusion models (LDM) [27] enhance efficiency by working in a lower-dimensional space learned by an autoencoder. The first component of LDM includes a pre-trained encoder, \mathcal{E}caligraphic_E, and decoder, 𝒟𝒟\mathcal{D}caligraphic_D, trained on a large dataset of images. The encoder maps an image, x𝑥xitalic_x, to a spatial latent code, z=(x)𝑧𝑥z=\mathcal{E}(x)italic_z = caligraphic_E ( italic_x ), and the decoder reconstructs the original image from the latent code, 𝒟((x))x𝒟𝑥𝑥\mathcal{D}(\mathcal{E}(x))\approx xcaligraphic_D ( caligraphic_E ( italic_x ) ) ≈ italic_x. The second component is a diffusion model trained to generate codes in the learned latent space. Given an input, c𝑐citalic_c, the LDM is trained to generate an image conditioned on c𝑐citalic_c using the following objective function:

=𝔼z(x),t,c,ϵ𝒩(0,1)[ϵϵθ(zt,c,t)22]subscript𝔼formulae-sequencesimilar-to𝑧𝑥𝑡𝑐similar-toitalic-ϵ𝒩01delimited-[]superscriptsubscriptnormitalic-ϵsubscriptitalic-ϵ𝜃subscript𝑧𝑡𝑐𝑡22\mathcal{L}=\mathbb{E}_{z\sim\mathcal{E}(x),t,c,\epsilon\sim\mathcal{N}(0,1)}% \Big{[}\|\epsilon-\epsilon_{\theta}(z_{t},c,t)\|_{2}^{2}\Big{]}caligraphic_L = blackboard_E start_POSTSUBSCRIPT italic_z ∼ caligraphic_E ( italic_x ) , italic_t , italic_c , italic_ϵ ∼ caligraphic_N ( 0 , 1 ) end_POSTSUBSCRIPT [ ∥ italic_ϵ - italic_ϵ start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT ( italic_z start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT , italic_c , italic_t ) ∥ start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ]

where ztsubscript𝑧𝑡z_{t}italic_z start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT is the latent code for time t𝑡titalic_t, and ϵθsubscriptitalic-ϵ𝜃\epsilon_{\theta}italic_ϵ start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT is the denoising network. During inference, a random noise tensor is sampled in latent space and gradually denoised to produce a latent code, zsuperscript𝑧z^{\prime}italic_z start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. The latent code is then transformed into an image using the pre-trained decoder, x=𝒟(z)superscript𝑥𝒟superscript𝑧x^{\prime}=\mathcal{D}(z^{\prime})italic_x start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = caligraphic_D ( italic_z start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

Concept-Erasure on T2I Models. Recently, several strategies have been developed to prevent generative models from producing undesirable images. Negative Prompt (NP) [3] and Safe Latent Diffusion (SLD) [28] suggest modifying the inference process to divert the final output from undesired concepts. Other approaches employ classifiers to alter the output [26, 1, 4]. Since inference guiding methods can be evaded with sufficient access to model parameters [32], subsequent works including Erased Stable Diffusion (ESD) [8], Selective Amnesia (SA) [11], Forget-Me-Not (FMN) [39], Ablating Concepts (AC) [16], and Unified Concept Editing (UCE) [9] advocate for fine-tuning Stable Diffusion model weights.

Jailbraking Generative Models. Deep neural networks are known for their brittleness and various algorithms are known for creating inputs that lead these models to produce undesirable outputs. In the context of Large Language Models (LLMs), the term “jailbreaks” refers to adversarial inputs that trigger unsafe, harmful, or unwanted responses from the model. Some jailbreaks have been discovered manually through experimentation or red-teaming [5], while others have been discovered through LLM generation [23, 38]. Jailbreaking techniques include adding or prefixing adversarial strings to the original request. In the realm of text-to-image models, despite undergoing research on concept erasure methods used to remove undesirable concepts from the weights [8, 9, 16, 3, 28, 39, 11], recent works have shown that they are still susceptible to adversarial inputs [34, 24].

As current concept erasure methods for T2I models are often reliant on protecting against specific user inputs, adversarial methods find other inputs that can induce unsafe generations. In particular, Tsai et al. [34] uses a CLIP text encoder to construct a concept vector; a vector in embedding space representing the unsafe content. It then uses a genetic algorithm [31] to find hard prompts that produce the concept vector in the embedding space. Additionally, Pham et al. [24] propose Concept Inversion, which is a method based on Textual Inversion [7] to search for word embeddings that circumvent concept erasure methods. Textual Inversion [7] learns to capture the user-provided concept by representing it through new “words” in the embedding space of a frozen T2I model without changing the model weights. In particular, the authors designate a placeholder string, csubscript𝑐c_{*}italic_c start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT, to represent the new concept the user wishes to learn. They replace the vector associated with the tokenized string with a learned embedding vsubscript𝑣v_{*}italic_v start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT, in essence “injecting” the concept into the model vocabulary. The technique is referred to as Textual Inversion and consists of finding an approximate solution to the following optimization problem:

v=argminv𝔼z(x),c,ϵ𝒩(0,1),t[ϵϵθ(zt,c,t)22].subscript𝑣subscriptargmin𝑣subscript𝔼formulae-sequencesimilar-to𝑧𝑥subscript𝑐similar-toitalic-ϵ𝒩01𝑡delimited-[]superscriptsubscriptnormitalic-ϵsubscriptitalic-ϵ𝜃subscript𝑧𝑡subscript𝑐𝑡22v_{*}=\operatorname*{arg\,min}_{v}\mathbb{E}_{z\sim\mathcal{E}(x),c_{*},% \epsilon\sim\mathcal{N}(0,1),t}\Big{[}\|\epsilon-\epsilon_{\theta}(z_{t},c_{*}% ,t)\|_{2}^{2}\Big{]}.italic_v start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT = start_OPERATOR roman_arg roman_min end_OPERATOR start_POSTSUBSCRIPT italic_v end_POSTSUBSCRIPT blackboard_E start_POSTSUBSCRIPT italic_z ∼ caligraphic_E ( italic_x ) , italic_c start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT , italic_ϵ ∼ caligraphic_N ( 0 , 1 ) , italic_t end_POSTSUBSCRIPT [ ∥ italic_ϵ - italic_ϵ start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT ( italic_z start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT , italic_c start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT , italic_t ) ∥ start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ] .

Task Vectors and Parameter Space Interpolations. Although neural networks are inherently non-linear, previous research has shown that interpolating the weights of two neural networks can preserve their high accuracy if they share a portion of their optimization trajectory [15, 6]. In the context of fine-tuning, accuracy consistently improves when the weights of a pre-trained model are gradually shifted towards its fine-tuned counterpart [22, 13, 37]. Beyond a single task, Matena & Raffel [22] discovered that averaging the weights of multiple models, fine-tuned on different tasks from the same starting point can result in a model with high accuracy on all the fine-tuning tasks. Li et al. [19] observed similar outcomes when averaging the parameters of language models fine-tuned across various domains. Wortsman et al. [36] found that averaging the weights of models fine-tuned on multiple tasks can improve accuracy on a new downstream task without additional training.

Interestingly, the weight difference learned during fine tuning can also be learned on one task and transferred to another to achieve a similar function. Like a vector, it can also be multiplied by a (possibly negative) scalar, and often conveys an appropriate meaning to the model function. Ilharco et al. [14] first compute a Task Vector (TV) as:

τ=θftθpre,𝜏subscript𝜃𝑓𝑡subscript𝜃𝑝𝑟𝑒\tau=\theta_{ft}-\theta_{pre},italic_τ = italic_θ start_POSTSUBSCRIPT italic_f italic_t end_POSTSUBSCRIPT - italic_θ start_POSTSUBSCRIPT italic_p italic_r italic_e end_POSTSUBSCRIPT ,

where θpresubscript𝜃𝑝𝑟𝑒\theta_{pre}italic_θ start_POSTSUBSCRIPT italic_p italic_r italic_e end_POSTSUBSCRIPT is the pre-trained model and θftsubscript𝜃𝑓𝑡\theta_{ft}italic_θ start_POSTSUBSCRIPT italic_f italic_t end_POSTSUBSCRIPT is the model fine-tuned on a selected set of tasks. Subtracting the TV, scaled by a constant α𝛼\alphaitalic_α, from the pre-trained weights θpresubscript𝜃𝑝𝑟𝑒\theta_{pre}italic_θ start_POSTSUBSCRIPT italic_p italic_r italic_e end_POSTSUBSCRIPT will make the model perform worse on the selected tasks for which the fine-tuning process was done. On the other hand, adding a scaled TV will improve the model’s performance on the same tasks. Ilharco et al. [14] show that Task Vectors, scaled by α[0,1]𝛼01\alpha\in[0,1]italic_α ∈ [ 0 , 1 ], can be applied to CLIP classifiers and LLMs to alter their behavior. In this work, we show that Task Vectors can also be applied to text-to-image diffusion models (in particular, the UNet module in Stable Diffusion) to perform concept erasure.

3 Conditional and Unconditional Concept Erasure

3.1 Motivating analysis

We start by noticing that current concept erasure methods are input-dependent. Such methods rely on the concept name to suppress the generation of a targeted concept. For instance, ESD [8] fine-tunes the pre-trained diffusion U-Net model weights to remove a specific style or concept when conditioned on a specific prompt. The authors propose a fine-tuning loss that reduces the probability of generating an image x𝑥xitalic_x based on the likelihood described by the textual description of the concept, aiming to reduce the probability of the target concept c𝑐citalic_c: θ(x)θ(x)θ(c|x)ηproportional-tosubscriptsuperscript𝜃𝑥subscript𝜃𝑥subscript𝜃superscriptconditional𝑐𝑥𝜂\mathbb{P}_{\theta^{*}}(x)\propto\frac{\mathbb{P}_{\theta}(x)}{\mathbb{P}_{% \theta}(c|x)^{\eta}}blackboard_P start_POSTSUBSCRIPT italic_θ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT end_POSTSUBSCRIPT ( italic_x ) ∝ divide start_ARG blackboard_P start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT ( italic_x ) end_ARG start_ARG blackboard_P start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT ( italic_c | italic_x ) start_POSTSUPERSCRIPT italic_η end_POSTSUPERSCRIPT end_ARG, where θsuperscript𝜃\theta^{*}italic_θ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT is the UNet weights of the diffusion model, θ𝜃\thetaitalic_θ is the original weights, η𝜂\etaitalic_η is a scale power factor, and (x)𝑥\mathbb{P}(x)blackboard_P ( italic_x ) represents the distribution generated by the original model. Since the loss function depends on the concept name c𝑐citalic_c, we hypothesize that ESD only suppresses the generation of the targeted concept when explicitly prompted with its textual name.

To further investigate this, we inspect the input space of the SD 1.4 model, and look for different embeddings in dense space that would generate a target concept (e.g., “Van Gogh”). To this end, we use Textual Inversion [7] and limit it to different similarity ranges from the concept name (i.e., the embedding of the string “Van Gogh”). As can be seen in Fig. 1, for the unedited model (second row, “SD 1.4”) a large set of embeddings in dense space ranging in different similarities from the concept name, can all generate images featuring the target concept. Too far away from the concept name generations may gradually fail to reconstruct the concept.

While it is already known that common concept erasure methods may be circumvented by prompts not seen during the erasure process [34, 24], we find that they often filter only a small neighborhood around the embedding used for training. For example, with the ESD concept erasure method [8], we see similar inversion capabilities across most of the model input space. The input filtration claimed by [24] is performed only in proximity to a specific input prompt, as we illustrate in Fig. 2. Therefore, while existing methods are effective in blocking expected prompts, they are less robust to unexpected ones. Motivated by this analysis, we turn to the main goal of this paper: First, we define a notion of safety that goes beyond a specific user prompt. Second, we suggest an effective method for concept erasure that does not depend on a specific prompt.

3.2 Marginal, conditional, and absolute safety

A straightforward way to quantify the safety of a model against undesired generations is to estimate the marginal probability of an unsafe generation. Given a generative model G𝐺Gitalic_G, a prompt p𝑝pitalic_p drawn from a distribution D𝐷Ditalic_D, and the set of unsafe generations U𝑈Uitalic_U, the marginal probability P𝑃Pitalic_P for unsafe generation is given as Smarginalsubscript𝑆𝑚𝑎𝑟𝑔𝑖𝑛𝑎𝑙S_{marginal}italic_S start_POSTSUBSCRIPT italic_m italic_a italic_r italic_g italic_i italic_n italic_a italic_l end_POSTSUBSCRIPT:

Smarginal=PpD(G(p)U).subscript𝑆𝑚𝑎𝑟𝑔𝑖𝑛𝑎𝑙subscript𝑃similar-to𝑝𝐷𝐺𝑝𝑈S_{marginal}=P_{p\sim D}(G(p)\in U).italic_S start_POSTSUBSCRIPT italic_m italic_a italic_r italic_g italic_i italic_n italic_a italic_l end_POSTSUBSCRIPT = italic_P start_POSTSUBSCRIPT italic_p ∼ italic_D end_POSTSUBSCRIPT ( italic_G ( italic_p ) ∈ italic_U ) . (1)

We note that the marginal probability P𝑃Pitalic_P is also potentially affected by the noise distribution (e.g., the random noise which is the input for a diffusion model). Yet, explicitly calculating this marginal safety is not possible as the empirical distribution of test prompts may be unknown. A main reason for it is that adversaries may change the prompt distribution after the design of our model G𝐺Gitalic_G and its safety mechanisms.

As this notion of marginal safety is impractical, it is tempting to replace it with a criterion of conditional safety. This notion takes into account a set of a few prompts supplied by the user, C𝐶Citalic_C, known to be related to the target concept we wish to erase. Our aim then would be to reduce the maximal probability of unsafe generation with any of the prompts pC𝑝𝐶p\in Citalic_p ∈ italic_C:

Sconditional=maxpCP(G(p)U).subscript𝑆𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛𝑎𝑙subscript𝑝𝐶𝑃𝐺𝑝𝑈S_{conditional}=\max_{{p}\in C}P(G(p)\in U).italic_S start_POSTSUBSCRIPT italic_c italic_o italic_n italic_d italic_i italic_t italic_i italic_o italic_n italic_a italic_l end_POSTSUBSCRIPT = roman_max start_POSTSUBSCRIPT italic_p ∈ italic_C end_POSTSUBSCRIPT italic_P ( italic_G ( italic_p ) ∈ italic_U ) . (2)

Optimizing G𝐺Gitalic_G for this safety criteria would ensure that all prompts within the set C𝐶Citalic_C would induce an unsafe behavior with a probability Sconditionalsubscript𝑆𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛𝑎𝑙S_{conditional}italic_S start_POSTSUBSCRIPT italic_c italic_o italic_n italic_d italic_i italic_t italic_i italic_o italic_n italic_a italic_l end_POSTSUBSCRIPT at most. This safety criterion is often optimized by most existing concept erasure methods. Yet, optimizing this criterion would not yield any guarantee outside the set C𝐶Citalic_C.

Therefore, we focus on a safety criterion that is independent from any user-supplied prompts we term unconditional safety. We suggest a safety criterion limiting the probability with which unsafe generation would occur, given a constrained input complexity (e.g., the prompt length). While input length is a good parameter for input complexity in many cases, with dense embedding we may instead limit the resolution in which the dense embedding is given. The resolution of a continuous input vector vd𝑣superscript𝑑v\in\mathbb{R}^{d}italic_v ∈ blackboard_R start_POSTSUPERSCRIPT italic_d end_POSTSUPERSCRIPT is closely related to the input prompt length [35]. For one example, encoding a higher resolution dense embedding corresponds to more bits of information [18]. Specifically, we denote the input complexity (measured by resolution or length) by DLsubscript𝐷𝐿D_{L}italic_D start_POSTSUBSCRIPT italic_L end_POSTSUBSCRIPT and use it to write the unconditional safety criteria. Namely, the unconditional safety criteria Luncodsubscript𝐿𝑢𝑛𝑐𝑜𝑑L_{uncod}italic_L start_POSTSUBSCRIPT italic_u italic_n italic_c italic_o italic_d end_POSTSUBSCRIPT is the minimal complexity L𝐿Litalic_L (e.g., prompt length) for which we have a prompt pDL𝑝subscript𝐷𝐿p\in D_{L}italic_p ∈ italic_D start_POSTSUBSCRIPT italic_L end_POSTSUBSCRIPT that induces an unsafe generation G(p)U𝐺𝑝𝑈G(p)\in Uitalic_G ( italic_p ) ∈ italic_U with a probability of at least ε𝜀\varepsilonitalic_ε.

Luncod= the minimal Ls.t.:maxpDLP(G(p)U)>ε:subscript𝐿𝑢𝑛𝑐𝑜𝑑 the minimal 𝐿s.t.subscript𝑝subscript𝐷𝐿𝑃𝐺𝑝𝑈𝜀L_{uncod}=\text{ the minimal }L\ \ \text{s.t.}:\\ \max_{p\in D_{L}}P(G(p)\in U)>\varepsilon\\ italic_L start_POSTSUBSCRIPT italic_u italic_n italic_c italic_o italic_d end_POSTSUBSCRIPT = the minimal italic_L s.t. : roman_max start_POSTSUBSCRIPT italic_p ∈ italic_D start_POSTSUBSCRIPT italic_L end_POSTSUBSCRIPT end_POSTSUBSCRIPT italic_P ( italic_G ( italic_p ) ∈ italic_U ) > italic_ε (3)

We discuss other possible safety criteria in Sec. 6.

3.3 Task Vectors for unconditional safety

Although calculating the unconditional safety criterion Luncodsubscript𝐿𝑢𝑛𝑐𝑜𝑑L_{uncod}italic_L start_POSTSUBSCRIPT italic_u italic_n italic_c italic_o italic_d end_POSTSUBSCRIPT is impractical for large values of L𝐿Litalic_L, we can demonstrate its improvement on toy models. We hypothesize that prompt-independent concept erasure methods such as TV edits may provide better unconditional safety. To test this hypothesis we trained a toy model with a dense “prompt” space of dimensions d=8𝑑8d=8italic_d = 8. We trained our model to generate images from the MNIST [17] dataset (See SM for implementation details).

123450.00.00.00.00.20.20.20.20.40.40.40.40.60.60.60.60.80.80.80.81.01.01.01.0Input Complexity ParameterUnsafe Generation ProbabilityOriginal modelInput-dependent erasureInput-independent erasure
Figure 3: TV-based concept-erasure provides better unconditional safety. We plot the probability of unsafe generation with the most successful adversarial prompt from each given input complexity class (See Sec.3.2). While the input-dependent (finetune-based) concept erasure method is focused on protecting against undesired generations with a specific prompt, other prompts still produce unsafe generations with high probability. The input-independent (TV-based) erasure reduces the probability of unsafe generations compared both to the original and the input-independent models, across the different complexity classes.

We apply three different concept-erasure models to erase the MNIST digit 0 (“the target concept”) from our diffusion model: (i) Input dependent concept-erasure: We fine-tune the model to produce the remaining 9 digits when given 0 as conditional input. (ii) Input-independent concept-erasure: We utilize a TV edit for input-independent concept-erasure [14]. We fine-tune our model to generate only the target concept (digit 0), and then subtract the model weight change achieved by the fine-tuning process from the original model. This process is input-independent as we perform unconditional fine-tuning discarding the usage of conditional input embedding (iii) Original model: We also evaluate the original model, without concept erasure. For all models, we use a pre-trained classifier to automatically evaluate whether the target concept was indeed generated. Implementation details for the classifier and all three methods, along with examples of the faithfulness of our classifier to human semantics can be found in the SM.

We now turn to evaluate the unconditional safety criterion for the three models above. Specifically, we define the input complexity classes DLsubscript𝐷𝐿D_{L}italic_D start_POSTSUBSCRIPT italic_L end_POSTSUBSCRIPT as the resolutions in which we perform an exhaustive search of the possible prompts in continuous space. For each complexity class DLsubscript𝐷𝐿D_{L}italic_D start_POSTSUBSCRIPT italic_L end_POSTSUBSCRIPT, we explore a grid in d𝑑ditalic_d dimensions, with the inspected values in each dimension comprised of L𝐿Litalic_L equally spaced values, totaling Ldsuperscript𝐿𝑑L^{d}italic_L start_POSTSUPERSCRIPT italic_d end_POSTSUPERSCRIPT points per grid. For example, the grid point (0.0,1.0,1.0,0.0,1.0,)0.01.01.00.01.0(0.0,1.0,1.0,0.0,-1.0,...)( 0.0 , 1.0 , 1.0 , 0.0 , - 1.0 , … ) belongs to a low input complexity class, while the grid point (0.4,0.8,0.6,0.2,1.0,)0.40.80.60.21.0(0.4,0.8,0.6,-0.2,-1.0,...)( 0.4 , 0.8 , 0.6 , - 0.2 , - 1.0 , … ) belongs to a higher one. Intuitively, the higher the input complexity class we examine, the closer we are to an exhaustive search in continuous input space.

We can clearly see in Fig. 3 that the TV edit provides a much better unconditional safety Luncodsubscript𝐿𝑢𝑛𝑐𝑜𝑑L_{uncod}italic_L start_POSTSUBSCRIPT italic_u italic_n italic_c italic_o italic_d end_POSTSUBSCRIPT guarantee. The original and fine-tuned models provide a non-trivial probability of generating the target concept, even for relatively low complexity parameters L𝐿Litalic_L. Moreover, even for the fine-tuned concept erasure, we can find prompts in the medium complexity range (L=5𝐿5L=5italic_L = 5) that generate the target concept with very high probability. However, with the TV-based concept-erasure, the unsafe generation can be better mitigated across all examined complexity classes. This suggests that the TV-based erasure does not merely input-filter the model, but attenuates its ability to generate the unsafe concept more robustly across the input space.

Interpreting this result according to our unconditional safety criteria (Eq. 3), we find that only the input independent method provides a non-trivial bound of the unsafe generation probability for complexity parameters L5𝐿5L\geq 5italic_L ≥ 5. As our input space in this experiment is of dimension d=8𝑑8d=8italic_d = 8, complexity classes of large values of L𝐿Litalic_L are infeasible to compute (DL=6subscript𝐷𝐿6D_{L=6}italic_D start_POSTSUBSCRIPT italic_L = 6 end_POSTSUBSCRIPT already contains Ld=1679616superscript𝐿𝑑1679616L^{d}=1679616italic_L start_POSTSUPERSCRIPT italic_d end_POSTSUPERSCRIPT = 1679616 possible dense prompts).

4 Diverse Inversion for Robust Concept Erasure Using Task Vectors

Motivated by the potential of TV-based editing as a method capable of improving the unconditional safety of T2I models, we now focus on applying this technique to larger models. Namely, we wish to erase unsafe concepts from large diffusion models while otherwise retaining their text-to-image capabilities. Measuring the degree of preservation of the desired text-to-image capabilities can be done directly, since this typically involves expected user inputs and outputs. However, anticipating the model’s reaction to adversarial prompts unknown at the time of editing can be challenging.

To estimate how well the model is protected against unexpected inputs, we would like to observe its outputs for a diverse array of adversarial prompts. We cannot inspect all the input prompts of a given length as we did for the toy model, due to the very large number of possible prompts. To this end, we create a diverse safety validation set composed of diverse input tokens that can all generate unsafe content with the original model. We note that a real-life adversary chooses their prompt after TV-based concept erasure has been applied, and not before it. Yet, the fact that an adversarial prompt often transfers well between erased and original (un-erased) models [24, 40] motivates us to rely on a large set of diverse adversarial prompts optimized for the original method. We show in Sec.5.2 that our method allows us to apply TV-based erasure to gain robustness to adversarial techniques applied after the erasure edit.

Our method for applying Task Vectors for concept erasure in large models consists of three parts. First, we learn a diverse set of adversarial prompts, allowing us to estimate TV edit robustness. Next, we show this learned set allows us to choose robust hyper-parameters for TV edits while maintaining the model utility. Finally, we show that we can not only choose performant hyper-parameter values but also sub-select the set of model parameters we wish to edit for better performance.

4.1 Diverse Inversion

As we discuss in Sec. 3, concept erasure methods can provide a false sense of security by performing “input-filtering”. This suggests that additional inputs are needed to better evaluate concept erasure methods. We would like to have a diverse set on inputs, evaluating the concept erasure capability independently from any specific adversarial prompt. Yet, our experiment in Fig. 1 also shows that in addition to suppressing the harmful generation when prompted with the concept name, the sanitized Stable Diffusion model also sanitizes surrounding word embeddings. Therefore, these additional inputs need to be far from the embedding of the concept name as well as sufficiently diverse. To create a better list of inputs for robust evaluation of concept erasure, one can search for word embeddings as follows:

𝐯=argmin𝐯𝔼z(x),c,ϵ𝒩(0,1),t[ϵϵθ(zt,c,t)22],subscript𝐯subscriptargmin𝐯subscript𝔼formulae-sequencesimilar-to𝑧𝑥subscript𝑐similar-toitalic-ϵ𝒩01𝑡delimited-[]superscriptsubscriptnormitalic-ϵsubscriptitalic-ϵ𝜃subscript𝑧𝑡subscript𝑐𝑡22\displaystyle\mathbf{v}_{*}=\operatorname*{arg\,min}_{\mathbf{v}}\mathbb{E}_{z% \sim\mathcal{E}(x),c_{*},\epsilon\sim\mathcal{N}(0,1),t}\Big{[}\|\epsilon-% \epsilon_{\theta}(z_{t},c_{*},t)\|_{2}^{2}\Big{]},bold_v start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT = start_OPERATOR roman_arg roman_min end_OPERATOR start_POSTSUBSCRIPT bold_v end_POSTSUBSCRIPT blackboard_E start_POSTSUBSCRIPT italic_z ∼ caligraphic_E ( italic_x ) , italic_c start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT , italic_ϵ ∼ caligraphic_N ( 0 , 1 ) , italic_t end_POSTSUBSCRIPT [ ∥ italic_ϵ - italic_ϵ start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT ( italic_z start_POSTSUBSCRIPT italic_t end_POSTSUBSCRIPT , italic_c start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT , italic_t ) ∥ start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ] , (4)
s.t. {Sim(vi,vconcept)[a,b]fori=1,2,,n,Sim(vi,vj)[c,d]fori,j=1,2,,n,ij.\displaystyle\text{s.t. }\left\{\begin{aligned} &\text{Sim}(v_{i*},v_{\text{% concept}})\in[a,b]\text{for}i=1,2,\ldots,n,\\ &\text{Sim}(v_{i*},v_{j*})\in[c,d]\text{for}i,j=1,2,\ldots,n,i\neq j.\end{% aligned}\right.s.t. { start_ROW start_CELL end_CELL start_CELL Sim ( italic_v start_POSTSUBSCRIPT italic_i ∗ end_POSTSUBSCRIPT , italic_v start_POSTSUBSCRIPT concept end_POSTSUBSCRIPT ) ∈ [ italic_a , italic_b ] for italic_i = 1 , 2 , … , italic_n , end_CELL end_ROW start_ROW start_CELL end_CELL start_CELL Sim ( italic_v start_POSTSUBSCRIPT italic_i ∗ end_POSTSUBSCRIPT , italic_v start_POSTSUBSCRIPT italic_j ∗ end_POSTSUBSCRIPT ) ∈ [ italic_c , italic_d ] for italic_i , italic_j = 1 , 2 , … , italic_n , italic_i ≠ italic_j . end_CELL end_ROW

In Eq. 4, we optimize for a set of embeddings 𝐯=(v1,v2,,vn)subscript𝐯subscript𝑣1subscript𝑣2subscript𝑣𝑛\mathbf{v}_{*}=(v_{1},v_{2},...,v_{n})bold_v start_POSTSUBSCRIPT ∗ end_POSTSUBSCRIPT = ( italic_v start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT , italic_v start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT , … , italic_v start_POSTSUBSCRIPT italic_n end_POSTSUBSCRIPT ). The first constraint ensures that the learned embeddings are not too close to the embedding of the concept name (e.g. Van Gogh). The second constraint pushes the learned embeddings away from each other to diversify them. Nevertheless, the optimization procedure in Eq. 4 can be highly non-convex, and we found that vanilla inversion with random restart can be used as an approximation to learn sufficiently diverse embeddings for our proposed erasure method.

4.2 Tuning the TV edit strength

With the augmented set of inputs that all make Stable Diffusion generate images of the target concept, we can choose the parameter α𝛼\alphaitalic_α that controls the edit strength of the TV. We look for a value that suppresses any such generation with a prompt from our Diverse Inversion set. In a recent result, Pham et al. [24] show that a robust model might not always be usable in practice. I.e. the model outputs for non-adversarial prompts will not align with the prompts’ semantics. Hence, we also measure the model performance on control tasks featuring unrelated concepts. Examining both measures we can vary the value of α𝛼\alphaitalic_α to create a scatter plot and pick the α𝛼\alphaitalic_α that yields the desired trade-off between robustness and usability (Sec. 5.2).

4.3 Sub-selecting TV weights

In our experiments, larger values of α𝛼\alphaitalic_α tend to make the Stable Diffusion model more robust against inversion. However, this can also affect the model performance on unrelated tasks. Motivated by [10, 21], we hypothesize that not all layers on the UNet need to be edited. We test our hypothesis by not editing certain blocks of the UNet. In other words, we suggest pruning certain layers of the TV weights.

0.180.180.180.180.20.20.20.20.220.220.220.220.240.240.240.240.260.260.260.260.280.280.280.280.30.30.30.30.320.320.320.320.340.340.340.340.360.360.360.360.380.380.380.380.120.120.120.120.140.140.140.140.160.160.160.160.180.180.180.180.200.200.200.200.220.220.220.220.240.240.240.240.260.260.260.260.280.280.280.280.300.300.300.300.320.320.320.32Erasure ScoreControl TaskOriginal modelPruned TV (first 3 blocks)
(a) “French Horn”
0.220.220.220.220.230.230.230.230.240.240.240.240.250.250.250.250.260.260.260.260.270.270.270.270.280.280.280.280.290.290.290.290.30.30.30.30.310.310.310.310.320.320.320.320.330.330.330.330.340.340.340.340.350.350.350.350.360.360.360.360.370.370.370.370.220.220.220.220.230.230.230.230.240.240.240.240.250.250.250.250.260.260.260.260.270.270.270.270.280.280.280.280.290.290.290.290.300.300.300.300.310.310.310.310.320.320.320.320.330.330.330.330.340.340.340.340.350.350.350.35Erasure ScoreControl TaskOriginal modelPruned TV (first 3 blocks)
(b) “Art by Thomas Kinkade”
Figure 4: The trade-off between erasure score and control task performance. We plot the robustness measured according to erasure score, lower is better, and control task performance, higher is better, for models erased with different TV edit strengths (parameterized by α𝛼\alphaitalic_α). Our Diverse Inversion method allows us to explore the trade-off between concept erasure robustness and model utility when editing different subsets of the model parameter. We discover that different target concepts may benefit from editing different subsets of model parameters.

5 Experiments

5.1 Experimental setup

Metrics: To assess the content of the generated images, we use CLIP ViT-B/32 [25] pre-trained on LAION-2B [29]. Following previous works [24, 11, 8, 9], the control task for all experiments is the average CLIP similarity score of 6 concepts across 3 different concept categories (artistic style, objects, and specific people): “art by Kilian Eng”, “art by Picasso”, “garbage truck”, “chain saw”, “Brad Pitt”, and “Angelina Jolie”. Motivated by our experiment in Sec. 3, we propose to use a metric known as Erasure Score to validate the robustness of the edited Stable Diffusion model to many different attack prompts. The metric is defined as follows: after obtaining word embeddings via Diverse Inversion, we generate an image for each learned embedding and the concept name from the Stable Diffusion model. Erasure Score (ES) is defined as the maximum (calculated over all generated images) CLIP similarity between the generated images and the concept name. A lower Erasure Score indicates more robustness against adversarial inputs. Our results on robustness to different adversarial methods are demonstrated qualitatively in Figs. 6 and 5, and quantitatively in the supplementary material (SM).

Implementation Details: For calculating the Erasure Score we use our Diverse Inversion method to find 100100100100 word embeddings that trigger the generation of the erased concept. These embeddings lie evenly across 5 non-overlap** intervals, where each interval represents the allowed similarity between the learned embeddings and the embedding of the concept name. Moreover, we ensure that the pairwise similarity between learned embeddings within each interval cannot be too large. To obtain the TV for concept erasure, we first fine-tune the UNet of the Stable Diffusion model on a combination of synthetic and real images of the targeted concept, using the empty string as the caption. The fine-tuned UNet is then used to compute TV for the editing procedure. Further details appear in the SM.

5.2 Results

We demonstrate in Figs. 5 and 6 that our method provides robustness to current adversarial methods applied after the concept erasure edit. In the second row in each of the sub-figures of Fig. 5 we show that for certain values of the edit strength α𝛼\alphaitalic_α, the Stable Diffusion model manages to suppress the generation of the targeted concept when explicitly prompted with the same concept name. However, when Concept Inversion [24] is applied, we can still recover the erased concept. On the other hand, when α𝛼\alphaitalic_α is increased, we obtain both a lower Erasure Score (ES) and a more robust erased model. This suggests that we can use the Erasure Score to guide us in selecting an appropriate edit strength, α𝛼\alphaitalic_α, to make the model more robust against adversarial inputs. We also test our edited models against hard prompts obtained from the Ring-A-Bell method [34]. Fig. 6 shows that the adversarial prompts manage to fully circumvent 7 concept erasure methods but are unable to recover the target concepts erased using TV.

A notable drawback of using Task Vectors (TV) is that this method requires using significantly higher values of α𝛼\alphaitalic_α to enhance the Stable Diffusion model’s robustness against adversarial inputs. Consequently, this might compromise the model’s generative performance on concepts unrelated to the erased concept. Fig. 4 demonstrates that certain layers of TV can be pruned to better preserve generative performance on unrelated concepts, while still maintaining robustness against adversarial inputs.

{tblr}

width = colspec = Q[20]Q[70]Q[70]Q[70], columneven = c, columnodd = c, rowsep=1pt, colsep=1pt, & “Van Gogh” Concept Inversion “Thomas Kinkade”
Original Model Refer to caption Refer to caption Refer to caption
α=0.75𝛼0.75\alpha=0.75italic_α = 0.75 ES = 0.34090.34090.34090.3409 Refer to caption Refer to caption Refer to caption
α=2.25𝛼2.25\alpha=2.25italic_α = 2.25 ES = 0.23760.23760.23760.2376 Refer to caption Refer to caption Refer to caption

{tblr}

width = colspec = Q[20]Q[70]Q[70]Q[70], columneven = c, columnodd = c, rowsep=1pt, colsep=1pt, & “French Horn” Concept Inversion “Garbage Truck”
Original Model Refer to caption Refer to caption Refer to caption
α=2.75𝛼2.75\alpha=2.75italic_α = 2.75 ES = 0.33440.33440.33440.3344 Refer to caption Refer to caption Refer to caption
α=4.0𝛼4.0\alpha=4.0italic_α = 4.0 ES = 0.23440.23440.23440.2344 Refer to caption Refer to caption Refer to caption

Figure 5: TV based concept erasure robustness to Concept Inversion. A full TV edit is utilized to erase “Van Gogh” (Left) A pruned TV edit is utilized to erase “French Horn” (Right). We display three model variants (by row): the original model, and two models from which we removed the targeted concept using Task Vectors of different magnitudes. In both cases, TV-based erasure is robust against Concept Inversion ([24]) and preserves the model utility on the control task. The third column demonstrates that TV preserves model performance on unrelated concepts.
Refer to caption
Figure 6: Generated images with the ‘Ring-A-Bell’ [34] prompt for the concept “Van Gogh”. We show that the adversarial prompt obtained from the “Ring-A-Bell” paper (bottom of the image) can circumvent 7 leading concept-erasure methods, but not our suggested TV erasure procedure. More similar results can be found in the SM.

6 Discussion

Model innocence as a safety goal. It is tempting to pursue other definitions of safety as well, such as model innocence which stipulates that a model behaves similarly to one that was never exposed to any examples of unsafe behaviors. Yet, beyond the questions of practicality, an innocent model may still be unsafe. For example, an advanced enough model that understands the concept of something being safe-for-work, and the concept of negation, may be expected to allow the creation of various not-safe-for-work images [2].

Absolute safety. Making it impossible to generate unwanted content may seem to represent the absolute ideal in model safety. However, completely avoiding unsafe content depends on the ability to recognize all unsafe behaviors. The ability to describe all unsafe behaviors without defining such behaviors in advance is therefore left for further research [2].

7 Limitations

Provable guarantees for erasure. An inherent weakness of any erasure method is the inability to evaluate them in advance against yet unknown future adversarial methods [2]. We acknowledge this as a weakness of our suggested method as well. Yet, we provide not only results against current adversarial methods but also a principled analysis of the unique qualities of TV-based concept erasure being input-independent; this is one of our main contributions.

TV-based erasure. Our suggested method is reliant on TV techniques. Yet, the parameter space of neural networks is far from being completely understood [20]. This means that the exact cases where TV-based erasure can work or fail are not clear yet. The application of Task Vectors for more fine-grained, or coarse-grained concepts, is yet to be explored. Similarly, it is not clear yet how to apply our Diverse Inversion techniques to other modalities such as language. Additionally, when erasing an excessive number of concepts it is not clear how to avoid a significant deterioration of the control task performance.

Dependence on the Diverse Inversion set. While we claim to suggest an input-independent concept erasure method, our method is dependent on the discovered Diverse Inversion set. Nevertheless, we only use it to tune hyper-parameters: the TV edit strength, and the identity of the edited layers. Therefore, our edit is not only independent of any user-supplied prompt but also, apart from hyper-parameters, independent of the embedding found using the Diverse Inversion method.

8 Conclusions

We propose adapting Task Vectors (TV), a recently proposed technique for model editing, for erasing concepts from generative models. On a range of test cases, we demonstrate how TVs can be used to sanitize undesirable concepts from text-to-image models in a way that is independent of specific user prompts. This distinguishes TV from existing methods in the literature and makes it more robust. Our method, Diverse Inversion, enables us to better maintain model utility while removing harmful concepts. We anticipate that our method will be of interest to the broader AI safety community, and can be extended to other model families such as large language models (LLMs) and other multimodal vision-language models.

Acknowledgments

The authors were partially supported by the AI Research Institutes Program supported by NSF and USDA-NIFA under grant no. 2021-67021-35329, NSF SaTC grant 2154119, and a Cyber NYC gift from Google Research. KM was supported by a US Department of Education GAANN fellowship. NC was partially supported by the Israeli data science scholarship for outstanding postdoctoral fellows (VATAT).

References

  • AI [2022] Stability AI. Stable diffusion 2.0 release, 2022. Jul 9, 2023.
  • Amodei et al. [2016] Dario Amodei, Chris Olah, Jacob Steinhardt, Paul Christiano, John Schulman, and Dan Mané. Concrete problems in ai safety. arXiv preprint arXiv:1606.06565, 2016.
  • AUTOMATIC1111 [2022] AUTOMATIC1111. Negative prompt, 2022.
  • Bedapudi [2022] Praneeth Bedapudi. Nudenet: Neural nets for nudity detection and censoring, 2022.
  • Chao et al. [2023] Patrick Chao, Alexander Robey, Edgar Dobriban, Hamed Hassani, George J. Pappas, and Eric Wong. Jailbreaking black box large language models in twenty queries. CoRR, abs/2310.08419, 2023.
  • Frankle et al. [2020] Jonathan Frankle, Gintare Karolina Dziugaite, Daniel M. Roy, and Michael Carbin. Linear mode connectivity and the lottery ticket hypothesis. In International Conference on Machine Learning, 2020.
  • Gal et al. [2023] Rinon Gal, Yuval Alaluf, Yuval Atzmon, Or Patashnik, Amit Haim Bermano, Gal Chechik, and Daniel Cohen-Or. An image is worth one word: Personalizing text-to-image generation using textual inversion. In International Conference on Learning Representations, 2023.
  • Gandikota et al. [2023a] Rohit Gandikota, Joanna Materzynska, Jaden Fiotto-Kaufman, and David Bau. Erasing concepts from diffusion models. In International Conference on Computer Vision, 2023a.
  • Gandikota et al. [2023b] Rohit Gandikota, Hadas Orgad, Yonatan Belinkov, Joanna Materzynska, and David Bau. Unified concept editing in diffusion models. In IEEE/CVF Winter Conference on Applications of Computer Vision, 2023b.
  • Hase et al. [2023] Peter Hase, Mohit Bansal, Been Kim, and Asma Ghandeharioun. Does localization inform editing? surprising differences in causality-based localization vs. knowledge editing in language models. In Annual Conference on Neural Information Processing Systems, 2023.
  • Heng and Soh [2023] Alvin Heng and Harold Soh. Selective amnesia: A continual learning approach to forgetting in deep generative models. In Advances in Neural Information Processing Systems, 2023.
  • Ho et al. [2020] Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising diffusion probabilistic models. In Advances in Neural Information Processing Systems, 2020.
  • Ilharco et al. [2022] Gabriel Ilharco, Mitchell Wortsman, Samir Yitzhak Gadre, Shuran Song, Hannaneh Hajishirzi, Simon Kornblith, Ali Farhadi, and Ludwig Schmidt. Patching open-vocabulary models by interpolating weights. In Advances in Neural Information Processing Systems, 2022.
  • Ilharco et al. [2023] Gabriel Ilharco, Marco Túlio Ribeiro, Mitchell Wortsman, Ludwig Schmidt, Hannaneh Hajishirzi, and Ali Farhadi. Editing models with task arithmetic. In International Conference on Learning Representations, 2023.
  • Izmailov et al. [2018] Pavel Izmailov, Dmitrii Podoprikhin, Timur Garipov, Dmitry P. Vetrov, and Andrew Gordon Wilson. Averaging weights leads to wider optima and better generalization. In Conference on Uncertainty in Artificial Intelligence, 2018.
  • Kumari et al. [2023] Nupur Kumari, Bingliang Zhang, Sheng-Yu Wang, Eli Shechtman, Richard Zhang, and Jun-Yan Zhu. Ablating concepts in text-to-image diffusion models. In International Conference on Computer Vision, 2023.
  • LeCun et al. [2010] Yann LeCun, Corinna Cortes, and Christopher J.C. Burges. Mnist handwritten digit database. ATT Labs [Online]. Available: http://yann.lecun.com/exdb/mnist, 2, 2010.
  • Li et al. [2008] Ming Li, Paul Vitányi, et al. An introduction to Kolmogorov complexity and its applications. Springer, 2008.
  • Li et al. [2022] Margaret Li, Suchin Gururangan, Tim Dettmers, Mike Lewis, Tim Althoff, Noah A. Smith, and Luke Zettlemoyer. Branch-train-merge: Embarrassingly parallel training of expert language models. CoRR, abs/2208.03306, 2022.
  • Ma et al. [2020] Chao Ma, Stephan Wojtowytsch, Lei Wu, et al. Towards a mathematical understanding of neural network-based machine learning: what we know and what we don’t. arXiv preprint arXiv:2009.10713, 2020.
  • Maini et al. [2023] Pratyush Maini, Michael Curtis Mozer, Hanie Sedghi, Zachary Chase Lipton, J. Zico Kolter, and Chiyuan Zhang. Can neural network memorization be localized? In International Conference on Machine Learning, 2023.
  • Matena and Raffel [2022] Michael Matena and Colin Raffel. Merging models with fisher-weighted averaging. In Advances in Neural Information Processing Systems, 2022.
  • Perez et al. [2022] Ethan Perez, Saffron Huang, Francis Song, Trevor Cai, Roman Ring, John Aslanides, Amelia Glaese, Nat McAleese, and Geoffrey Irving. Red teaming language models with language models. In Conference on Empirical Methods in Natural Language Processing, 2022.
  • Pham et al. [2024] Minh Pham, Kelly O. Marshall, Niv Cohen, Govind Mittal, and Chinmay Hegde. Circumventing concept erasure methods for text-to-image generative models. In International Conference on Learning Representations, 2024.
  • Radford et al. [2021] Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, Gretchen Krueger, and Ilya Sutskever. Learning transferable visual models from natural language supervision. In International Conference on Machine Learning, 2021.
  • Rando et al. [2022] Javier Rando, Daniel Paleka, David Lindner, Lennart Heim, and Florian Tramèr. Red-teaming the stable diffusion safety filter. In Advances in Neural Information Processing Systems Workshop, 2022.
  • Rombach et al. [2022] Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, and Björn Ommer. High-resolution image synthesis with latent diffusion models. In Conference on Computer Vision and Pattern Recognition, 2022.
  • Schramowski et al. [2023] Patrick Schramowski, Manuel Brack, Björn Deiseroth, and Kristian Kersting. Safe latent diffusion: Mitigating inappropriate degeneration in diffusion models. In Conference on Computer Vision and Pattern Recognition, 2023.
  • Schuhmann et al. [2022] Christoph Schuhmann, Romain Beaumont, Richard Vencu, Cade Gordon, Ross Wightman, Mehdi Cherti, Theo Coombes, Aarush Katta, Clayton Mullis, Mitchell Wortsman, Patrick Schramowski, Srivatsa Kundurthy, Katherine Crowson, Ludwig Schmidt, Robert Kaczmarczyk, and Jenia Jitsev. LAION-5B: an open large-scale dataset for training next generation image-text models. In Advances in Neural Information Processing Systems, 2022.
  • Sehwag [2021] Vikash Sehwag. Minimal implementation of diffusion models, 2021.
  • Sivanandam and Deepa [2008] S. N. Sivanandam and S. N. Deepa. Introduction to genetic algorithms. Springer, 2008.
  • SmithMano [2022] SmithMano. Tutorial: How to remove the safety filter in 5 seconds, 2022.
  • Sohl-Dickstein et al. [2015] Jascha Sohl-Dickstein, Eric A. Weiss, Niru Maheswaranathan, and Surya Ganguli. Deep unsupervised learning using nonequilibrium thermodynamics. In International Conference on Machine Learning Workshop, 2015.
  • Tsai et al. [2024] Yu-Lin Tsai, Chia-Yi Hsu, Chulin Xie, Chih-Hsun Lin, Jia-You Chen, Bo Li, Pin-Yu Chen, Chia-Mu Yu, and Chun-Ying Huang. Ring-a-bell! how reliable are concept removal methods for diffusion models? In International Conference on Learning Representations, 2024.
  • Wolf et al. [2023] Yotam Wolf, Noam Wies, Yoav Levine, and Amnon Shashua. Fundamental limitations of alignment in large language models. arXiv preprint arXiv:2304.11082, 2023.
  • Wortsman et al. [2022a] Mitchell Wortsman, Gabriel Ilharco, Samir Yitzhak Gadre, Rebecca Roelofs, Raphael Gontijo Lopes, Ari S. Morcos, Hongseok Namkoong, Ali Farhadi, Yair Carmon, Simon Kornblith, and Ludwig Schmidt. Model soups: averaging weights of multiple fine-tuned models improves accuracy without increasing inference time. In International Conference on Machine Learning, 2022a.
  • Wortsman et al. [2022b] Mitchell Wortsman, Gabriel Ilharco, Jong Wook Kim, Mike Li, Simon Kornblith, Rebecca Roelofs, Raphael Gontijo Lopes, Hannaneh Hajishirzi, Ali Farhadi, Hongseok Namkoong, and Ludwig Schmidt. Robust fine-tuning of zero-shot models. In Conference on Computer Vision and Pattern Recognition, 2022b.
  • Wu et al. [2024] Yuanwei Wu, Xiang Li, Yixin Liu, Pan Zhou, and Lichao Sun. Jailbreaking gpt-4v via self-adversarial attacks with system prompts. CoRR, abs/2311.09127, 2024.
  • Zhang et al. [2023] Eric J. Zhang, Kai Wang, Xingqian Xu, Zhangyang Wang, and Humphrey Shi. Forget-me-not: Learning to forget in text-to-image diffusion models. CoRR, abs/2303.17591, 2023.
  • Zou et al. [2023] Andy Zou, Zifan Wang, J. Zico Kolter, and Matt Fredrikson. Universal and transferable adversarial attacks on aligned language models. CoRR, abs/2307.15043, 2023.
\thetitle

Supplementary Material

CAUTION: This section includes generated content that may contain offensive or distressing material.

9 Additional Implementation Details

For all of our experiments except the toy MNIST one, we use Stable Diffusion 1.4 (SD 1.4). To compute the TV for SD 1.4, we fine-tune the UNet component on 15 synthetic images and 15 real images obtained from Google Images (30 in total). The synthetic images are obtained from the unedited SD 1.4 using the prompt “a photo of [object name]” for object concepts, and “a painting in the style of [artist name]” for art style concepts. We fine-tune for 1000 steps using a learning rate of 1e051𝑒051e-051 italic_e - 05.

10 Images for MNIST Experiment

Fig. 7 demonstrates that both Fine-tuning and TV can be used to erase the digit 0 from the toy diffusion model. We also use a pre-trained classifier to quantitatively assess the generation quality of the edited models in Tab. 1. Both editing methods can erase the target class when the model is given 00 as conditional input, while preserving generative performance on other classes. However, Fig. 8 shows that TV is more robust against inversion. For the toy diffusion models, we used implementation from [30]. However, we modify the architecture to support conditional embeddings of dimension d=8𝑑8d=8italic_d = 8, and normalize the input embeddings during training and inference. Such modifications are made to make the space of input embeddings that generate actual digits more compact. This makes the model more likely to generate faithful images when given our sampled embeddings as conditional input. We train and fine-tune using a batch size of 512512512512 for 100100100100 epochs.

Table 1: Classification accuracy (%) on generated images
Target class Other classes
Original 98.2 98.1
Fine-tuning 1.4 97.3
Task Vector 0.4 97.3
{tblr}

width = colspec = Q[40]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80], columneven = c, columnodd = c, rowsep=1pt, colsep=1pt, vline3=1-4, & 0 (erased class) 1 2 3 4 5 6 7 8 9
Original Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption
Fine tuning Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption
Task Vector Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption

Figure 7: Fine-tuning and Task Vector can suppress the generation of digit 0 when the diffusion model is given class 0 as the conditional input.
{tblr}

width = colspec = Q[80]Q[80]Q[80], columneven = c, columnodd = c, rowsep=1pt, colsep=2pt, Original & Fine-tuning TV
Refer to caption Refer to caption Refer to caption

Figure 8: Inversion of the erased class (digit 0) works on the original and fine-tuned diffusion models, but not on the edited model using Task Vector.

10.1 Ablation for Diverse Inversion

To study the necessity of Diverse Inversion, we also perform vanilla Textual Inversion (TI) [7] to find 50505050 word embeddings for Van Gogh style. Fig. 9 suggests that without the additional constraints, the cosine similarities between the learned embeddings through vanilla TI and the embedding of the concept name will center around 0.00.00.00.0. However, with Diverse Inversion, we can enhance the diversity of our learned embeddings by controlling such cosine similarities taken with respect to the concept name. Fig. 10 shows samples of SD 1.4 when we used the learned embeddings of Diverse Inversion as conditional input.

Refer to caption
Figure 9: Histogram of cosine similarities between learned embeddings and the embedding of the concept name (“Van Gogh”).
{tblr}

width = colspec = Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80], columneven = c, columnodd = c, rowsep=1pt, colsep=2pt, Embedding 1 & Embedding 2 Embedding 3 Embedding 4 Embedding 5 Embedding 6 Embedding 7 Embedding 8 Embedding 9 Embedding 10
Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption

Figure 10: Generated images using learned embeddings from Diverse Inversion

10.2 Additional Results

We provide additional results on the robustness of TV in Tab. 2. We followed a similar setup to Pham et al. [24] to quantify the robustness of erasure methods on objects. In particular, we first generate 500 images for the prompt with the concept name and 500 images with Concept Inversion. We then use a pre-trained classifier to measure the presence of the erased object in the generated images.

Table 2: Quantitative results of Concept Inversion for object concept (Acc. % of erased model / Acc. % of CI): Using Concept Inversion, we can generate images of the erased objects, which can be seen by an increase in average accuracy across 4 concept erasure methods except Task Vector. “SD 1.4” features the accuracy of the original model with the concept name. Accuracy is measured with a classifier as in [8].
{tblr}

width = colspec = Q[150]Q[100]Q[100]Q[100]Q[100]Q[100]Q[100], columneven = c, column2-6 = c, hline1 = 2-7, hline2 = -, hline12 = -, colsep=2pt, rowsep=0.1pt, & SD 1.4 TV ESD UCE NP SLD-Med
cassette player 6.4 2.0 / 0.0 0.2 / 6.2 0.0 / 2.8 4.0 / 9.4 1.0 / 2.4
chain saw 68.6 1.2 / 0.3 0.0 / 64.0 0.0 / 43.6 4.0 / 82.8 0.8 / 86.6
church 79.6 12.4 / 0.4 0.8 / 87.4 10.0 / 82.2 25.4 / 78.4 20.6 / 72.0
english springer 93.6 9.1 / 0.3 0.2 / 48.2 0.0 / 69.6 27.0 / 90.4 24.6 / 96.4
french horn 99.3 26.1 / 0.0 0.0 / 81.6 0.4 / 99.4 62.4 / 99.0 17.0 / 97.6
garbage truck 83.2 9.2 / 0.4 0.8 / 57.0 16.4 / 89.6 39.4 / 84.6 19.8 / 94.8
gas pump 76.6 3.2 / 0.3 0.0 / 73.8 0.0 / 73.0 18.0 / 79.6 12.8 / 75.6
golf ball 96.2 13.4 / 0.5 0.0 / 28.6 0.2 / 18.6 45.2 / 88.4 60.2 / 98.8
parachute 96.2 19.2 / 0.0 0.0 / 94.2 1.6 / 94.2 32.8 / 77.2 52.8 / 95.8
tench 79.6 12.2 / 0.1 0.3 / 59.7 0.0 / 20.6 27.6 / 72.6 20.6 / 75.4
Average 77.9 10.8 / 0.2 0.2 / 60.1 2.9 / 59.4 28.6 / 76.2 23.0 / 79.5

Refer to caption
Figure 11: Generated images with the ‘Ring-A-Bell’ [34] prompt for the concept “Nudity”. We show that the adversarial prompt obtained from the “Ring-A-Bell” paper (bottom of the image) can circumvent 7 leading concept-erasure methods, but not our suggested TV erasure procedure.
{tblr}

width = colspec = Q[30]Q[80]Q[80]Q[80]Q[80]Q[80]Q[80], columneven = c, columnodd = c, rowsep=1pt, colsep=1pt, vline12=1-4, & 0 embeddings 1 embeddings 3 embeddings 5 embeddings 7 embeddings 9 embeddings
Concept Name Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption
Inversion Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption Refer to caption

Figure 12: More learned input embeddings can help pick a more robust α𝛼\alphaitalic_α for TV. Top row: Images generated using the prompt “a painting in the style of Van Gogh”; bottom row: Images generated using the prompt “a painting in the style of Sisubscriptsuperscript𝑆𝑖S^{*}_{i}italic_S start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT”, where Sisubscriptsuperscript𝑆𝑖S^{*}_{i}italic_S start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT is the token associated with the ithsuperscript𝑖𝑡i^{th}italic_i start_POSTSUPERSCRIPT italic_t italic_h end_POSTSUPERSCRIPT learned embeddings. We first generate images using the concept name and learned embeddings (if any), and then choose α𝛼\alphaitalic_α until the Erasure Score is below 0.240.240.240.24. When using less than 5 learned embeddings, we can achieve a low Erasure Score even with a low α𝛼\alphaitalic_α. However, such a low ES score can provide a false sense of security since Concept Inversion can still recover the erased concept. By utilizing more embeddings, the ES score can provide a better estimate of which α𝛼\alphaitalic_α to pick to make the model more robust against adversarial inputs.