import{S as vt,i as Ct,s as Ut,e as o,k as c,w as E,t as i,M as Tt,c as s,d as t,m as d,a,x as P,h as l,b as p,G as n,g as f,y as Z,L as Jt,q as G,o as x,B as k,v as jt}from"../../../chunks/vendor-hf-doc-builder.js";import{D as Qe}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as It}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Xn}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function Dt(zn){let y,we,_,v,se,W,Re,ae,Xe,ve,b,C,ie,B,ze,le,Ye,Ce,U,qe,S,He,Oe,Ue,H,Ke,Te,O,re,en,Je,N,ce,nn,tn,je,T,V,on,K,sn,an,ln,A,rn,ee,cn,dn,Ie,$,de,pn,fn,De,L,un,ne,mn,Ee,F,Pe,M,J,pe,Q,hn,fe,gn,Ze,u,R,yn,ue,_n,bn,X,Mn,te,wn,vn,Cn,j,z,Un,me,Tn,Jn,I,Y,jn,m,In,he,Dn,En,ge,Pn,Zn,ye,Gn,xn,_e,kn,Wn,Bn,D,q,Sn,w,Nn,be,Vn,An,Me,$n,Ln,Ge;return W=new Xn({}),B=new Xn({}),F=new It({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUwQWZyb20lMjBpbyUyMGltcG9ydCUyMEJ5dGVzSU8lMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ3ljbGVEaWZmdXNpb25QaXBlbGluZSUyQyUyMERESU1TY2hlZHVsZXIlMEElMEElMjMlMjBsb2FkJTIwdGhlJTIwcGlwZWxpbmUlMEElMjMlMjBtYWtlJTIwc3VyZSUyMHlvdSdyZSUyMGxvZ2dlZCUyMGluJTIwd2l0aCUyMCU2MGh1Z2dpbmdmYWNlLWNsaSUyMGxvZ2luJTYwJTBBbW9kZWxfaWRfb3JfcGF0aCUyMCUzRCUyMCUyMkNvbXBWaXMlMkZzdG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h1cmwpJTBBaW5pdF9pbWFnZSUyMCUzRCUyMEltYWdlLm9wZW4oQnl0ZXNJTyhyZXNwb25zZS5jb250ZW50KSkuY29udmVydCglMjJSR0IlMjIpJTBBaW5pdF9pbWFnZSUyMCUzRCUyMGluaXRfaW1hZ2UucmVzaXplKCg1MTIlMkMlMjA1MTIpKSUwQWluaXRfaW1hZ2Uuc2F2ZSglMjJibGFjay5wbmclMjIpJTBBJTBBc291cmNlX3Byb21wdCUyMCUzRCUyMCUyMkElMjBibGFjayUyMGNvbG9yZWQlMjBjYXIlMjIlMEFwcm9tcHQlMjAlM0QlMjAlMjJBJTIwYmx1ZSUyMGNvbG9yZWQlMjBjYXIlMjIlMEElMEElMjMlMjBjYWxsJTIwdGhlJTIwcGlwZWxpbmUlMEF0b3JjaC5tYW51YWxfc2VlZCgwKSUwQWltYWdlJTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlM0Rwcm9tcHQlMkMlMEElMjAlMjAlMjAlMjBzb3VyY2VfcHJvbXB0JTNEc291cmNlX3Byb21wdCUyQyUwQSUyMCUyMCUyMCUyMGltYWdlJTNEaW5pdF9pbWFnZSUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QxMDAlMkMlMEElMjAlMjAlMjAlMjBldGElM0QwLjElMkMlMEElMjAlMjAlMjAlMjBzdHJlbmd0aCUzRDAuODUlMkMlMEElMjAlMjAlMjAlMjBndWlkYW5jZV9zY2FsZSUzRDMlMkMlMEElMjAlMjAlMjAlMjBzb3VyY2VfZ3VpZGFuY2Vfc2NhbGUlM0QxJTJDJTBBKS5pbWFnZXMlNUIwJTVEJTBBJTBBaW1hZ2Uuc2F2ZSglMjJibGFja190b19ibHVlLnBuZyUyMik=",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>)`}}),Q=new Xn({}),R=new Qe({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:": CLIPImageProcessor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.CycleDiffusionPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.17.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.17.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.17.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.17.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.17.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.17.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>CLIPImageProcessor</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.17.0/src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py#L129"}}),z=new Qe({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, numpy.ndarray, typing.List[torch.FloatTensor], typing.List[PIL.Image.Image], typing.List[numpy.ndarray]] = 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:": int = 1"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"}],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> <code>np.ndarray</code>, <code>PIL.Image.Image</code>, <code>List[torch.FloatTensor]</code>, <code>List[PIL.Image.Image]</code>, or <code>List[np.ndarray]</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch, that will be used as the starting point for the
process. Can also accpet image latents as <code>image</code>, if passing latents directly, it will not be encoded
again.`,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.17.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.17.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"},{anchor:"diffusers.CycleDiffusionPipeline.__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.0/src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py#L615",returnDescription:`
<p><a
  href="/docs/diffusers/v0.17.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.17.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),Y=new Qe({props:{name:"enable_model_cpu_offload",anchor:"diffusers.CycleDiffusionPipeline.enable_model_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.17.0/src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py#L261"}}),q=new Qe({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.17.0/src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py#L235"}}),{c(){y=o("meta"),we=c(),_=o("h1"),v=o("a"),se=o("span"),E(W.$$.fragment),Re=c(),ae=o("span"),Xe=i("Cycle Diffusion"),ve=c(),b=o("h2"),C=o("a"),ie=o("span"),E(B.$$.fragment),ze=c(),le=o("span"),Ye=i("Overview"),Ce=c(),U=o("p"),qe=i("Cycle Diffusion is a Text-Guided Image-to-Image Generation model proposed in "),S=o("a"),He=i("Unifying Diffusion Models\u2019 Latent Space, with Applications to CycleDiffusion and Guidance"),Oe=i(" by Chen Henry Wu, Fernando De la Torre."),Ue=c(),H=o("p"),Ke=i("The abstract of the paper is the following:"),Te=c(),O=o("p"),re=o("em"),en=i("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."),Je=c(),N=o("p"),ce=o("em"),nn=i("Tips"),tn=i(":"),je=c(),T=o("ul"),V=o("li"),on=i("The Cycle Diffusion pipeline is fully compatible with any "),K=o("a"),sn=i("Stable Diffusion"),an=i(" checkpoints"),ln=c(),A=o("li"),rn=i("Currently Cycle Diffusion only works with the "),ee=o("a"),cn=i("DDIMScheduler"),dn=i("."),Ie=c(),$=o("p"),de=o("em"),pn=i("Example"),fn=i(":"),De=c(),L=o("p"),un=i("In the following we should how to best use the "),ne=o("a"),mn=i("CycleDiffusionPipeline"),Ee=c(),E(F.$$.fragment),Pe=c(),M=o("h2"),J=o("a"),pe=o("span"),E(Q.$$.fragment),hn=c(),fe=o("span"),gn=i("CycleDiffusionPipeline"),Ze=c(),u=o("div"),E(R.$$.fragment),yn=c(),ue=o("p"),_n=i("Pipeline for text-guided image to image generation using Stable Diffusion."),bn=c(),X=o("p"),Mn=i("This model inherits from "),te=o("a"),wn=i("DiffusionPipeline"),vn=i(`. 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.)`),Cn=c(),j=o("div"),E(z.$$.fragment),Un=c(),me=o("p"),Tn=i("Function invoked when calling the pipeline for generation."),Jn=c(),I=o("div"),E(Y.$$.fragment),jn=c(),m=o("p"),In=i(`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),he=o("code"),Dn=i("enable_sequential_cpu_offload"),En=i(", this method moves one whole model at a time to the GPU when its "),ge=o("code"),Pn=i("forward"),Zn=i(`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),ye=o("code"),Gn=i("enable_sequential_cpu_offload"),xn=i(", but performance is much better due to the iterative execution of the "),_e=o("code"),kn=i("unet"),Wn=i("."),Bn=c(),D=o("div"),E(q.$$.fragment),Sn=c(),w=o("p"),Nn=i(`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
`),be=o("code"),Vn=i("torch.device('meta') and loaded to GPU only when their specific submodule has its "),An=i("forward"),Me=o("code"),$n=i("method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Ln=i("enable_model_cpu_offload`, but performance is lower."),this.h()},l(e){const r=Tt('[data-svelte="svelte-1phssyn"]',document.head);y=s(r,"META",{name:!0,content:!0}),r.forEach(t),we=d(e),_=s(e,"H1",{class:!0});var xe=a(_);v=s(xe,"A",{id:!0,class:!0,href:!0});var Yn=a(v);se=s(Yn,"SPAN",{});var qn=a(se);P(W.$$.fragment,qn),qn.forEach(t),Yn.forEach(t),Re=d(xe),ae=s(xe,"SPAN",{});var Hn=a(ae);Xe=l(Hn,"Cycle Diffusion"),Hn.forEach(t),xe.forEach(t),ve=d(e),b=s(e,"H2",{class:!0});var ke=a(b);C=s(ke,"A",{id:!0,class:!0,href:!0});var On=a(C);ie=s(On,"SPAN",{});var Kn=a(ie);P(B.$$.fragment,Kn),Kn.forEach(t),On.forEach(t),ze=d(ke),le=s(ke,"SPAN",{});var et=a(le);Ye=l(et,"Overview"),et.forEach(t),ke.forEach(t),Ce=d(e),U=s(e,"P",{});var We=a(U);qe=l(We,"Cycle Diffusion is a Text-Guided Image-to-Image Generation model proposed in "),S=s(We,"A",{href:!0,rel:!0});var nt=a(S);He=l(nt,"Unifying Diffusion Models\u2019 Latent Space, with Applications to CycleDiffusion and Guidance"),nt.forEach(t),Oe=l(We," by Chen Henry Wu, Fernando De la Torre."),We.forEach(t),Ue=d(e),H=s(e,"P",{});var tt=a(H);Ke=l(tt,"The abstract of the paper is the following:"),tt.forEach(t),Te=d(e),O=s(e,"P",{});var ot=a(O);re=s(ot,"EM",{});var st=a(re);en=l(st,"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."),st.forEach(t),ot.forEach(t),Je=d(e),N=s(e,"P",{});var Fn=a(N);ce=s(Fn,"EM",{});var at=a(ce);nn=l(at,"Tips"),at.forEach(t),tn=l(Fn,":"),Fn.forEach(t),je=d(e),T=s(e,"UL",{});var Be=a(T);V=s(Be,"LI",{});var Se=a(V);on=l(Se,"The Cycle Diffusion pipeline is fully compatible with any "),K=s(Se,"A",{href:!0});var it=a(K);sn=l(it,"Stable Diffusion"),it.forEach(t),an=l(Se," checkpoints"),Se.forEach(t),ln=d(Be),A=s(Be,"LI",{});var Ne=a(A);rn=l(Ne,"Currently Cycle Diffusion only works with the "),ee=s(Ne,"A",{href:!0});var lt=a(ee);cn=l(lt,"DDIMScheduler"),lt.forEach(t),dn=l(Ne,"."),Ne.forEach(t),Be.forEach(t),Ie=d(e),$=s(e,"P",{});var Qn=a($);de=s(Qn,"EM",{});var rt=a(de);pn=l(rt,"Example"),rt.forEach(t),fn=l(Qn,":"),Qn.forEach(t),De=d(e),L=s(e,"P",{});var Rn=a(L);un=l(Rn,"In the following we should how to best use the "),ne=s(Rn,"A",{href:!0});var ct=a(ne);mn=l(ct,"CycleDiffusionPipeline"),ct.forEach(t),Rn.forEach(t),Ee=d(e),P(F.$$.fragment,e),Pe=d(e),M=s(e,"H2",{class:!0});var Ve=a(M);J=s(Ve,"A",{id:!0,class:!0,href:!0});var dt=a(J);pe=s(dt,"SPAN",{});var pt=a(pe);P(Q.$$.fragment,pt),pt.forEach(t),dt.forEach(t),hn=d(Ve),fe=s(Ve,"SPAN",{});var ft=a(fe);gn=l(ft,"CycleDiffusionPipeline"),ft.forEach(t),Ve.forEach(t),Ze=d(e),u=s(e,"DIV",{class:!0});var h=a(u);P(R.$$.fragment,h),yn=d(h),ue=s(h,"P",{});var ut=a(ue);_n=l(ut,"Pipeline for text-guided image to image generation using Stable Diffusion."),ut.forEach(t),bn=d(h),X=s(h,"P",{});var Ae=a(X);Mn=l(Ae,"This model inherits from "),te=s(Ae,"A",{href:!0});var mt=a(te);wn=l(mt,"DiffusionPipeline"),mt.forEach(t),vn=l(Ae,`. 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.)`),Ae.forEach(t),Cn=d(h),j=s(h,"DIV",{class:!0});var $e=a(j);P(z.$$.fragment,$e),Un=d($e),me=s($e,"P",{});var ht=a(me);Tn=l(ht,"Function invoked when calling the pipeline for generation."),ht.forEach(t),$e.forEach(t),Jn=d(h),I=s(h,"DIV",{class:!0});var Le=a(I);P(Y.$$.fragment,Le),jn=d(Le),m=s(Le,"P",{});var g=a(m);In=l(g,`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),he=s(g,"CODE",{});var gt=a(he);Dn=l(gt,"enable_sequential_cpu_offload"),gt.forEach(t),En=l(g,", this method moves one whole model at a time to the GPU when its "),ge=s(g,"CODE",{});var yt=a(ge);Pn=l(yt,"forward"),yt.forEach(t),Zn=l(g,`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),ye=s(g,"CODE",{});var _t=a(ye);Gn=l(_t,"enable_sequential_cpu_offload"),_t.forEach(t),xn=l(g,", but performance is much better due to the iterative execution of the "),_e=s(g,"CODE",{});var bt=a(_e);kn=l(bt,"unet"),bt.forEach(t),Wn=l(g,"."),g.forEach(t),Le.forEach(t),Bn=d(h),D=s(h,"DIV",{class:!0});var Fe=a(D);P(q.$$.fragment,Fe),Sn=d(Fe),w=s(Fe,"P",{});var oe=a(w);Nn=l(oe,`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
`),be=s(oe,"CODE",{});var Mt=a(be);Vn=l(Mt,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),Mt.forEach(t),An=l(oe,"forward"),Me=s(oe,"CODE",{});var wt=a(Me);$n=l(wt,"method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),wt.forEach(t),Ln=l(oe,"enable_model_cpu_offload`, but performance is lower."),oe.forEach(t),Fe.forEach(t),h.forEach(t),this.h()},h(){p(y,"name","hf:doc:metadata"),p(y,"content",JSON.stringify(Et)),p(v,"id","cycle-diffusion"),p(v,"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"),p(v,"href","#cycle-diffusion"),p(_,"class","relative group"),p(C,"id","overview"),p(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"),p(C,"href","#overview"),p(b,"class","relative group"),p(S,"href","https://arxiv.org/abs/2210.05559"),p(S,"rel","nofollow"),p(K,"href","./stable_diffusion"),p(ee,"href","/docs/diffusers/v0.17.0/en/api/schedulers/ddim#diffusers.DDIMScheduler"),p(ne,"href","/docs/diffusers/v0.17.0/en/api/pipelines/cycle_diffusion#diffusers.CycleDiffusionPipeline"),p(J,"id","diffusers.CycleDiffusionPipeline"),p(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"),p(J,"href","#diffusers.CycleDiffusionPipeline"),p(M,"class","relative group"),p(te,"href","/docs/diffusers/v0.17.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),p(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),p(D,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),p(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,r){n(document.head,y),f(e,we,r),f(e,_,r),n(_,v),n(v,se),Z(W,se,null),n(_,Re),n(_,ae),n(ae,Xe),f(e,ve,r),f(e,b,r),n(b,C),n(C,ie),Z(B,ie,null),n(b,ze),n(b,le),n(le,Ye),f(e,Ce,r),f(e,U,r),n(U,qe),n(U,S),n(S,He),n(U,Oe),f(e,Ue,r),f(e,H,r),n(H,Ke),f(e,Te,r),f(e,O,r),n(O,re),n(re,en),f(e,Je,r),f(e,N,r),n(N,ce),n(ce,nn),n(N,tn),f(e,je,r),f(e,T,r),n(T,V),n(V,on),n(V,K),n(K,sn),n(V,an),n(T,ln),n(T,A),n(A,rn),n(A,ee),n(ee,cn),n(A,dn),f(e,Ie,r),f(e,$,r),n($,de),n(de,pn),n($,fn),f(e,De,r),f(e,L,r),n(L,un),n(L,ne),n(ne,mn),f(e,Ee,r),Z(F,e,r),f(e,Pe,r),f(e,M,r),n(M,J),n(J,pe),Z(Q,pe,null),n(M,hn),n(M,fe),n(fe,gn),f(e,Ze,r),f(e,u,r),Z(R,u,null),n(u,yn),n(u,ue),n(ue,_n),n(u,bn),n(u,X),n(X,Mn),n(X,te),n(te,wn),n(X,vn),n(u,Cn),n(u,j),Z(z,j,null),n(j,Un),n(j,me),n(me,Tn),n(u,Jn),n(u,I),Z(Y,I,null),n(I,jn),n(I,m),n(m,In),n(m,he),n(he,Dn),n(m,En),n(m,ge),n(ge,Pn),n(m,Zn),n(m,ye),n(ye,Gn),n(m,xn),n(m,_e),n(_e,kn),n(m,Wn),n(u,Bn),n(u,D),Z(q,D,null),n(D,Sn),n(D,w),n(w,Nn),n(w,be),n(be,Vn),n(w,An),n(w,Me),n(Me,$n),n(w,Ln),Ge=!0},p:Jt,i(e){Ge||(G(W.$$.fragment,e),G(B.$$.fragment,e),G(F.$$.fragment,e),G(Q.$$.fragment,e),G(R.$$.fragment,e),G(z.$$.fragment,e),G(Y.$$.fragment,e),G(q.$$.fragment,e),Ge=!0)},o(e){x(W.$$.fragment,e),x(B.$$.fragment,e),x(F.$$.fragment,e),x(Q.$$.fragment,e),x(R.$$.fragment,e),x(z.$$.fragment,e),x(Y.$$.fragment,e),x(q.$$.fragment,e),Ge=!1},d(e){t(y),e&&t(we),e&&t(_),k(W),e&&t(ve),e&&t(b),k(B),e&&t(Ce),e&&t(U),e&&t(Ue),e&&t(H),e&&t(Te),e&&t(O),e&&t(Je),e&&t(N),e&&t(je),e&&t(T),e&&t(Ie),e&&t($),e&&t(De),e&&t(L),e&&t(Ee),k(F,e),e&&t(Pe),e&&t(M),k(Q),e&&t(Ze),e&&t(u),k(R),k(z),k(Y),k(q)}}}const Et={local:"cycle-diffusion",sections:[{local:"overview",title:"Overview"},{local:"diffusers.CycleDiffusionPipeline",title:"CycleDiffusionPipeline"}],title:"Cycle Diffusion"};function Pt(zn){return jt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Wt extends vt{constructor(y){super();Ct(this,y,Pt,Dt,Ut,{})}}export{Wt as default,Et as metadata};
