import{S as Ro,i as Ko,s as Yo,e as o,k as d,w as g,t as r,M as Jo,c as n,d as i,m as p,a,x as _,h as l,b as s,G as e,g as c,y as v,L as Qo,q as b,o as w,B as E,v as Xo}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as Te}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as Zo}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as it}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";function en(eo){let P,ot,D,C,Se,G,St,Ie,It,nt,k,L,Ae,H,At,Ce,Ct,at,W,B,Lt,Ot,st,me,Nt,rt,he,Le,qt,lt,ge,jt,dt,h,_e,R,Ut,zt,Vt,ve,K,Ft,Gt,Ht,be,Y,Wt,Bt,Rt,we,J,Kt,Yt,pt,$,O,Oe,Q,Jt,Ne,Qt,ft,N,qe,M,je,Xt,Zt,Ue,ei,ti,Ee,ii,oi,ze,T,Ve,X,ni,ai,Fe,Ge,si,ri,Z,ee,li,di,ct,ye,pi,ut,S,q,He,te,fi,We,ci,mt,ie,ht,I,j,Be,oe,ui,Re,mi,gt,u,ne,hi,Ke,gi,_i,ae,vi,xe,bi,wi,Ei,y,se,yi,Ye,xi,Pi,Je,Di,ki,U,re,$i,le,Mi,Qe,Ti,Si,Ii,z,de,Ai,pe,Ci,fe,Li,Oi,Ni,V,ce,qi,A,ji,Xe,Ui,zi,Ze,Vi,Fi,Gi,x,ue,Hi,et,Wi,Bi,tt,Ri,_t;return G=new it({}),H=new it({}),Q=new it({}),te=new it({}),ie=new Zo({props:{code:`import torch
from diffusers import StableDiffusionModelEditingPipeline

model_ckpt = "CompVis/stable-diffusion-v1-4"
pipe = StableDiffusionModelEditingPipeline.from_pretrained(model_ckpt)

pipe = pipe.to("cuda")

source_prompt = "A pack of roses"
destination_prompt = "A pack of blue roses"
pipe.edit_model(source_prompt, destination_prompt)

