import{S as Vo,i as Ho,s as Xo,e as o,k as d,w as g,t as r,M as Qo,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 b,L as Ro,q as v,o as w,B as E,v as Yo}from"../../../chunks/vendor-hf-doc-builder.js";import{D as $e}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as Ko}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as it}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function en(eo){let M,ot,T,N,Ie,q,It,Se,St,nt,P,C,Ae,B,At,Ne,Nt,at,F,z,Ct,jt,st,me,Jt,rt,he,Ce,Ut,lt,ge,Lt,dt,h,_e,V,Ot,Wt,Gt,be,H,Zt,qt,Bt,ve,X,Ft,zt,Vt,we,Q,Ht,Xt,pt,k,j,je,R,Qt,Je,Rt,ft,J,Ue,D,Le,Yt,Kt,Oe,ei,ti,Ee,ii,oi,We,$,Ge,Y,ni,ai,Ze,qe,si,ri,K,ee,li,di,ct,ye,pi,ut,I,U,Be,te,fi,Fe,ci,mt,ie,ht,S,L,ze,oe,ui,Ve,mi,gt,u,ne,hi,He,gi,_i,ae,bi,xe,vi,wi,Ei,y,se,yi,Xe,xi,Mi,Qe,Ti,Pi,O,re,ki,le,Di,Re,$i,Ii,Si,W,de,Ai,pe,Ni,fe,Ci,ji,Ji,G,ce,Ui,A,Li,Ye,Oi,Wi,Ke,Gi,Zi,qi,x,ue,Bi,et,Fi,zi,tt,Vi,_t;return q=new it({}),B=new it({}),R=new it({}),te=new it({}),ie=new Ko({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uTW9kZWxFZGl0aW5nUGlwZWxpbmUlMEElMEFtb2RlbF9ja3B0JTIwJTNEJTIwJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25Nb2RlbEVkaXRpbmdQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2twdCklMEElMEFwaXBlJTIwJTNEJTIwcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQXNvdXJjZV9wcm9tcHQlMjAlM0QlMjAlMjJBJTIwcGFjayUyMG9mJTIwcm9zZXMlMjIlMEFkZXN0aW5hdGlvbl9wcm9tcHQlMjAlM0QlMjAlMjJBJTIwcGFjayUyMG9mJTIwYmx1ZSUyMHJvc2VzJTIyJTBBcGlwZS5lZGl0X21vZGVsKHNvdXJjZV9wcm9tcHQlMkMlMjBkZXN0aW5hdGlvbl9wcm9tcHQpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQSUyMGZpZWxkJTIwb2YlMjByb3NlcyUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQpLmltYWdlcyU1QjAlNUQlMEFpbWFnZS5zYXZlKCUyMmZpZWxkX29mX3Jvc2VzLnBuZyUyMik=",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 $e({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.17.1/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.17.1/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.17.1/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.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L58"}}),se=new $e({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.17.1/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.17.1/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.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L616",returnDescription:`
<p><a
  href="/docs/diffusers/v0.17.1/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.17.1/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),re=new $e({props:{name:"disable_vae_slicing",anchor:"diffusers.StableDiffusionModelEditingPipeline.disable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L178"}}),de=new $e({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.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L498"}}),ce=new $e({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.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L186"}}),ue=new $e({props:{name:"enable_vae_slicing",anchor:"diffusers.StableDiffusionModelEditingPipeline.enable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L168"}}),{c(){M=o("meta"),ot=d(),T=o("h1"),N=o("a"),Ie=o("span"),g(q.$$.fragment),It=d(),Se=o("span"),St=r("Editing Implicit Assumptions in Text-to-Image Diffusion Models"),nt=d(),P=o("h2"),C=o("a"),Ae=o("span"),g(B.$$.fragment),At=d(),Ne=o("span"),Nt=r("Overview"),at=d(),F=o("p"),z=o("a"),Ct=r("Editing Implicit Assumptions in Text-to-Image Diffusion Models"),jt=r(" by Hadas Orgad, Bahjat Kawar, and Yonatan Belinkov."),st=d(),me=o("p"),Jt=r("The abstract of the paper is the following:"),rt=d(),he=o("p"),Ce=o("em"),Ut=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"),Lt=r("Resources:"),dt=d(),h=o("ul"),_e=o("li"),V=o("a"),Ot=r("Project Page"),Wt=r("."),Gt=d(),be=o("li"),H=o("a"),Zt=r("Paper"),qt=r("."),Bt=d(),ve=o("li"),X=o("a"),Ft=r("Original Code"),zt=r("."),Vt=d(),we=o("li"),Q=o("a"),Ht=r("Demo"),Xt=r("."),pt=d(),k=o("h2"),j=o("a"),je=o("span"),g(R.$$.fragment),Qt=d(),Je=o("span"),Rt=r("Available Pipelines:"),ft=d(),J=o("table"),Ue=o("thead"),D=o("tr"),Le=o("th"),Yt=r("Pipeline"),Kt=d(),Oe=o("th"),ei=r("Tasks"),ti=d(),Ee=o("th"),ii=r("Demo"),oi=d(),We=o("tbody"),$=o("tr"),Ge=o("td"),Y=o("a"),ni=r("StableDiffusionModelEditingPipeline"),ai=d(),Ze=o("td"),qe=o("em"),si=r("Text-to-Image Model Editing"),ri=d(),K=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(),I=o("h2"),U=o("a"),Be=o("span"),g(te.$$.fragment),fi=d(),Fe=o("span"),ci=r("Usage example"),mt=d(),g(ie.$$.fragment),ht=d(),S=o("h2"),L=o("a"),ze=o("span"),g(oe.$$.fragment),ui=d(),Ve=o("span"),mi=r("StableDiffusionModelEditingPipeline"),gt=d(),u=o("div"),g(ne.$$.fragment),hi=d(),He=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"),bi=r("This model inherits from "),xe=o("a"),vi=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(),Xe=o("p"),xi=r("Function invoked when calling the pipeline for generation."),Mi=d(),Qe=o("p"),Ti=r("Examples:"),Pi=d(),O=o("div"),g(re.$$.fragment),ki=d(),le=o("p"),Di=r("Disable sliced VAE decoding. If "),Re=o("code"),$i=r("enable_vae_slicing"),Ii=r(` was previously invoked, this method will go back to
computing decoding in one step.`),Si=d(),W=o("div"),g(de.$$.fragment),Ai=d(),pe=o("p"),Ni=r("Apply model editing via closed-form solution (see Eq. 5 in the TIME paper "),fe=o("a"),Ci=r("https://arxiv.org/abs/2303.08084"),ji=r(")"),Ji=d(),G=o("div"),g(ce.$$.fragment),Ui=d(),A=o("p"),Li=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
`),Ye=o("code"),Oi=r("torch.device('meta') and loaded to GPU only when their specific submodule has its "),Wi=r("forward"),Ke=o("code"),Gi=r("method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Zi=r("enable_model_cpu_offload`, but performance is lower."),qi=d(),x=o("div"),g(ue.$$.fragment),Bi=d(),et=o("p"),Fi=r("Enable sliced VAE decoding."),zi=d(),tt=o("p"),Vi=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=Qo('[data-svelte="svelte-1phssyn"]',document.head);M=n(f,"META",{name:!0,content:!0}),f.forEach(i),ot=p(t),T=n(t,"H1",{class:!0});var bt=a(T);N=n(bt,"A",{id:!0,class:!0,href:!0});var to=a(N);Ie=n(to,"SPAN",{});var io=a(Ie);_(q.$$.fragment,io),io.forEach(i),to.forEach(i),It=p(bt),Se=n(bt,"SPAN",{});var oo=a(Se);St=l(oo,"Editing Implicit Assumptions in Text-to-Image Diffusion Models"),oo.forEach(i),bt.forEach(i),nt=p(t),P=n(t,"H2",{class:!0});var vt=a(P);C=n(vt,"A",{id:!0,class:!0,href:!0});var no=a(C);Ae=n(no,"SPAN",{});var ao=a(Ae);_(B.$$.fragment,ao),ao.forEach(i),no.forEach(i),At=p(vt),Ne=n(vt,"SPAN",{});var so=a(Ne);Nt=l(so,"Overview"),so.forEach(i),vt.forEach(i),at=p(t),F=n(t,"P",{});var Hi=a(F);z=n(Hi,"A",{href:!0,rel:!0});var ro=a(z);Ct=l(ro,"Editing Implicit Assumptions in Text-to-Image Diffusion Models"),ro.forEach(i),jt=l(Hi," by Hadas Orgad, Bahjat Kawar, and Yonatan Belinkov."),Hi.forEach(i),st=p(t),me=n(t,"P",{});var lo=a(me);Jt=l(lo,"The abstract of the paper is the following:"),lo.forEach(i),rt=p(t),he=n(t,"P",{});var po=a(he);Ce=n(po,"EM",{});var fo=a(Ce);Ut=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);Lt=l(co,"Resources:"),co.forEach(i),dt=p(t),h=n(t,"UL",{});var Z=a(h);_e=n(Z,"LI",{});var Xi=a(_e);V=n(Xi,"A",{href:!0,rel:!0});var uo=a(V);Ot=l(uo,"Project Page"),uo.forEach(i),Wt=l(Xi,"."),Xi.forEach(i),Gt=p(Z),be=n(Z,"LI",{});var Qi=a(be);H=n(Qi,"A",{href:!0,rel:!0});var mo=a(H);Zt=l(mo,"Paper"),mo.forEach(i),qt=l(Qi,"."),Qi.forEach(i),Bt=p(Z),ve=n(Z,"LI",{});var Ri=a(ve);X=n(Ri,"A",{href:!0,rel:!0});var ho=a(X);Ft=l(ho,"Original Code"),ho.forEach(i),zt=l(Ri,"."),Ri.forEach(i),Vt=p(Z),we=n(Z,"LI",{});var Yi=a(we);Q=n(Yi,"A",{href:!0,rel:!0});var go=a(Q);Ht=l(go,"Demo"),go.forEach(i),Xt=l(Yi,"."),Yi.forEach(i),Z.forEach(i),pt=p(t),k=n(t,"H2",{class:!0});var wt=a(k);j=n(wt,"A",{id:!0,class:!0,href:!0});var _o=a(j);je=n(_o,"SPAN",{});var bo=a(je);_(R.$$.fragment,bo),bo.forEach(i),_o.forEach(i),Qt=p(wt),Je=n(wt,"SPAN",{});var vo=a(Je);Rt=l(vo,"Available Pipelines:"),vo.forEach(i),wt.forEach(i),ft=p(t),J=n(t,"TABLE",{});var Et=a(J);Ue=n(Et,"THEAD",{});var wo=a(Ue);D=n(wo,"TR",{});var Me=a(D);Le=n(Me,"TH",{});var Eo=a(Le);Yt=l(Eo,"Pipeline"),Eo.forEach(i),Kt=p(Me),Oe=n(Me,"TH",{});var yo=a(Oe);ei=l(yo,"Tasks"),yo.forEach(i),ti=p(Me),Ee=n(Me,"TH",{align:!0});var xo=a(Ee);ii=l(xo,"Demo"),xo.forEach(i),Me.forEach(i),wo.forEach(i),oi=p(Et),We=n(Et,"TBODY",{});var Mo=a(We);$=n(Mo,"TR",{});var Te=a($);Ge=n(Te,"TD",{});var To=a(Ge);Y=n(To,"A",{href:!0,rel:!0});var Po=a(Y);ni=l(Po,"StableDiffusionModelEditingPipeline"),Po.forEach(i),To.forEach(i),ai=p(Te),Ze=n(Te,"TD",{});var ko=a(Ze);qe=n(ko,"EM",{});var Do=a(qe);si=l(Do,"Text-to-Image Model Editing"),Do.forEach(i),ko.forEach(i),ri=p(Te),K=n(Te,"TD",{align:!0});var Ki=a(K);ee=n(Ki,"A",{href:!0,rel:!0});var $o=a(ee);li=l($o,"\u{1F917} Space"),$o.forEach(i),di=l(Ki,")"),Ki.forEach(i),Te.forEach(i),Mo.forEach(i),Et.forEach(i),ct=p(t),ye=n(t,"P",{});var Io=a(ye);pi=l(Io,"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."),Io.forEach(i),ut=p(t),I=n(t,"H2",{class:!0});var yt=a(I);U=n(yt,"A",{id:!0,class:!0,href:!0});var So=a(U);Be=n(So,"SPAN",{});var Ao=a(Be);_(te.$$.fragment,Ao),Ao.forEach(i),So.forEach(i),fi=p(yt),Fe=n(yt,"SPAN",{});var No=a(Fe);ci=l(No,"Usage example"),No.forEach(i),yt.forEach(i),mt=p(t),_(ie.$$.fragment,t),ht=p(t),S=n(t,"H2",{class:!0});var xt=a(S);L=n(xt,"A",{id:!0,class:!0,href:!0});var Co=a(L);ze=n(Co,"SPAN",{});var jo=a(ze);_(oe.$$.fragment,jo),jo.forEach(i),Co.forEach(i),ui=p(xt),Ve=n(xt,"SPAN",{});var Jo=a(Ve);mi=l(Jo,"StableDiffusionModelEditingPipeline"),Jo.forEach(i),xt.forEach(i),gt=p(t),u=n(t,"DIV",{class:!0});var m=a(u);_(ne.$$.fragment,m),hi=p(m),He=n(m,"P",{});var Uo=a(He);gi=l(Uo,"Pipeline for text-to-image model editing using \u201CEditing Implicit Assumptions in Text-to-Image Diffusion Models\u201D."),Uo.forEach(i),_i=p(m),ae=n(m,"P",{});var Mt=a(ae);bi=l(Mt,"This model inherits from "),xe=n(Mt,"A",{href:!0});var Lo=a(xe);vi=l(Lo,"DiffusionPipeline"),Lo.forEach(i),wi=l(Mt,`. 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.).`),Mt.forEach(i),Ei=p(m),y=n(m,"DIV",{class:!0});var Pe=a(y);_(se.$$.fragment,Pe),yi=p(Pe),Xe=n(Pe,"P",{});var Oo=a(Xe);xi=l(Oo,"Function invoked when calling the pipeline for generation."),Oo.forEach(i),Mi=p(Pe),Qe=n(Pe,"P",{});var Wo=a(Qe);Ti=l(Wo,"Examples:"),Wo.forEach(i),Pe.forEach(i),Pi=p(m),O=n(m,"DIV",{class:!0});var Tt=a(O);_(re.$$.fragment,Tt),ki=p(Tt),le=n(Tt,"P",{});var Pt=a(le);Di=l(Pt,"Disable sliced VAE decoding. If "),Re=n(Pt,"CODE",{});var Go=a(Re);$i=l(Go,"enable_vae_slicing"),Go.forEach(i),Ii=l(Pt,` was previously invoked, this method will go back to
computing decoding in one step.`),Pt.forEach(i),Tt.forEach(i),Si=p(m),W=n(m,"DIV",{class:!0});var kt=a(W);_(de.$$.fragment,kt),Ai=p(kt),pe=n(kt,"P",{});var Dt=a(pe);Ni=l(Dt,"Apply model editing via closed-form solution (see Eq. 5 in the TIME paper "),fe=n(Dt,"A",{href:!0,rel:!0});var Zo=a(fe);Ci=l(Zo,"https://arxiv.org/abs/2303.08084"),Zo.forEach(i),ji=l(Dt,")"),Dt.forEach(i),kt.forEach(i),Ji=p(m),G=n(m,"DIV",{class:!0});var $t=a(G);_(ce.$$.fragment,$t),Ui=p($t),A=n($t,"P",{});var ke=a(A);Li=l(ke,`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
`),Ye=n(ke,"CODE",{});var qo=a(Ye);Oi=l(qo,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),qo.forEach(i),Wi=l(ke,"forward"),Ke=n(ke,"CODE",{});var Bo=a(Ke);Gi=l(Bo,"method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Bo.forEach(i),Zi=l(ke,"enable_model_cpu_offload`, but performance is lower."),ke.forEach(i),$t.forEach(i),qi=p(m),x=n(m,"DIV",{class:!0});var De=a(x);_(ue.$$.fragment,De),Bi=p(De),et=n(De,"P",{});var Fo=a(et);Fi=l(Fo,"Enable sliced VAE decoding."),Fo.forEach(i),zi=p(De),tt=n(De,"P",{});var zo=a(tt);Vi=l(zo,`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.`),zo.forEach(i),De.forEach(i),m.forEach(i),this.h()},h(){s(M,"name","hf:doc:metadata"),s(M,"content",JSON.stringify(tn)),s(N,"id","editing-implicit-assumptions-in-texttoimage-diffusion-models"),s(N,"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(N,"href","#editing-implicit-assumptions-in-texttoimage-diffusion-models"),s(T,"class","relative group"),s(C,"id","overview"),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","#overview"),s(P,"class","relative group"),s(z,"href","https://arxiv.org/abs/2303.08084"),s(z,"rel","nofollow"),s(V,"href","https://time-diffusion.github.io/"),s(V,"rel","nofollow"),s(H,"href","https://arxiv.org/abs/2303.08084"),s(H,"rel","nofollow"),s(X,"href","https://github.com/bahjat-kawar/time-diffusion"),s(X,"rel","nofollow"),s(Q,"href","https://huggingface.co/spaces/bahjat-kawar/time-diffusion"),s(Q,"rel","nofollow"),s(j,"id","available-pipelines"),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","#available-pipelines"),s(k,"class","relative group"),s(Ee,"align","center"),s(Y,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py"),s(Y,"rel","nofollow"),s(ee,"href","https://huggingface.co/spaces/bahjat-kawar/time-diffusion"),s(ee,"rel","nofollow"),s(K,"align","center"),s(U,"id","usage-example"),s(U,"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(U,"href","#usage-example"),s(I,"class","relative group"),s(L,"id","diffusers.StableDiffusionModelEditingPipeline"),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","#diffusers.StableDiffusionModelEditingPipeline"),s(S,"class","relative group"),s(xe,"href","/docs/diffusers/v0.17.1/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(O,"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(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),s(G,"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,M),c(t,ot,f),c(t,T,f),e(T,N),e(N,Ie),b(q,Ie,null),e(T,It),e(T,Se),e(Se,St),c(t,nt,f),c(t,P,f),e(P,C),e(C,Ae),b(B,Ae,null),e(P,At),e(P,Ne),e(Ne,Nt),c(t,at,f),c(t,F,f),e(F,z),e(z,Ct),e(F,jt),c(t,st,f),c(t,me,f),e(me,Jt),c(t,rt,f),c(t,he,f),e(he,Ce),e(Ce,Ut),c(t,lt,f),c(t,ge,f),e(ge,Lt),c(t,dt,f),c(t,h,f),e(h,_e),e(_e,V),e(V,Ot),e(_e,Wt),e(h,Gt),e(h,be),e(be,H),e(H,Zt),e(be,qt),e(h,Bt),e(h,ve),e(ve,X),e(X,Ft),e(ve,zt),e(h,Vt),e(h,we),e(we,Q),e(Q,Ht),e(we,Xt),c(t,pt,f),c(t,k,f),e(k,j),e(j,je),b(R,je,null),e(k,Qt),e(k,Je),e(Je,Rt),c(t,ft,f),c(t,J,f),e(J,Ue),e(Ue,D),e(D,Le),e(Le,Yt),e(D,Kt),e(D,Oe),e(Oe,ei),e(D,ti),e(D,Ee),e(Ee,ii),e(J,oi),e(J,We),e(We,$),e($,Ge),e(Ge,Y),e(Y,ni),e($,ai),e($,Ze),e(Ze,qe),e(qe,si),e($,ri),e($,K),e(K,ee),e(ee,li),e(K,di),c(t,ct,f),c(t,ye,f),e(ye,pi),c(t,ut,f),c(t,I,f),e(I,U),e(U,Be),b(te,Be,null),e(I,fi),e(I,Fe),e(Fe,ci),c(t,mt,f),b(ie,t,f),c(t,ht,f),c(t,S,f),e(S,L),e(L,ze),b(oe,ze,null),e(S,ui),e(S,Ve),e(Ve,mi),c(t,gt,f),c(t,u,f),b(ne,u,null),e(u,hi),e(u,He),e(He,gi),e(u,_i),e(u,ae),e(ae,bi),e(ae,xe),e(xe,vi),e(ae,wi),e(u,Ei),e(u,y),b(se,y,null),e(y,yi),e(y,Xe),e(Xe,xi),e(y,Mi),e(y,Qe),e(Qe,Ti),e(u,Pi),e(u,O),b(re,O,null),e(O,ki),e(O,le),e(le,Di),e(le,Re),e(Re,$i),e(le,Ii),e(u,Si),e(u,W),b(de,W,null),e(W,Ai),e(W,pe),e(pe,Ni),e(pe,fe),e(fe,Ci),e(pe,ji),e(u,Ji),e(u,G),b(ce,G,null),e(G,Ui),e(G,A),e(A,Li),e(A,Ye),e(Ye,Oi),e(A,Wi),e(A,Ke),e(Ke,Gi),e(A,Zi),e(u,qi),e(u,x),b(ue,x,null),e(x,Bi),e(x,et),e(et,Fi),e(x,zi),e(x,tt),e(tt,Vi),_t=!0},p:Ro,i(t){_t||(v(q.$$.fragment,t),v(B.$$.fragment,t),v(R.$$.fragment,t),v(te.$$.fragment,t),v(ie.$$.fragment,t),v(oe.$$.fragment,t),v(ne.$$.fragment,t),v(se.$$.fragment,t),v(re.$$.fragment,t),v(de.$$.fragment,t),v(ce.$$.fragment,t),v(ue.$$.fragment,t),_t=!0)},o(t){w(q.$$.fragment,t),w(B.$$.fragment,t),w(R.$$.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(M),t&&i(ot),t&&i(T),E(q),t&&i(nt),t&&i(P),E(B),t&&i(at),t&&i(F),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(k),E(R),t&&i(ft),t&&i(J),t&&i(ct),t&&i(ye),t&&i(ut),t&&i(I),E(te),t&&i(mt),E(ie,t),t&&i(ht),t&&i(S),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 Yo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ln extends Vo{constructor(M){super();Ho(this,M,on,en,Xo,{})}}export{ln as default,tn as metadata};
