import{S as Kt,i as ei,s as ti,e as o,k as f,w as M,t as r,M as ii,c as n,d as i,m as u,a as s,x as D,h as l,b as a,G as t,g as m,y as T,q as $,o as P,B as k,v as oi,L as ni}from"../../../chunks/vendor-hf-doc-builder.js";import{T as si}from"../../../chunks/Tip-hf-doc-builder.js";import{D as ue}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as ai}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as St}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ri}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function li(le){let c,E,g,h,b,d,v,j;return{c(){c=o("p"),E=r("Make sure to check out the Schedulers "),g=o("a"),h=r("guide"),b=r(" to learn how to explore the tradeoff between scheduler speed and quality, and see the "),d=o("a"),v=r("reuse components across pipelines"),j=r(" section to learn how to efficiently load the same components into multiple pipelines."),this.h()},l(N){c=n(N,"P",{});var y=s(c);E=l(y,"Make sure to check out the Schedulers "),g=n(y,"A",{href:!0});var S=s(g);h=l(S,"guide"),S.forEach(i),b=l(y," to learn how to explore the tradeoff between scheduler speed and quality, and see the "),d=n(y,"A",{href:!0});var I=s(d);v=l(I,"reuse components across pipelines"),I.forEach(i),j=l(y," section to learn how to efficiently load the same components into multiple pipelines."),y.forEach(i),this.h()},h(){a(g,"href","/using-diffusers/schedulers"),a(d,"href","/using-diffusers/loading#reuse-components-across-pipelines")},m(N,y){m(N,c,y),t(c,E),t(c,g),t(g,h),t(c,b),t(c,d),t(d,v),t(c,j)},d(N){N&&i(c)}}}function di(le){let c,E,g,h,b;return h=new ai({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uTW9kZWxFZGl0aW5nUGlwZWxpbmUlMEElMEFtb2RlbF9ja3B0JTIwJTNEJTIwJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25Nb2RlbEVkaXRpbmdQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2twdCklMEElMEFwaXBlJTIwJTNEJTIwcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQXNvdXJjZV9wcm9tcHQlMjAlM0QlMjAlMjJBJTIwcGFjayUyMG9mJTIwcm9zZXMlMjIlMEFkZXN0aW5hdGlvbl9wcm9tcHQlMjAlM0QlMjAlMjJBJTIwcGFjayUyMG9mJTIwYmx1ZSUyMHJvc2VzJTIyJTBBcGlwZS5lZGl0X21vZGVsKHNvdXJjZV9wcm9tcHQlMkMlMjBkZXN0aW5hdGlvbl9wcm9tcHQpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQSUyMGZpZWxkJTIwb2YlMjByb3NlcyUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQpLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionModelEditingPipeline

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

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

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

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;A field of roses&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(prompt).images[<span class="hljs-number">0</span>]`}}),{c(){c=o("p"),E=r("Examples:"),g=f(),M(h.$$.fragment)},l(d){c=n(d,"P",{});var v=s(c);E=l(v,"Examples:"),v.forEach(i),g=u(d),D(h.$$.fragment,d)},m(d,v){m(d,c,v),t(c,E),m(d,g,v),T(h,d,v),b=!0},p:ni,i(d){b||($(h.$$.fragment,d),b=!0)},o(d){P(h.$$.fragment,d),b=!1},d(d){d&&i(c),d&&i(g),k(h,d)}}}function pi(le){let c,E,g,h,b,d,v,j,N,y,S,I,qe,Be,De,de,ze,Te,pe,me,Fe,$e,x,Ve,F,Qe,Xe,V,He,Ye,Q,Re,Ke,Pe,O,ke,L,G,ge,X,et,he,tt,Se,_,H,it,_e,ot,nt,Y,st,ce,at,rt,lt,A,R,dt,be,pt,ct,W,ft,U,K,ut,ee,mt,ve,gt,ht,_t,Z,te,bt,ie,vt,oe,wt,yt,Et,q,ne,xt,we,Mt,Ie,C,B,ye,se,Dt,Ee,Tt,Ae,J,ae,$t,xe,Pt,je;return d=new St({}),O=new si({props:{$$slots:{default:[li]},$$scope:{ctx:le}}}),X=new St({}),H=new ue({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.19.2/en/api/models/autoencoderkl#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> (<a href="https://huggingface.co/docs/transformers/v4.31.0/en/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIPTextModel</a>) &#x2014;
Frozen text-encoder (<a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a>).`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.tokenizer",description:`<strong>tokenizer</strong> (<a href="https://huggingface.co/docs/transformers/v4.31.0/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>) &#x2014;
A <code>CLIPTokenizer</code> to tokenize text.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.unet",description:`<strong>unet</strong> (<a href="/docs/diffusers/v0.19.2/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014;
A <code>UNet2DConditionModel</code> to denoise the encoded image latents.`,name:"unet"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.19.2/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. Can be one of
<a href="/docs/diffusers/v0.19.2/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.19.2/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.19.2/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>.`,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 more details
about a model&#x2019;s potential harms.`,name:"safety_checker"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<a href="https://huggingface.co/docs/transformers/v4.31.0/en/model_doc/clip#transformers.CLIPFeatureExtractor" rel="nofollow">CLIPFeatureExtractor</a>) &#x2014;
A <code>CLIPFeatureExtractor</code> to extract features from generated images; used as inputs to 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 with 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 <code>[]</code> for no augmentations.`,name:"with_augs"}],source:"https://github.com/huggingface/diffusers/blob/v0.19.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L38"}}),R=new ue({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[typing.List[str], 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 image generation. If not defined, you need to pass <code>prompt_embeds</code>.`,name:"prompt"},{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to <code>self.unet.config.sample_size * self.vae_scale_factor</code>) &#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 <code>self.unet.config.sample_size * self.vae_scale_factor</code>) &#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;
A higher guidance scale value encourages the model to generate images closely linked to the text
<code>prompt</code> at the expense of lower image quality. Guidance scale is enabled when <code>guidance_scale &gt; 1</code>.`,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 to guide what to not include in image generation. If not defined, you need to
pass <code>negative_prompt_embeds</code> instead. Ignored when not using guidance (<code>guidance_scale &lt; 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;) from the <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">DDIM</a> paper. Only applies
to the <a href="/docs/diffusers/v0.19.2/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, and is ignored in other schedulers.`,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;
A <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow"><code>torch.Generator</code></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 is 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 (prompt weighting). If not
provided, text embeddings are generated from the <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 (prompt weighting). If
not provided, <code>negative_prompt_embeds</code> are generated from the <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 generated image. Choose between <code>PIL.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.19.2/en/api/pipelines/stable_diffusion/inpaint#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 calls every <code>callback_steps</code> steps during inference. The function is 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 is called. If not specified, the callback is 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 in
<a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cross_attention.py" rel="nofollow"><code>self.processor</code></a>.`,name:"cross_attention_kwargs"}],source:"https://github.com/huggingface/diffusers/blob/v0.19.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L549",returnDescription:`
<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/v0.19.2/en/api/pipelines/stable_diffusion/inpaint#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> is returned,
otherwise a <code>tuple</code> is returned where the first element is a list with the generated images and the
second element is a list of <code>bool</code>s indicating whether the corresponding generated image contains
\u201Cnot-safe-for-work\u201D (nsfw) content.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/v0.19.2/en/api/pipelines/stable_diffusion/inpaint#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),W=new ri({props:{anchor:"diffusers.StableDiffusionModelEditingPipeline.__call__.example",$$slots:{default:[di]},$$scope:{ctx:le}}}),K=new ue({props:{name:"disable_vae_slicing",anchor:"diffusers.StableDiffusionModelEditingPipeline.disable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.19.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L156"}}),te=new ue({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 <code>source_prompt</code> 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 <code>False</code>, edits accumulate.`,name:"restart_params"}],source:"https://github.com/huggingface/diffusers/blob/v0.19.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L431"}}),ne=new ue({props:{name:"enable_vae_slicing",anchor:"diffusers.StableDiffusionModelEditingPipeline.enable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.19.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py#L148"}}),se=new St({}),ae=new ue({props:{name:"class diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput",anchor:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput",parameters:[{name:"images",val:": typing.Union[typing.List[PIL.Image.Image], numpy.ndarray]"},{name:"nsfw_content_detected",val:": typing.Optional[typing.List[bool]]"}],parametersDescription:[{anchor:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput.images",description:`<strong>images</strong> (<code>List[PIL.Image.Image]</code> or <code>np.ndarray</code>) &#x2014;
List of denoised PIL images of length <code>batch_size</code> or NumPy array of shape <code>(batch_size, height, width, num_channels)</code>.`,name:"images"},{anchor:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput.nsfw_content_detected",description:`<strong>nsfw_content_detected</strong> (<code>List[bool]</code>) &#x2014;
List indicating whether the corresponding generated image contains &#x201C;not-safe-for-work&#x201D; (nsfw) content or
<code>None</code> if safety checking could not be performed.`,name:"nsfw_content_detected"}],source:"https://github.com/huggingface/diffusers/blob/v0.19.2/src/diffusers/pipelines/stable_diffusion/__init__.py#L22"}}),{c(){c=o("meta"),E=f(),g=o("h1"),h=o("a"),b=o("span"),M(d.$$.fragment),v=f(),j=o("span"),N=r("Text-to-image model editing"),y=f(),S=o("p"),I=o("a"),qe=r("Editing Implicit Assumptions in Text-to-Image Diffusion Models"),Be=r(" is by Hadas Orgad, Bahjat Kawar, and Yonatan Belinkov. This pipeline enables editing diffusion model weights, such that its assumptions of a given concept are changed. The resulting change is expected to take effect in all prompt generations related to the edited concept."),De=f(),de=o("p"),ze=r("The abstract from the paper is:"),Te=f(),pe=o("p"),me=o("em"),Fe=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."),$e=f(),x=o("p"),Ve=r("You can find additional information about model editing on the "),F=o("a"),Qe=r("project page"),Xe=r(", "),V=o("a"),He=r("original codebase"),Ye=r(", and try it out in a "),Q=o("a"),Re=r("demo"),Ke=r("."),Pe=f(),M(O.$$.fragment),ke=f(),L=o("h2"),G=o("a"),ge=o("span"),M(X.$$.fragment),et=f(),he=o("span"),tt=r("StableDiffusionModelEditingPipeline"),Se=f(),_=o("div"),M(H.$$.fragment),it=f(),_e=o("p"),ot=r("Pipeline for text-to-image model editing."),nt=f(),Y=o("p"),st=r("This model inherits from "),ce=o("a"),at=r("DiffusionPipeline"),rt=r(`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),lt=f(),A=o("div"),M(R.$$.fragment),dt=f(),be=o("p"),pt=r("The call function to the pipeline for generation."),ct=f(),M(W.$$.fragment),ft=f(),U=o("div"),M(K.$$.fragment),ut=f(),ee=o("p"),mt=r("Disable sliced VAE decoding. If "),ve=o("code"),gt=r("enable_vae_slicing"),ht=r(` was previously enabled, this method will go back to
computing decoding in one step.`),_t=f(),Z=o("div"),M(te.$$.fragment),bt=f(),ie=o("p"),vt=r("Apply model editing via closed-form solution (see Eq. 5 in the TIME "),oe=o("a"),wt=r("paper"),yt=r(")."),Et=f(),q=o("div"),M(ne.$$.fragment),xt=f(),we=o("p"),Mt=r(`Enable sliced VAE decoding. 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.`),Ie=f(),C=o("h2"),B=o("a"),ye=o("span"),M(se.$$.fragment),Dt=f(),Ee=o("span"),Tt=r("StableDiffusionPipelineOutput"),Ae=f(),J=o("div"),M(ae.$$.fragment),$t=f(),xe=o("p"),Pt=r("Output class for Stable Diffusion pipelines."),this.h()},l(e){const p=ii('[data-svelte="svelte-1phssyn"]',document.head);c=n(p,"META",{name:!0,content:!0}),p.forEach(i),E=u(e),g=n(e,"H1",{class:!0});var re=s(g);h=n(re,"A",{id:!0,class:!0,href:!0});var Me=s(h);b=n(Me,"SPAN",{});var It=s(b);D(d.$$.fragment,It),It.forEach(i),Me.forEach(i),v=u(re),j=n(re,"SPAN",{});var At=s(j);N=l(At,"Text-to-image model editing"),At.forEach(i),re.forEach(i),y=u(e),S=n(e,"P",{});var kt=s(S);I=n(kt,"A",{href:!0,rel:!0});var jt=s(I);qe=l(jt,"Editing Implicit Assumptions in Text-to-Image Diffusion Models"),jt.forEach(i),Be=l(kt," is by Hadas Orgad, Bahjat Kawar, and Yonatan Belinkov. This pipeline enables editing diffusion model weights, such that its assumptions of a given concept are changed. The resulting change is expected to take effect in all prompt generations related to the edited concept."),kt.forEach(i),De=u(e),de=n(e,"P",{});var Nt=s(de);ze=l(Nt,"The abstract from the paper is:"),Nt.forEach(i),Te=u(e),pe=n(e,"P",{});var Lt=s(pe);me=n(Lt,"EM",{});var Ct=s(me);Fe=l(Ct,"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."),Ct.forEach(i),Lt.forEach(i),$e=u(e),x=n(e,"P",{});var z=s(x);Ve=l(z,"You can find additional information about model editing on the "),F=n(z,"A",{href:!0,rel:!0});var Jt=s(F);Qe=l(Jt,"project page"),Jt.forEach(i),Xe=l(z,", "),V=n(z,"A",{href:!0,rel:!0});var Ot=s(V);He=l(Ot,"original codebase"),Ot.forEach(i),Ye=l(z,", and try it out in a "),Q=n(z,"A",{href:!0,rel:!0});var Gt=s(Q);Re=l(Gt,"demo"),Gt.forEach(i),Ke=l(z,"."),z.forEach(i),Pe=u(e),D(O.$$.fragment,e),ke=u(e),L=n(e,"H2",{class:!0});var Ne=s(L);G=n(Ne,"A",{id:!0,class:!0,href:!0});var Wt=s(G);ge=n(Wt,"SPAN",{});var Ut=s(ge);D(X.$$.fragment,Ut),Ut.forEach(i),Wt.forEach(i),et=u(Ne),he=n(Ne,"SPAN",{});var Zt=s(he);tt=l(Zt,"StableDiffusionModelEditingPipeline"),Zt.forEach(i),Ne.forEach(i),Se=u(e),_=n(e,"DIV",{class:!0});var w=s(_);D(H.$$.fragment,w),it=u(w),_e=n(w,"P",{});var qt=s(_e);ot=l(qt,"Pipeline for text-to-image model editing."),qt.forEach(i),nt=u(w),Y=n(w,"P",{});var Le=s(Y);st=l(Le,"This model inherits from "),ce=n(Le,"A",{href:!0});var Bt=s(ce);at=l(Bt,"DiffusionPipeline"),Bt.forEach(i),rt=l(Le,`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Le.forEach(i),lt=u(w),A=n(w,"DIV",{class:!0});var fe=s(A);D(R.$$.fragment,fe),dt=u(fe),be=n(fe,"P",{});var zt=s(be);pt=l(zt,"The call function to the pipeline for generation."),zt.forEach(i),ct=u(fe),D(W.$$.fragment,fe),fe.forEach(i),ft=u(w),U=n(w,"DIV",{class:!0});var Ce=s(U);D(K.$$.fragment,Ce),ut=u(Ce),ee=n(Ce,"P",{});var Je=s(ee);mt=l(Je,"Disable sliced VAE decoding. If "),ve=n(Je,"CODE",{});var Ft=s(ve);gt=l(Ft,"enable_vae_slicing"),Ft.forEach(i),ht=l(Je,` was previously enabled, this method will go back to
computing decoding in one step.`),Je.forEach(i),Ce.forEach(i),_t=u(w),Z=n(w,"DIV",{class:!0});var Oe=s(Z);D(te.$$.fragment,Oe),bt=u(Oe),ie=n(Oe,"P",{});var Ge=s(ie);vt=l(Ge,"Apply model editing via closed-form solution (see Eq. 5 in the TIME "),oe=n(Ge,"A",{href:!0,rel:!0});var Vt=s(oe);wt=l(Vt,"paper"),Vt.forEach(i),yt=l(Ge,")."),Ge.forEach(i),Oe.forEach(i),Et=u(w),q=n(w,"DIV",{class:!0});var We=s(q);D(ne.$$.fragment,We),xt=u(We),we=n(We,"P",{});var Qt=s(we);Mt=l(Qt,`Enable sliced VAE decoding. 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.`),Qt.forEach(i),We.forEach(i),w.forEach(i),Ie=u(e),C=n(e,"H2",{class:!0});var Ue=s(C);B=n(Ue,"A",{id:!0,class:!0,href:!0});var Xt=s(B);ye=n(Xt,"SPAN",{});var Ht=s(ye);D(se.$$.fragment,Ht),Ht.forEach(i),Xt.forEach(i),Dt=u(Ue),Ee=n(Ue,"SPAN",{});var Yt=s(Ee);Tt=l(Yt,"StableDiffusionPipelineOutput"),Yt.forEach(i),Ue.forEach(i),Ae=u(e),J=n(e,"DIV",{class:!0});var Ze=s(J);D(ae.$$.fragment,Ze),$t=u(Ze),xe=n(Ze,"P",{});var Rt=s(xe);Pt=l(Rt,"Output class for Stable Diffusion pipelines."),Rt.forEach(i),Ze.forEach(i),this.h()},h(){a(c,"name","hf:doc:metadata"),a(c,"content",JSON.stringify(ci)),a(h,"id","texttoimage-model-editing"),a(h,"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"),a(h,"href","#texttoimage-model-editing"),a(g,"class","relative group"),a(I,"href","https://huggingface.co/papers/2303.08084"),a(I,"rel","nofollow"),a(F,"href","https://time-diffusion.github.io/"),a(F,"rel","nofollow"),a(V,"href","https://github.com/bahjat-kawar/time-diffusion"),a(V,"rel","nofollow"),a(Q,"href","https://huggingface.co/spaces/bahjat-kawar/time-diffusion"),a(Q,"rel","nofollow"),a(G,"id","diffusers.StableDiffusionModelEditingPipeline"),a(G,"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"),a(G,"href","#diffusers.StableDiffusionModelEditingPipeline"),a(L,"class","relative group"),a(ce,"href","/docs/diffusers/v0.19.2/en/api/pipelines/overview#diffusers.DiffusionPipeline"),a(A,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(oe,"href","https://arxiv.org/abs/2303.08084"),a(oe,"rel","nofollow"),a(Z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(B,"id","diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"),a(B,"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"),a(B,"href","#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"),a(C,"class","relative group"),a(J,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,p){t(document.head,c),m(e,E,p),m(e,g,p),t(g,h),t(h,b),T(d,b,null),t(g,v),t(g,j),t(j,N),m(e,y,p),m(e,S,p),t(S,I),t(I,qe),t(S,Be),m(e,De,p),m(e,de,p),t(de,ze),m(e,Te,p),m(e,pe,p),t(pe,me),t(me,Fe),m(e,$e,p),m(e,x,p),t(x,Ve),t(x,F),t(F,Qe),t(x,Xe),t(x,V),t(V,He),t(x,Ye),t(x,Q),t(Q,Re),t(x,Ke),m(e,Pe,p),T(O,e,p),m(e,ke,p),m(e,L,p),t(L,G),t(G,ge),T(X,ge,null),t(L,et),t(L,he),t(he,tt),m(e,Se,p),m(e,_,p),T(H,_,null),t(_,it),t(_,_e),t(_e,ot),t(_,nt),t(_,Y),t(Y,st),t(Y,ce),t(ce,at),t(Y,rt),t(_,lt),t(_,A),T(R,A,null),t(A,dt),t(A,be),t(be,pt),t(A,ct),T(W,A,null),t(_,ft),t(_,U),T(K,U,null),t(U,ut),t(U,ee),t(ee,mt),t(ee,ve),t(ve,gt),t(ee,ht),t(_,_t),t(_,Z),T(te,Z,null),t(Z,bt),t(Z,ie),t(ie,vt),t(ie,oe),t(oe,wt),t(ie,yt),t(_,Et),t(_,q),T(ne,q,null),t(q,xt),t(q,we),t(we,Mt),m(e,Ie,p),m(e,C,p),t(C,B),t(B,ye),T(se,ye,null),t(C,Dt),t(C,Ee),t(Ee,Tt),m(e,Ae,p),m(e,J,p),T(ae,J,null),t(J,$t),t(J,xe),t(xe,Pt),je=!0},p(e,[p]){const re={};p&2&&(re.$$scope={dirty:p,ctx:e}),O.$set(re);const Me={};p&2&&(Me.$$scope={dirty:p,ctx:e}),W.$set(Me)},i(e){je||($(d.$$.fragment,e),$(O.$$.fragment,e),$(X.$$.fragment,e),$(H.$$.fragment,e),$(R.$$.fragment,e),$(W.$$.fragment,e),$(K.$$.fragment,e),$(te.$$.fragment,e),$(ne.$$.fragment,e),$(se.$$.fragment,e),$(ae.$$.fragment,e),je=!0)},o(e){P(d.$$.fragment,e),P(O.$$.fragment,e),P(X.$$.fragment,e),P(H.$$.fragment,e),P(R.$$.fragment,e),P(W.$$.fragment,e),P(K.$$.fragment,e),P(te.$$.fragment,e),P(ne.$$.fragment,e),P(se.$$.fragment,e),P(ae.$$.fragment,e),je=!1},d(e){i(c),e&&i(E),e&&i(g),k(d),e&&i(y),e&&i(S),e&&i(De),e&&i(de),e&&i(Te),e&&i(pe),e&&i($e),e&&i(x),e&&i(Pe),k(O,e),e&&i(ke),e&&i(L),k(X),e&&i(Se),e&&i(_),k(H),k(R),k(W),k(K),k(te),k(ne),e&&i(Ie),e&&i(C),k(se),e&&i(Ae),e&&i(J),k(ae)}}}const ci={local:"texttoimage-model-editing",sections:[{local:"diffusers.StableDiffusionModelEditingPipeline",title:"StableDiffusionModelEditingPipeline"},{local:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput",title:"StableDiffusionPipelineOutput"}],title:"Text-to-image model editing"};function fi(le){return oi(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class vi extends Kt{constructor(c){super();ei(this,c,fi,pi,ti,{})}}export{vi as default,ci as metadata};
