import{S as Kn,i as Jn,s as Qn,e as s,k as d,w as z,t as a,M as Xn,c as o,d as t,m as f,a as i,x as F,h as r,b as c,G as n,g as p,y as W,L as Yn,q as B,o as V,B as H,v as Zn}from"../../../chunks/vendor-hf-doc-builder.js";import{D as Cn}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as et}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Pn}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function nt(xn){let h,de,g,y,Z,k,Me,ee,Le,fe,_,b,ne,I,Ge,te,Oe,ue,w,Ne,$,Ue,ze,me,R,Fe,he,K,se,We,ge,E,oe,Be,Ve,_e,D,q,He,J,Re,Ke,Je,j,Qe,Q,Xe,Ye,ve,S,ie,Ze,en,ye,T,nn,X,tn,be,A,we,v,C,ae,M,sn,re,on,De,u,L,an,le,rn,ln,G,cn,Y,pn,dn,fn,P,O,un,ce,mn,hn,x,N,gn,U,_n,pe,vn,yn,Ce;return k=new Pn({}),I=new Pn({}),A=new et({props:{code:`import requests
import torch
from PIL import Image
from io import BytesIO

from diffusers import CycleDiffusionPipeline, DDIMScheduler

# load the pipeline
# make sure you're logged in with \`huggingface-cli login\`
model_id_or_path = "CompVis/stable-diffusion-v1-4"
scheduler = DDIMScheduler.from_pretrained(model_id_or_path, subfolder="scheduler")
pipe = CycleDiffusionPipeline.from_pretrained(model_id_or_path, scheduler=scheduler).to("cuda")

# let's download an initial image
url = "https://raw.githubusercontent.com/ChenWu98/cycle-diffusion/main/data/dalle2/An%20astronaut%20riding%20a%20horse.png"
response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((512, 512))
init_image.save("horse.png")

# let's specify a prompt
source_prompt = "An astronaut riding a horse"
prompt = "An astronaut riding an elephant"

# call the pipeline
image = pipe(
    prompt=prompt,
    source_prompt=source_prompt,
    image=init_image,
    num_inference_steps=100,
    eta=0.1,
    strength=0.8,
    guidance_scale=2,
    source_guidance_scale=1,
).images[0]

image.save("horse_to_elephant.png")

# let's try another example
# See more samples at the original repo: https://github.com/ChenWu98/cycle-diffusion
url = "https://raw.githubusercontent.com/ChenWu98/cycle-diffusion/main/data/dalle2/A%20black%20colored%20car.png"
response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((512, 512))
init_image.save("black.png")

source_prompt = "A black colored car"
prompt = "A blue colored car"

# call the pipeline
torch.manual_seed(0)
image = pipe(
    prompt=prompt,
    source_prompt=source_prompt,
    image=init_image,
    num_inference_steps=100,
    eta=0.1,
    strength=0.85,
    guidance_scale=3,
    source_guidance_scale=1,
).images[0]

image.save("black_to_blue.png")`,highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CycleDiffusionPipeline, DDIMScheduler

<span class="hljs-comment"># load the pipeline</span>
<span class="hljs-comment"># make sure you&#x27;re logged in with \`huggingface-cli login\`</span>
model_id_or_path = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
scheduler = DDIMScheduler.from_pretrained(model_id_or_path, subfolder=<span class="hljs-string">&quot;scheduler&quot;</span>)
pipe = CycleDiffusionPipeline.from_pretrained(model_id_or_path, scheduler=scheduler).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-comment"># let&#x27;s download an initial image</span>
url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/ChenWu98/cycle-diffusion/main/data/dalle2/An%20astronaut%20riding%20a%20horse.png&quot;</span>
response = requests.get(url)
init_image = Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)
init_image = init_image.resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
init_image.save(<span class="hljs-string">&quot;horse.png&quot;</span>)

<span class="hljs-comment"># let&#x27;s specify a prompt</span>
source_prompt = <span class="hljs-string">&quot;An astronaut riding a horse&quot;</span>
prompt = <span class="hljs-string">&quot;An astronaut riding an elephant&quot;</span>

<span class="hljs-comment"># call the pipeline</span>
image = pipe(
    prompt=prompt,
    source_prompt=source_prompt,
    image=init_image,
    num_inference_steps=<span class="hljs-number">100</span>,
    eta=<span class="hljs-number">0.1</span>,
    strength=<span class="hljs-number">0.8</span>,
    guidance_scale=<span class="hljs-number">2</span>,
    source_guidance_scale=<span class="hljs-number">1</span>,
).images[<span class="hljs-number">0</span>]

image.save(<span class="hljs-string">&quot;horse_to_elephant.png&quot;</span>)

<span class="hljs-comment"># let&#x27;s try another example</span>
<span class="hljs-comment"># See more samples at the original repo: https://github.com/ChenWu98/cycle-diffusion</span>
url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/ChenWu98/cycle-diffusion/main/data/dalle2/A%20black%20colored%20car.png&quot;</span>
response = requests.get(url)
init_image = Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)
init_image = init_image.resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
init_image.save(<span class="hljs-string">&quot;black.png&quot;</span>)

source_prompt = <span class="hljs-string">&quot;A black colored car&quot;</span>
prompt = <span class="hljs-string">&quot;A blue colored car&quot;</span>

<span class="hljs-comment"># call the pipeline</span>
torch.manual_seed(<span class="hljs-number">0</span>)
image = pipe(
    prompt=prompt,
    source_prompt=source_prompt,
    image=init_image,
    num_inference_steps=<span class="hljs-number">100</span>,
    eta=<span class="hljs-number">0.1</span>,
    strength=<span class="hljs-number">0.85</span>,
    guidance_scale=<span class="hljs-number">3</span>,
    source_guidance_scale=<span class="hljs-number">1</span>,
).images[<span class="hljs-number">0</span>]

image.save(<span class="hljs-string">&quot;black_to_blue.png&quot;</span>)`}}),M=new Pn({}),L=new Cn({props:{name:"class diffusers.CycleDiffusionPipeline",anchor:"diffusers.CycleDiffusionPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": DDIMScheduler"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"feature_extractor",val:": CLIPFeatureExtractor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.CycleDiffusionPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.12.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.CycleDiffusionPipeline.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.CycleDiffusionPipeline.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.CycleDiffusionPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/v0.12.0/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.CycleDiffusionPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.12.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. Can be one of
<a href="/docs/diffusers/v0.12.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.12.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.12.0/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.CycleDiffusionPipeline.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/CompVis/stable-diffusion-v1-4" rel="nofollow">model card</a> for details.`,name:"safety_checker"},{anchor:"diffusers.CycleDiffusionPipeline.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"}],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py#L121"}}),O=new Cn({props:{name:"__call__",anchor:"diffusers.CycleDiffusionPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]]"},{name:"source_prompt",val:": typing.Union[str, typing.List[str]]"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image] = None"},{name:"strength",val:": float = 0.8"},{name:"num_inference_steps",val:": typing.Optional[int] = 50"},{name:"guidance_scale",val:": typing.Optional[float] = 7.5"},{name:"source_guidance_scale",val:": typing.Optional[float] = 1"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"eta",val:": typing.Optional[float] = 0.1"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"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:": typing.Optional[int] = 1"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.CycleDiffusionPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>) &#x2014;
The prompt or prompts to guide the image generation.`,name:"prompt"},{anchor:"diffusers.CycleDiffusionPipeline.__call__.image",description:`<strong>image</strong> (<code>torch.FloatTensor</code> or <code>PIL.Image.Image</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch, that will be used as the starting point for the
process.`,name:"image"},{anchor:"diffusers.CycleDiffusionPipeline.__call__.strength",description:`<strong>strength</strong> (<code>float</code>, <em>optional</em>, defaults to 0.8) &#x2014;
Conceptually, indicates how much to transform the reference <code>image</code>. Must be between 0 and 1. <code>image</code>
will be used as a starting point, adding more noise to it the larger the <code>strength</code>. The number of
denoising steps depends on the amount of noise initially added. When <code>strength</code> is 1, added noise will
be maximum and the denoising process will run for the full number of iterations specified in
<code>num_inference_steps</code>. A value of 1, therefore, essentially ignores <code>image</code>.`,name:"strength"},{anchor:"diffusers.CycleDiffusionPipeline.__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. This parameter will be modulated by <code>strength</code>.`,name:"num_inference_steps"},{anchor:"diffusers.CycleDiffusionPipeline.__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.CycleDiffusionPipeline.__call__.source_guidance_scale",description:`<strong>source_guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 1) &#x2014;
Guidance scale for the source prompt. This is useful to control the amount of influence the source
prompt for encoding.`,name:"source_guidance_scale"},{anchor:"diffusers.CycleDiffusionPipeline.__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.CycleDiffusionPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#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.12.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.CycleDiffusionPipeline.__call__.generator",description:`<strong>generator</strong> (<code>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.CycleDiffusionPipeline.__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.CycleDiffusionPipeline.__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.CycleDiffusionPipeline.__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.CycleDiffusionPipeline.__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.12.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.CycleDiffusionPipeline.__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.CycleDiffusionPipeline.__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"}],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py#L543",returnDescription:`
<p><a
  href="/docs/diffusers/v0.12.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.12.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),N=new Cn({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.CycleDiffusionPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py#L225"}}),{c(){h=s("meta"),de=d(),g=s("h1"),y=s("a"),Z=s("span"),z(k.$$.fragment),Me=d(),ee=s("span"),Le=a("Cycle Diffusion"),fe=d(),_=s("h2"),b=s("a"),ne=s("span"),z(I.$$.fragment),Ge=d(),te=s("span"),Oe=a("Overview"),ue=d(),w=s("p"),Ne=a("Cycle Diffusion is a Text-Guided Image-to-Image Generation model proposed in "),$=s("a"),Ue=a("Unifying Diffusion Models\u2019 Latent Space, with Applications to CycleDiffusion and Guidance"),ze=a(" by Chen Henry Wu, Fernando De la Torre."),me=d(),R=s("p"),Fe=a("The abstract of the paper is the following:"),he=d(),K=s("p"),se=s("em"),We=a("Diffusion models have achieved unprecedented performance in generative modeling. The commonly-adopted formulation of the latent code of diffusion models is a sequence of gradually denoised samples, as opposed to the simpler (e.g., Gaussian) latent space of GANs, VAEs, and normalizing flows. This paper provides an alternative, Gaussian formulation of the latent space of various diffusion models, as well as an invertible DPM-Encoder that maps images into the latent space. While our formulation is purely based on the definition of diffusion models, we demonstrate several intriguing consequences. (1) Empirically, we observe that a common latent space emerges from two diffusion models trained independently on related domains. In light of this finding, we propose CycleDiffusion, which uses DPM-Encoder for unpaired image-to-image translation. Furthermore, applying CycleDiffusion to text-to-image diffusion models, we show that large-scale text-to-image diffusion models can be used as zero-shot image-to-image editors. (2) One can guide pre-trained diffusion models and GANs by controlling the latent codes in a unified, plug-and-play formulation based on energy-based models. Using the CLIP model and a face recognition model as guidance, we demonstrate that diffusion models have better coverage of low-density sub-populations and individuals than GANs."),ge=d(),E=s("p"),oe=s("em"),Be=a("Tips"),Ve=a(":"),_e=d(),D=s("ul"),q=s("li"),He=a("The Cycle Diffusion pipeline is fully compatible with any "),J=s("a"),Re=a("Stable Diffusion"),Ke=a(" checkpoints"),Je=d(),j=s("li"),Qe=a("Currently Cycle Diffusion only works with the "),Q=s("a"),Xe=a("DDIMScheduler"),Ye=a("."),ve=d(),S=s("p"),ie=s("em"),Ze=a("Example"),en=a(":"),ye=d(),T=s("p"),nn=a("In the following we should how to best use the "),X=s("a"),tn=a("CycleDiffusionPipeline"),be=d(),z(A.$$.fragment),we=d(),v=s("h2"),C=s("a"),ae=s("span"),z(M.$$.fragment),sn=d(),re=s("span"),on=a("CycleDiffusionPipeline"),De=d(),u=s("div"),z(L.$$.fragment),an=d(),le=s("p"),rn=a("Pipeline for text-guided image to image generation using Stable Diffusion."),ln=d(),G=s("p"),cn=a("This model inherits from "),Y=s("a"),pn=a("DiffusionPipeline"),dn=a(`. 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.)`),fn=d(),P=s("div"),z(O.$$.fragment),un=d(),ce=s("p"),mn=a("Function invoked when calling the pipeline for generation."),hn=d(),x=s("div"),z(N.$$.fragment),gn=d(),U=s("p"),_n=a(`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
`),pe=s("code"),vn=a("torch.device('meta') and loaded to GPU only when their specific submodule has its "),yn=a("forward` method called."),this.h()},l(e){const l=Xn('[data-svelte="svelte-1phssyn"]',document.head);h=o(l,"META",{name:!0,content:!0}),l.forEach(t),de=f(e),g=o(e,"H1",{class:!0});var Pe=i(g);y=o(Pe,"A",{id:!0,class:!0,href:!0});var kn=i(y);Z=o(kn,"SPAN",{});var In=i(Z);F(k.$$.fragment,In),In.forEach(t),kn.forEach(t),Me=f(Pe),ee=o(Pe,"SPAN",{});var $n=i(ee);Le=r($n,"Cycle Diffusion"),$n.forEach(t),Pe.forEach(t),fe=f(e),_=o(e,"H2",{class:!0});var xe=i(_);b=o(xe,"A",{id:!0,class:!0,href:!0});var En=i(b);ne=o(En,"SPAN",{});var qn=i(ne);F(I.$$.fragment,qn),qn.forEach(t),En.forEach(t),Ge=f(xe),te=o(xe,"SPAN",{});var jn=i(te);Oe=r(jn,"Overview"),jn.forEach(t),xe.forEach(t),ue=f(e),w=o(e,"P",{});var ke=i(w);Ne=r(ke,"Cycle Diffusion is a Text-Guided Image-to-Image Generation model proposed in "),$=o(ke,"A",{href:!0,rel:!0});var Sn=i($);Ue=r(Sn,"Unifying Diffusion Models\u2019 Latent Space, with Applications to CycleDiffusion and Guidance"),Sn.forEach(t),ze=r(ke," by Chen Henry Wu, Fernando De la Torre."),ke.forEach(t),me=f(e),R=o(e,"P",{});var Tn=i(R);Fe=r(Tn,"The abstract of the paper is the following:"),Tn.forEach(t),he=f(e),K=o(e,"P",{});var An=i(K);se=o(An,"EM",{});var Mn=i(se);We=r(Mn,"Diffusion models have achieved unprecedented performance in generative modeling. The commonly-adopted formulation of the latent code of diffusion models is a sequence of gradually denoised samples, as opposed to the simpler (e.g., Gaussian) latent space of GANs, VAEs, and normalizing flows. This paper provides an alternative, Gaussian formulation of the latent space of various diffusion models, as well as an invertible DPM-Encoder that maps images into the latent space. While our formulation is purely based on the definition of diffusion models, we demonstrate several intriguing consequences. (1) Empirically, we observe that a common latent space emerges from two diffusion models trained independently on related domains. In light of this finding, we propose CycleDiffusion, which uses DPM-Encoder for unpaired image-to-image translation. Furthermore, applying CycleDiffusion to text-to-image diffusion models, we show that large-scale text-to-image diffusion models can be used as zero-shot image-to-image editors. (2) One can guide pre-trained diffusion models and GANs by controlling the latent codes in a unified, plug-and-play formulation based on energy-based models. Using the CLIP model and a face recognition model as guidance, we demonstrate that diffusion models have better coverage of low-density sub-populations and individuals than GANs."),Mn.forEach(t),An.forEach(t),ge=f(e),E=o(e,"P",{});var bn=i(E);oe=o(bn,"EM",{});var Ln=i(oe);Be=r(Ln,"Tips"),Ln.forEach(t),Ve=r(bn,":"),bn.forEach(t),_e=f(e),D=o(e,"UL",{});var Ie=i(D);q=o(Ie,"LI",{});var $e=i(q);He=r($e,"The Cycle Diffusion pipeline is fully compatible with any "),J=o($e,"A",{href:!0});var Gn=i(J);Re=r(Gn,"Stable Diffusion"),Gn.forEach(t),Ke=r($e," checkpoints"),$e.forEach(t),Je=f(Ie),j=o(Ie,"LI",{});var Ee=i(j);Qe=r(Ee,"Currently Cycle Diffusion only works with the "),Q=o(Ee,"A",{href:!0});var On=i(Q);Xe=r(On,"DDIMScheduler"),On.forEach(t),Ye=r(Ee,"."),Ee.forEach(t),Ie.forEach(t),ve=f(e),S=o(e,"P",{});var wn=i(S);ie=o(wn,"EM",{});var Nn=i(ie);Ze=r(Nn,"Example"),Nn.forEach(t),en=r(wn,":"),wn.forEach(t),ye=f(e),T=o(e,"P",{});var Dn=i(T);nn=r(Dn,"In the following we should how to best use the "),X=o(Dn,"A",{href:!0});var Un=i(X);tn=r(Un,"CycleDiffusionPipeline"),Un.forEach(t),Dn.forEach(t),be=f(e),F(A.$$.fragment,e),we=f(e),v=o(e,"H2",{class:!0});var qe=i(v);C=o(qe,"A",{id:!0,class:!0,href:!0});var zn=i(C);ae=o(zn,"SPAN",{});var Fn=i(ae);F(M.$$.fragment,Fn),Fn.forEach(t),zn.forEach(t),sn=f(qe),re=o(qe,"SPAN",{});var Wn=i(re);on=r(Wn,"CycleDiffusionPipeline"),Wn.forEach(t),qe.forEach(t),De=f(e),u=o(e,"DIV",{class:!0});var m=i(u);F(L.$$.fragment,m),an=f(m),le=o(m,"P",{});var Bn=i(le);rn=r(Bn,"Pipeline for text-guided image to image generation using Stable Diffusion."),Bn.forEach(t),ln=f(m),G=o(m,"P",{});var je=i(G);cn=r(je,"This model inherits from "),Y=o(je,"A",{href:!0});var Vn=i(Y);pn=r(Vn,"DiffusionPipeline"),Vn.forEach(t),dn=r(je,`. 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.)`),je.forEach(t),fn=f(m),P=o(m,"DIV",{class:!0});var Se=i(P);F(O.$$.fragment,Se),un=f(Se),ce=o(Se,"P",{});var Hn=i(ce);mn=r(Hn,"Function invoked when calling the pipeline for generation."),Hn.forEach(t),Se.forEach(t),hn=f(m),x=o(m,"DIV",{class:!0});var Te=i(x);F(N.$$.fragment,Te),gn=f(Te),U=o(Te,"P",{});var Ae=i(U);_n=r(Ae,`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
`),pe=o(Ae,"CODE",{});var Rn=i(pe);vn=r(Rn,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),Rn.forEach(t),yn=r(Ae,"forward` method called."),Ae.forEach(t),Te.forEach(t),m.forEach(t),this.h()},h(){c(h,"name","hf:doc:metadata"),c(h,"content",JSON.stringify(tt)),c(y,"id","cycle-diffusion"),c(y,"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"),c(y,"href","#cycle-diffusion"),c(g,"class","relative group"),c(b,"id","overview"),c(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"),c(b,"href","#overview"),c(_,"class","relative group"),c($,"href","https://arxiv.org/abs/2210.05559"),c($,"rel","nofollow"),c(J,"href","./stable_diffusion"),c(Q,"href","/docs/diffusers/v0.12.0/en/api/schedulers/ddim#diffusers.DDIMScheduler"),c(X,"href","/docs/diffusers/v0.12.0/en/api/pipelines/cycle_diffusion#diffusers.CycleDiffusionPipeline"),c(C,"id","diffusers.CycleDiffusionPipeline"),c(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"),c(C,"href","#diffusers.CycleDiffusionPipeline"),c(v,"class","relative group"),c(Y,"href","/docs/diffusers/v0.12.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),c(P,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(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(e,l){n(document.head,h),p(e,de,l),p(e,g,l),n(g,y),n(y,Z),W(k,Z,null),n(g,Me),n(g,ee),n(ee,Le),p(e,fe,l),p(e,_,l),n(_,b),n(b,ne),W(I,ne,null),n(_,Ge),n(_,te),n(te,Oe),p(e,ue,l),p(e,w,l),n(w,Ne),n(w,$),n($,Ue),n(w,ze),p(e,me,l),p(e,R,l),n(R,Fe),p(e,he,l),p(e,K,l),n(K,se),n(se,We),p(e,ge,l),p(e,E,l),n(E,oe),n(oe,Be),n(E,Ve),p(e,_e,l),p(e,D,l),n(D,q),n(q,He),n(q,J),n(J,Re),n(q,Ke),n(D,Je),n(D,j),n(j,Qe),n(j,Q),n(Q,Xe),n(j,Ye),p(e,ve,l),p(e,S,l),n(S,ie),n(ie,Ze),n(S,en),p(e,ye,l),p(e,T,l),n(T,nn),n(T,X),n(X,tn),p(e,be,l),W(A,e,l),p(e,we,l),p(e,v,l),n(v,C),n(C,ae),W(M,ae,null),n(v,sn),n(v,re),n(re,on),p(e,De,l),p(e,u,l),W(L,u,null),n(u,an),n(u,le),n(le,rn),n(u,ln),n(u,G),n(G,cn),n(G,Y),n(Y,pn),n(G,dn),n(u,fn),n(u,P),W(O,P,null),n(P,un),n(P,ce),n(ce,mn),n(u,hn),n(u,x),W(N,x,null),n(x,gn),n(x,U),n(U,_n),n(U,pe),n(pe,vn),n(U,yn),Ce=!0},p:Yn,i(e){Ce||(B(k.$$.fragment,e),B(I.$$.fragment,e),B(A.$$.fragment,e),B(M.$$.fragment,e),B(L.$$.fragment,e),B(O.$$.fragment,e),B(N.$$.fragment,e),Ce=!0)},o(e){V(k.$$.fragment,e),V(I.$$.fragment,e),V(A.$$.fragment,e),V(M.$$.fragment,e),V(L.$$.fragment,e),V(O.$$.fragment,e),V(N.$$.fragment,e),Ce=!1},d(e){t(h),e&&t(de),e&&t(g),H(k),e&&t(fe),e&&t(_),H(I),e&&t(ue),e&&t(w),e&&t(me),e&&t(R),e&&t(he),e&&t(K),e&&t(ge),e&&t(E),e&&t(_e),e&&t(D),e&&t(ve),e&&t(S),e&&t(ye),e&&t(T),e&&t(be),H(A,e),e&&t(we),e&&t(v),H(M),e&&t(De),e&&t(u),H(L),H(O),H(N)}}}const tt={local:"cycle-diffusion",sections:[{local:"overview",title:"Overview"},{local:"diffusers.CycleDiffusionPipeline",title:"CycleDiffusionPipeline"}],title:"Cycle Diffusion"};function st(xn){return Zn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class lt extends Kn{constructor(h){super();Jn(this,h,st,nt,Qn,{})}}export{lt as default,tt as metadata};