prompt = "A field of roses"
image = pipe(prompt).images[0]
image.save("field_of_roses.png")`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionModelEditingPipeline

model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
pipe = StableDiffusionModelEditingPipeline.from_pretrained(model_ckpt)

pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

source_prompt = <span class="hljs-string">&quot;A pack of roses&quot;</span>
destination_prompt = <span class="hljs-string">&quot;A pack of blue roses&quot;</span>
pipe.edit_model(source_prompt, destination_prompt)

prompt = <span class="hljs-string">&quot;A field of roses&quot;</span>
image = pipe(prompt).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;field_of_roses.png&quot;</span>)`}}),oe=new it({}),ne=new Te({props:{name:"class diffusers.StableDiffusionModelEditingPipeline",anchor:"diffusers.StableDiffusionModelEditingPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": SchedulerMixin"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"feature_extractor",val:": CLIPFeatureExtractor"},{name:"requires_safety_checker",val:": bool = True"},{name:"with_to_k",val:": bool = True"},{name:"with_augs",val:": list = ['A photo of ', 'An image of ', 'A picture of ']"}],parametersDescription:[{anchor:"diffusers.StableDiffusionModelEditingPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.16.0/en/api/models#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.text_encoder",description:`<strong>text_encoder</strong> (<code>CLIPTextModel</code>) &#x2014;
Frozen text-encoder. Stable Diffusion uses the text portion of
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIP</a>, specifically
the <a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a> variant.`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>CLIPTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/v0.16.0/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.16.0/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents.`,name:"scheduler"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.safety_checker",description:`<strong>safety_checker</strong> (<code>StableDiffusionSafetyChecker</code>) &#x2014;
Classification module that estimates whether generated images could be considered offensive or harmful.
Please, refer to the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow">model card</a> for details.`,name:"safety_checker"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<code>CLIPFeatureExtractor</code>) &#x2014;
Model that extracts features from generated images to be used as inputs for the <code>safety_checker</code>.`,name:"feature_extractor"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.with_to_k",description:`<strong>with_to_k</strong> (<code>bool</code>) &#x2014;
Whether to edit the key projection matrices along wiht the value projection matrices.`,name:"with_to_k"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.with_augs",description:`<strong>with_augs</strong> (<code>list</code>) &#x2014;
Textual augmentations to apply while editing the text-to-image model. Set to [] for no augmentations.`,name:"with_augs"}],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L56"}}),se=new Te({props:{name:"__call__",anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]] = None"},{name:"height",val:": typing.Optional[int] = None"},{name:"width",val:": typing.Optional[int] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 7.5"},{name:"negative_prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"eta",val:": float = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": int = 1"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,name:"prompt"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The height in pixels of the generated image.`,name:"height"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.width",description:`<strong>width</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The width in pixels of the generated image.`,name:"width"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. If not defined, one has to pass
<code>negative_prompt_embeds</code> instead. Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code> is
less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate per prompt.`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) in the DDIM paper: <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">https://arxiv.org/abs/2010.02502</a>. Only applies to
<a href="/docs/diffusers/v0.16.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument.`,name:"negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.cross_attention_kwargs",description:`<strong>cross_attention_kwargs</strong> (<code>dict</code>, <em>optional</em>) &#x2014;
A kwargs dictionary that if specified is passed along to the <code>AttentionProcessor</code> as defined under
<code>self.processor</code> in
<a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cross_attention.py" rel="nofollow">diffusers.cross_attention</a>.`,name:"cross_attention_kwargs"}],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L596",returnDescription:`
<p><a
  href="/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> if <code>return_dict</code> is True, otherwise a <code>tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of </code>bool<code>s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) content, according to the </code>safety_checker\`.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),re=new Te({props:{name:"disable_vae_slicing",anchor:"diffusers.StableDiffusionModelEditingPipeline.disable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L175"}}),de=new Te({props:{name:"edit_model",anchor:"diffusers.StableDiffusionModelEditingPipeline.edit_model",parameters:[{name:"source_prompt",val:": str"},{name:"destination_prompt",val:": str"},{name:"lamb",val:": float = 0.1"},{name:"restart_params",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionModelEditingPipeline.edit_model.source_prompt",description:`<strong>source_prompt</strong> (<code>str</code>) &#x2014;
The source prompt containing the concept to be edited.`,name:"source_prompt"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.edit_model.destination_prompt",description:`<strong>destination_prompt</strong> (<code>str</code>) &#x2014;
The destination prompt. Must contain all words from source_prompt with additional ones to specify the
target edit.`,name:"destination_prompt"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.edit_model.lamb",description:`<strong>lamb</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The lambda parameter specifying the regularization intesity. Smaller values increase the editing power.`,name:"lamb"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.edit_model.restart_params",description:`<strong>restart_params</strong> (<code>bool</code>, <em>optional</em>, defaults to True) &#x2014;
Restart the model parameters to their pre-trained version before editing. This is done to avoid edit
compounding. When it is False, edits accumulate.`,name:"restart_params"}],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L478"}}),ce=new Te({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionModelEditingPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L183"}}),ue=new Te({props:{name:"enable_vae_slicing",anchor:"diffusers.StableDiffusionModelEditingPipeline.enable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L165"}}),{c(){P=o("meta"),ot=d(),D=o("h1"),C=o("a"),Se=o("span"),g(G.$$.fragment),St=d(),Ie=o("span"),It=r("Editing Implicit Assumptions in Text-to-Image Diffusion Models"),nt=d(),k=o("h2"),L=o("a"),Ae=o("span"),g(H.$$.fragment),At=d(),Ce=o("span"),Ct=r("Overview"),at=d(),W=o("p"),B=o("a"),Lt=r("Editing Implicit Assumptions in Text-to-Image Diffusion Models"),Ot=r(" by Hadas Orgad, Bahjat Kawar, and Yonatan Belinkov."),st=d(),me=o("p"),Nt=r("The abstract of the paper is the following:"),rt=d(),he=o("p"),Le=o("em"),qt=r("Text-to-image diffusion models often make implicit assumptions about the world when generating images. While some assumptions are useful (e.g., the sky is blue), they can also be outdated, incorrect, or reflective of social biases present in the training data. Thus, there is a need to control these assumptions without requiring explicit user input or costly re-training. In this work, we aim to edit a given implicit assumption in a pre-trained diffusion model. Our Text-to-Image Model Editing method, TIME for short, receives a pair of inputs: a \u201Csource\u201D under-specified prompt for which the model makes an implicit assumption (e.g., \u201Ca pack of roses\u201D), and a \u201Cdestination\u201D prompt that describes the same setting, but with a specified desired attribute (e.g., \u201Ca pack of blue roses\u201D). TIME then updates the model\u2019s cross-attention layers, as these layers assign visual meaning to textual tokens. We edit the projection matrices in these layers such that the source prompt is projected close to the destination prompt. Our method is highly efficient, as it modifies a mere 2.2% of the model\u2019s parameters in under one second. To evaluate model editing approaches, we introduce TIMED (TIME Dataset), containing 147 source and destination prompt pairs from various domains. Our experiments (using Stable Diffusion) show that TIME is successful in model editing, generalizes well for related prompts unseen during editing, and imposes minimal effect on unrelated generations."),lt=d(),ge=o("p"),jt=r("Resources:"),dt=d(),h=o("ul"),_e=o("li"),R=o("a"),Ut=r("Project Page"),zt=r("."),Vt=d(),ve=o("li"),K=o("a"),Ft=r("Paper"),Gt=r("."),Ht=d(),be=o("li"),Y=o("a"),Wt=r("Original Code"),Bt=r("."),Rt=d(),we=o("li"),J=o("a"),Kt=r("Demo"),Yt=r("."),pt=d(),$=o("h2"),O=o("a"),Oe=o("span"),g(Q.$$.fragment),Jt=d(),Ne=o("span"),Qt=r("Available Pipelines:"),ft=d(),N=o("table"),qe=o("thead"),M=o("tr"),je=o("th"),Xt=r("Pipeline"),Zt=d(),Ue=o("th"),ei=r("Tasks"),ti=d(),Ee=o("th"),ii=r("Demo"),oi=d(),ze=o("tbody"),T=o("tr"),Ve=o("td"),X=o("a"),ni=r("StableDiffusionModelEditingPipeline"),ai=d(),Fe=o("td"),Ge=o("em"),si=r("Text-to-Image Model Editing"),ri=d(),Z=o("td"),ee=o("a"),li=r("\u{1F917} Space"),di=r(")"),ct=d(),ye=o("p"),pi=r("This pipeline enables editing the diffusion model weights, such that its assumptions on a given concept are changed. The resulting change is expected to take effect in all prompt generations pertaining to the edited concept."),ut=d(),S=o("h2"),q=o("a"),He=o("span"),g(te.$$.fragment),fi=d(),We=o("span"),ci=r("Usage example"),mt=d(),g(ie.$$.fragment),ht=d(),I=o("h2"),j=o("a"),Be=o("span"),g(oe.$$.fragment),ui=d(),Re=o("span"),mi=r("StableDiffusionModelEditingPipeline"),gt=d(),u=o("div"),g(ne.$$.fragment),hi=d(),Ke=o("p"),gi=r("Pipeline for text-to-image model editing using \u201CEditing Implicit Assumptions in Text-to-Image Diffusion Models\u201D."),_i=d(),ae=o("p"),vi=r("This model inherits from "),xe=o("a"),bi=r("DiffusionPipeline"),wi=r(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.).`),Ei=d(),y=o("div"),g(se.$$.fragment),yi=d(),Ye=o("p"),xi=r("Function invoked when calling the pipeline for generation."),Pi=d(),Je=o("p"),Di=r("Examples:"),ki=d(),U=o("div"),g(re.$$.fragment),$i=d(),le=o("p"),Mi=r("Disable sliced VAE decoding. If "),Qe=o("code"),Ti=r("enable_vae_slicing"),Si=r(` was previously invoked, this method will go back to
computing decoding in one step.`),Ii=d(),z=o("div"),g(de.$$.fragment),Ai=d(),pe=o("p"),Ci=r("Apply model editing via closed-form solution (see Eq. 5 in the TIME paper "),fe=o("a"),Li=r("https://arxiv.org/abs/2303.08084"),Oi=r(")"),Ni=d(),V=o("div"),g(ce.$$.fragment),qi=d(),A=o("p"),ji=r(`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),Xe=o("code"),Ui=r("torch.device('meta') and loaded to GPU only when their specific submodule has its "),zi=r("forward"),Ze=o("code"),Vi=r("method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Fi=r("enable_model_cpu_offload`, but performance is lower."),Gi=d(),x=o("div"),g(ue.$$.fragment),Hi=d(),et=o("p"),Wi=r("Enable sliced VAE decoding."),Bi=d(),tt=o("p"),Ri=r(`When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several
steps. This is useful to save some memory and allow larger batch sizes.`),this.h()},l(t){const f=Jo('[data-svelte="svelte-1phssyn"]',document.head);P=n(f,"META",{name:!0,content:!0}),f.forEach(i),ot=p(t),D=n(t,"H1",{class:!0});var vt=a(D);C=n(vt,"A",{id:!0,class:!0,href:!0});var to=a(C);Se=n(to,"SPAN",{});var io=a(Se);_(G.$$.fragment,io),io.forEach(i),to.forEach(i),St=p(vt),Ie=n(vt,"SPAN",{});var oo=a(Ie);It=l(oo,"Editing Implicit Assumptions in Text-to-Image Diffusion Models"),oo.forEach(i),vt.forEach(i),nt=p(t),k=n(t,"H2",{class:!0});var bt=a(k);L=n(bt,"A",{id:!0,class:!0,href:!0});var no=a(L);Ae=n(no,"SPAN",{});var ao=a(Ae);_(H.$$.fragment,ao),ao.forEach(i),no.forEach(i),At=p(bt),Ce=n(bt,"SPAN",{});var so=a(Ce);Ct=l(so,"Overview"),so.forEach(i),bt.forEach(i),at=p(t),W=n(t,"P",{});var Ki=a(W);B=n(Ki,"A",{href:!0,rel:!0});var ro=a(B);Lt=l(ro,"Editing Implicit Assumptions in Text-to-Image Diffusion Models"),ro.forEach(i),Ot=l(Ki," by Hadas Orgad, Bahjat Kawar, and Yonatan Belinkov."),Ki.forEach(i),st=p(t),me=n(t,"P",{});var lo=a(me);Nt=l(lo,"The abstract of the paper is the following:"),lo.forEach(i),rt=p(t),he=n(t,"P",{});var po=a(he);Le=n(po,"EM",{});var fo=a(Le);qt=l(fo,"Text-to-image diffusion models often make implicit assumptions about the world when generating images. While some assumptions are useful (e.g., the sky is blue), they can also be outdated, incorrect, or reflective of social biases present in the training data. Thus, there is a need to control these assumptions without requiring explicit user input or costly re-training. In this work, we aim to edit a given implicit assumption in a pre-trained diffusion model. Our Text-to-Image Model Editing method, TIME for short, receives a pair of inputs: a \u201Csource\u201D under-specified prompt for which the model makes an implicit assumption (e.g., \u201Ca pack of roses\u201D), and a \u201Cdestination\u201D prompt that describes the same setting, but with a specified desired attribute (e.g., \u201Ca pack of blue roses\u201D). TIME then updates the model\u2019s cross-attention layers, as these layers assign visual meaning to textual tokens. We edit the projection matrices in these layers such that the source prompt is projected close to the destination prompt. Our method is highly efficient, as it modifies a mere 2.2% of the model\u2019s parameters in under one second. To evaluate model editing approaches, we introduce TIMED (TIME Dataset), containing 147 source and destination prompt pairs from various domains. Our experiments (using Stable Diffusion) show that TIME is successful in model editing, generalizes well for related prompts unseen during editing, and imposes minimal effect on unrelated generations."),fo.forEach(i),po.forEach(i),lt=p(t),ge=n(t,"P",{});var co=a(ge);jt=l(co,"Resources:"),co.forEach(i),dt=p(t),h=n(t,"UL",{});var F=a(h);_e=n(F,"LI",{});var Yi=a(_e);R=n(Yi,"A",{href:!0,rel:!0});var uo=a(R);Ut=l(uo,"Project Page"),uo.forEach(i),zt=l(Yi,"."),Yi.forEach(i),Vt=p(F),ve=n(F,"LI",{});var Ji=a(ve);K=n(Ji,"A",{href:!0,rel:!0});var mo=a(K);Ft=l(mo,"Paper"),mo.forEach(i),Gt=l(Ji,"."),Ji.forEach(i),Ht=p(F),be=n(F,"LI",{});var Qi=a(be);Y=n(Qi,"A",{href:!0,rel:!0});var ho=a(Y);Wt=l(ho,"Original Code"),ho.forEach(i),Bt=l(Qi,"."),Qi.forEach(i),Rt=p(F),we=n(F,"LI",{});var Xi=a(we);J=n(Xi,"A",{href:!0,rel:!0});var go=a(J);Kt=l(go,"Demo"),go.forEach(i),Yt=l(Xi,"."),Xi.forEach(i),F.forEach(i),pt=p(t),$=n(t,"H2",{class:!0});var wt=a($);O=n(wt,"A",{id:!0,class:!0,href:!0});var _o=a(O);Oe=n(_o,"SPAN",{});var vo=a(Oe);_(Q.$$.fragment,vo),vo.forEach(i),_o.forEach(i),Jt=p(wt),Ne=n(wt,"SPAN",{});var bo=a(Ne);Qt=l(bo,"Available Pipelines:"),bo.forEach(i),wt.forEach(i),ft=p(t),N=n(t,"TABLE",{});var Et=a(N);qe=n(Et,"THEAD",{});var wo=a(qe);M=n(wo,"TR",{});var Pe=a(M);je=n(Pe,"TH",{});var Eo=a(je);Xt=l(Eo,"Pipeline"),Eo.forEach(i),Zt=p(Pe),Ue=n(Pe,"TH",{});var yo=a(Ue);ei=l(yo,"Tasks"),yo.forEach(i),ti=p(Pe),Ee=n(Pe,"TH",{align:!0});var xo=a(Ee);ii=l(xo,"Demo"),xo.forEach(i),Pe.forEach(i),wo.forEach(i),oi=p(Et),ze=n(Et,"TBODY",{});var Po=a(ze);T=n(Po,"TR",{});var De=a(T);Ve=n(De,"TD",{});var Do=a(Ve);X=n(Do,"A",{href:!0,rel:!0});var ko=a(X);ni=l(ko,"StableDiffusionModelEditingPipeline"),ko.forEach(i),Do.forEach(i),ai=p(De),Fe=n(De,"TD",{});var $o=a(Fe);Ge=n($o,"EM",{});var Mo=a(Ge);si=l(Mo,"Text-to-Image Model Editing"),Mo.forEach(i),$o.forEach(i),ri=p(De),Z=n(De,"TD",{align:!0});var Zi=a(Z);ee=n(Zi,"A",{href:!0,rel:!0});var To=a(ee);li=l(To,"\u{1F917} Space"),To.forEach(i),di=l(Zi,")"),Zi.forEach(i),De.forEach(i),Po.forEach(i),Et.forEach(i),ct=p(t),ye=n(t,"P",{});var So=a(ye);pi=l(So,"This pipeline enables editing the diffusion model weights, such that its assumptions on a given concept are changed. The resulting change is expected to take effect in all prompt generations pertaining to the edited concept."),So.forEach(i),ut=p(t),S=n(t,"H2",{class:!0});var yt=a(S);q=n(yt,"A",{id:!0,class:!0,href:!0});var Io=a(q);He=n(Io,"SPAN",{});var Ao=a(He);_(te.$$.fragment,Ao),Ao.forEach(i),Io.forEach(i),fi=p(yt),We=n(yt,"SPAN",{});var Co=a(We);ci=l(Co,"Usage example"),Co.forEach(i),yt.forEach(i),mt=p(t),_(ie.$$.fragment,t),ht=p(t),I=n(t,"H2",{class:!0});var xt=a(I);j=n(xt,"A",{id:!0,class:!0,href:!0});var Lo=a(j);Be=n(Lo,"SPAN",{});var Oo=a(Be);_(oe.$$.fragment,Oo),Oo.forEach(i),Lo.forEach(i),ui=p(xt),Re=n(xt,"SPAN",{});var No=a(Re);mi=l(No,"StableDiffusionModelEditingPipeline"),No.forEach(i),xt.forEach(i),gt=p(t),u=n(t,"DIV",{class:!0});var m=a(u);_(ne.$$.fragment,m),hi=p(m),Ke=n(m,"P",{});var qo=a(Ke);gi=l(qo,"Pipeline for text-to-image model editing using \u201CEditing Implicit Assumptions in Text-to-Image Diffusion Models\u201D."),qo.forEach(i),_i=p(m),ae=n(m,"P",{});var Pt=a(ae);vi=l(Pt,"This model inherits from "),xe=n(Pt,"A",{href:!0});var jo=a(xe);bi=l(jo,"DiffusionPipeline"),jo.forEach(i),wi=l(Pt,`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.).`),Pt.forEach(i),Ei=p(m),y=n(m,"DIV",{class:!0});var ke=a(y);_(se.$$.fragment,ke),yi=p(ke),Ye=n(ke,"P",{});var Uo=a(Ye);xi=l(Uo,"Function invoked when calling the pipeline for generation."),Uo.forEach(i),Pi=p(ke),Je=n(ke,"P",{});var zo=a(Je);Di=l(zo,"Examples:"),zo.forEach(i),ke.forEach(i),ki=p(m),U=n(m,"DIV",{class:!0});var Dt=a(U);_(re.$$.fragment,Dt),$i=p(Dt),le=n(Dt,"P",{});var kt=a(le);Mi=l(kt,"Disable sliced VAE decoding. If "),Qe=n(kt,"CODE",{});var Vo=a(Qe);Ti=l(Vo,"enable_vae_slicing"),Vo.forEach(i),Si=l(kt,` was previously invoked, this method will go back to
computing decoding in one step.`),kt.forEach(i),Dt.forEach(i),Ii=p(m),z=n(m,"DIV",{class:!0});var $t=a(z);_(de.$$.fragment,$t),Ai=p($t),pe=n($t,"P",{});var Mt=a(pe);Ci=l(Mt,"Apply model editing via closed-form solution (see Eq. 5 in the TIME paper "),fe=n(Mt,"A",{href:!0,rel:!0});var Fo=a(fe);Li=l(Fo,"https://arxiv.org/abs/2303.08084"),Fo.forEach(i),Oi=l(Mt,")"),Mt.forEach(i),$t.forEach(i),Ni=p(m),V=n(m,"DIV",{class:!0});var Tt=a(V);_(ce.$$.fragment,Tt),qi=p(Tt),A=n(Tt,"P",{});var $e=a(A);ji=l($e,`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),Xe=n($e,"CODE",{});var Go=a(Xe);Ui=l(Go,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),Go.forEach(i),zi=l($e,"forward"),Ze=n($e,"CODE",{});var Ho=a(Ze);Vi=l(Ho,"method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Ho.forEach(i),Fi=l($e,"enable_model_cpu_offload`, but performance is lower."),$e.forEach(i),Tt.forEach(i),Gi=p(m),x=n(m,"DIV",{class:!0});var Me=a(x);_(ue.$$.fragment,Me),Hi=p(Me),et=n(Me,"P",{});var Wo=a(et);Wi=l(Wo,"Enable sliced VAE decoding."),Wo.forEach(i),Bi=p(Me),tt=n(Me,"P",{});var Bo=a(tt);Ri=l(Bo,`When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several
steps. This is useful to save some memory and allow larger batch sizes.`),Bo.forEach(i),Me.forEach(i),m.forEach(i),this.h()},h(){s(P,"name","hf:doc:metadata"),s(P,"content",JSON.stringify(tn)),s(C,"id","editing-implicit-assumptions-in-texttoimage-diffusion-models"),s(C,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),s(C,"href","#editing-implicit-assumptions-in-texttoimage-diffusion-models"),s(D,"class","relative group"),s(L,"id","overview"),s(L,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),s(L,"href","#overview"),s(k,"class","relative group"),s(B,"href","https://arxiv.org/abs/2303.08084"),s(B,"rel","nofollow"),s(R,"href","https://time-diffusion.github.io/"),s(R,"rel","nofollow"),s(K,"href","https://arxiv.org/abs/2303.08084"),s(K,"rel","nofollow"),s(Y,"href","https://github.com/bahjat-kawar/time-diffusion"),s(Y,"rel","nofollow"),s(J,"href","https://huggingface.co/spaces/bahjat-kawar/time-diffusion"),s(J,"rel","nofollow"),s(O,"id","available-pipelines"),s(O,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),s(O,"href","#available-pipelines"),s($,"class","relative group"),s(Ee,"align","center"),s(X,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py"),s(X,"rel","nofollow"),s(ee,"href","https://huggingface.co/spaces/bahjat-kawar/time-diffusion"),s(ee,"rel","nofollow"),s(Z,"align","center"),s(q,"id","usage-example"),s(q,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),s(q,"href","#usage-example"),s(S,"class","relative group"),s(j,"id","diffusers.StableDiffusionModelEditingPipeline"),s(j,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),s(j,"href","#diffusers.StableDiffusionModelEditingPipeline"),s(I,"class","relative group"),s(xe,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),s(y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),s(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),s(fe,"href","https://arxiv.org/abs/2303.08084"),s(fe,"rel","nofollow"),s(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),s(V,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),s(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),s(u,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,f){e(document.head,P),c(t,ot,f),c(t,D,f),e(D,C),e(C,Se),v(G,Se,null),e(D,St),e(D,Ie),e(Ie,It),c(t,nt,f),c(t,k,f),e(k,L),e(L,Ae),v(H,Ae,null),e(k,At),e(k,Ce),e(Ce,Ct),c(t,at,f),c(t,W,f),e(W,B),e(B,Lt),e(W,Ot),c(t,st,f),c(t,me,f),e(me,Nt),c(t,rt,f),c(t,he,f),e(he,Le),e(Le,qt),c(t,lt,f),c(t,ge,f),e(ge,jt),c(t,dt,f),c(t,h,f),e(h,_e),e(_e,R),e(R,Ut),e(_e,zt),e(h,Vt),e(h,ve),e(ve,K),e(K,Ft),e(ve,Gt),e(h,Ht),e(h,be),e(be,Y),e(Y,Wt),e(be,Bt),e(h,Rt),e(h,we),e(we,J),e(J,Kt),e(we,Yt),c(t,pt,f),c(t,$,f),e($,O),e(O,Oe),v(Q,Oe,null),e($,Jt),e($,Ne),e(Ne,Qt),c(t,ft,f),c(t,N,f),e(N,qe),e(qe,M),e(M,je),e(je,Xt),e(M,Zt),e(M,Ue),e(Ue,ei),e(M,ti),e(M,Ee),e(Ee,ii),e(N,oi),e(N,ze),e(ze,T),e(T,Ve),e(Ve,X),e(X,ni),e(T,ai),e(T,Fe),e(Fe,Ge),e(Ge,si),e(T,ri),e(T,Z),e(Z,ee),e(ee,li),e(Z,di),c(t,ct,f),c(t,ye,f),e(ye,pi),c(t,ut,f),c(t,S,f),e(S,q),e(q,He),v(te,He,null),e(S,fi),e(S,We),e(We,ci),c(t,mt,f),v(ie,t,f),c(t,ht,f),c(t,I,f),e(I,j),e(j,Be),v(oe,Be,null),e(I,ui),e(I,Re),e(Re,mi),c(t,gt,f),c(t,u,f),v(ne,u,null),e(u,hi),e(u,Ke),e(Ke,gi),e(u,_i),e(u,ae),e(ae,vi),e(ae,xe),e(xe,bi),e(ae,wi),e(u,Ei),e(u,y),v(se,y,null),e(y,yi),e(y,Ye),e(Ye,xi),e(y,Pi),e(y,Je),e(Je,Di),e(u,ki),e(u,U),v(re,U,null),e(U,$i),e(U,le),e(le,Mi),e(le,Qe),e(Qe,Ti),e(le,Si),e(u,Ii),e(u,z),v(de,z,null),e(z,Ai),e(z,pe),e(pe,Ci),e(pe,fe),e(fe,Li),e(pe,Oi),e(u,Ni),e(u,V),v(ce,V,null),e(V,qi),e(V,A),e(A,ji),e(A,Xe),e(Xe,Ui),e(A,zi),e(A,Ze),e(Ze,Vi),e(A,Fi),e(u,Gi),e(u,x),v(ue,x,null),e(x,Hi),e(x,et),e(et,Wi),e(x,Bi),e(x,tt),e(tt,Ri),_t=!0},p:Qo,i(t){_t||(b(G.$$.fragment,t),b(H.$$.fragment,t),b(Q.$$.fragment,t),b(te.$$.fragment,t),b(ie.$$.fragment,t),b(oe.$$.fragment,t),b(ne.$$.fragment,t),b(se.$$.fragment,t),b(re.$$.fragment,t),b(de.$$.fragment,t),b(ce.$$.fragment,t),b(ue.$$.fragment,t),_t=!0)},o(t){w(G.$$.fragment,t),w(H.$$.fragment,t),w(Q.$$.fragment,t),w(te.$$.fragment,t),w(ie.$$.fragment,t),w(oe.$$.fragment,t),w(ne.$$.fragment,t),w(se.$$.fragment,t),w(re.$$.fragment,t),w(de.$$.fragment,t),w(ce.$$.fragment,t),w(ue.$$.fragment,t),_t=!1},d(t){i(P),t&&i(ot),t&&i(D),E(G),t&&i(nt),t&&i(k),E(H),t&&i(at),t&&i(W),t&&i(st),t&&i(me),t&&i(rt),t&&i(he),t&&i(lt),t&&i(ge),t&&i(dt),t&&i(h),t&&i(pt),t&&i($),E(Q),t&&i(ft),t&&i(N),t&&i(ct),t&&i(ye),t&&i(ut),t&&i(S),E(te),t&&i(mt),E(ie,t),t&&i(ht),t&&i(I),E(oe),t&&i(gt),t&&i(u),E(ne),E(se),E(re),E(de),E(ce),E(ue)}}}const tn={local:"editing-implicit-assumptions-in-texttoimage-diffusion-models",sections:[{local:"overview",title:"Overview"},{local:"available-pipelines",title:"Available Pipelines:"},{local:"usage-example",title:"Usage example"},{local:"diffusers.StableDiffusionModelEditingPipeline",title:"StableDiffusionModelEditingPipeline"}],title:"Editing Implicit Assumptions in Text-to-Image Diffusion Models"};function on(eo){return Xo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ln extends Ro{constructor(P){super();Ko(this,P,on,en,Yo,{})}}export{ln as default,tn as metadata};
