Buckets:

download
raw
13.1 kB
import"../chunks/DsnmJJEf.js";import{i as Z,h as W,C as B,H as E,D as o,E as J,s as R,a as L}from"../chunks/BtE7mKSK.js";import{p as z,o as G,s as e,f as x,a as u,b as N,c as n,d as m,n as s,r as t}from"../chunks/jDjavuwI.js";import{E as F}from"../chunks/SrSJA0zO.js";const I='{"title":"Consistency Decoder","local":"consistency-decoder","sections":[{"title":"ConsistencyDecoderVAE","local":"diffusers.ConsistencyDecoderVAE","sections":[],"depth":2}],"depth":1}';var Y=m('<meta name="hf:doc:metadata"/>'),O=m("<p>Examples:</p> <!>",1),X=m(`<p></p> <!> <!> <p>Consistency decoder can be used to decode the latents from the denoising UNet in the <a href="/docs/diffusers/pr_14409/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a>. This decoder was introduced in the <a href="https://openai.com/dall-e-3" rel="nofollow">DALL-E 3 technical report</a>.</p> <p>The original codebase can be found at <a href="https://github.com/openai/consistencydecoder" rel="nofollow">openai/consistencydecoder</a>.</p> <blockquote class="warning"><p>Inference is only supported for 2 iterations as of now.</p></blockquote> <p>The pipeline could not have been contributed without the help of <a href="https://github.com/madebyollin" rel="nofollow">madebyollin</a> and <a href="https://github.com/mrsteyk" rel="nofollow">mrsteyk</a> from <a href="https://github.com/openai/consistencydecoder/issues/1" rel="nofollow">this issue</a>.</p> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The consistency decoder used with DALL-E 3.</p> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Decodes the input latent vector <code>z</code> using the consistency decoder VAE model.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Encode a batch of images into latents.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Disables custom attention processors and sets the default attention implementation.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Encode a batch of images using a tiled encoder.</p> <p>When this option is enabled, the VAE will split the input tensor into tiles to compute encoding in several
steps. This is useful to keep memory use constant regardless of image size. The end result of tiled encoding is
different from non-tiled encoding because each tile uses a different encoder. To avoid tiling artifacts, the
tiles overlap and are blended together to form a smooth output. You may still see tile-sized changes in the
output, but they should be much less noticeable.</p></div></div> <!> <p></p>`,1);function Q(T,w){z(w,!1),G(()=>{new URLSearchParams(window.location.search).get("fw")}),Z();var f=X();W("25mfxx",r=>{var p=Y();R(p,"content",I),u(r,p)});var h=e(x(f),2);B(h,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var _=e(h,2);E(_,{title:"Consistency Decoder",local:"consistency-decoder",headingTag:"h1"});var g=e(_,10);E(g,{title:"ConsistencyDecoderVAE",local:"diffusers.ConsistencyDecoderVAE",headingTag:"h2"});var a=e(g,2),b=n(a);o(b,{name:"class diffusers.ConsistencyDecoderVAE",anchor:"diffusers.ConsistencyDecoderVAE",source:"https://github.com/huggingface/diffusers/blob/vr_14409/src/diffusers/models/autoencoders/consistency_decoder_vae.py#L51",parameters:[{name:"scaling_factor",val:": float = 0.18215"},{name:"latent_channels",val:": int = 4"},{name:"sample_size",val:": int = 32"},{name:"encoder_act_fn",val:": str = 'silu'"},{name:"encoder_block_out_channels",val:": tuple = (128, 256, 512, 512)"},{name:"encoder_double_z",val:": bool = True"},{name:"encoder_down_block_types",val:": tuple = ('DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D')"},{name:"encoder_in_channels",val:": int = 3"},{name:"encoder_layers_per_block",val:": int = 2"},{name:"encoder_norm_num_groups",val:": int = 32"},{name:"encoder_out_channels",val:": int = 4"},{name:"decoder_add_attention",val:": bool = False"},{name:"decoder_block_out_channels",val:": tuple = (320, 640, 1024, 1024)"},{name:"decoder_down_block_types",val:": tuple = ('ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D')"},{name:"decoder_downsample_padding",val:": int = 1"},{name:"decoder_in_channels",val:": int = 7"},{name:"decoder_layers_per_block",val:": int = 3"},{name:"decoder_norm_eps",val:": float = 1e-05"},{name:"decoder_norm_num_groups",val:": int = 32"},{name:"decoder_num_train_timesteps",val:": int = 1024"},{name:"decoder_out_channels",val:": int = 6"},{name:"decoder_resnet_time_scale_shift",val:": str = 'scale_shift'"},{name:"decoder_time_embedding_type",val:": str = 'learned'"},{name:"decoder_up_block_types",val:": tuple = ('ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D')"}]});var v=e(b,4);F(v,{anchor:"diffusers.ConsistencyDecoderVAE.example",children:(r,p)=>{var D=O(),U=e(x(D),2);L(U,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUlMkMlMjBDb25zaXN0ZW5jeURlY29kZXJWQUUlMEElMEF2YWUlMjAlM0QlMjBDb25zaXN0ZW5jeURlY29kZXJWQUUuZnJvbV9wcmV0cmFpbmVkKCUyMm9wZW5haSUyRmNvbnNpc3RlbmN5LWRlY29kZXIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpJTBBcGlwZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJzdGFibGUtZGlmZnVzaW9uLXYxLTUlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMkMlMjB2YWUlM0R2YWUlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMEEpLnRvKCUyMmN1ZGElMjIpJTBBJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKCUyMmhvcnNlJTIyJTJDJTIwZ2VuZXJhdG9yJTNEdG9yY2gubWFudWFsX3NlZWQoMCkpLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",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> StableDiffusionPipeline, ConsistencyDecoderVAE
<span class="hljs-meta">&gt;&gt;&gt; </span>vae = ConsistencyDecoderVAE.from_pretrained(<span class="hljs-string">&quot;openai/consistency-decoder&quot;</span>, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = StableDiffusionPipeline.from_pretrained(
<span class="hljs-meta">... </span> <span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>, vae=vae, torch_dtype=torch.float16
<span class="hljs-meta">... </span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(<span class="hljs-string">&quot;horse&quot;</span>, generator=torch.manual_seed(<span class="hljs-number">0</span>)).images[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image`,lang:"py",wrap:!1}),u(r,D)},$$slots:{default:!0}});var c=e(v,2),C=n(c);o(C,{name:"decode",anchor:"diffusers.ConsistencyDecoderVAE.decode",source:"https://github.com/huggingface/diffusers/blob/vr_14409/src/diffusers/models/autoencoders/consistency_decoder_vae.py#L220",parameters:[{name:"z",val:": Tensor"},{name:"generator",val:": typing.Optional[torch.Generator] = None"},{name:"return_dict",val:": bool = True"},{name:"num_inference_steps",val:": int = 2"}],parametersDescription:[{anchor:"diffusers.ConsistencyDecoderVAE.decode.z",description:"<strong>z</strong> (torch.Tensor) &#x2014; The input latent vector.",name:"z"},{anchor:"diffusers.ConsistencyDecoderVAE.decode.generator",description:"<strong>generator</strong> (torch.Generator | None) &#x2014; The random number generator. Default is None.",name:"generator"},{anchor:"diffusers.ConsistencyDecoderVAE.decode.return_dict",description:"<strong>return_dict</strong> (bool) &#x2014; Whether to return the output as a dictionary. Default is True.",name:"return_dict"},{anchor:"diffusers.ConsistencyDecoderVAE.decode.num_inference_steps",description:"<strong>num_inference_steps</strong> (int) &#x2014; The number of inference steps. Default is 2.",name:"num_inference_steps"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>
<p>The decoded output.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>
<p>DecoderOutput | tuple[torch.Tensor]</p>
`}),s(2),t(c);var d=e(c,2),M=n(d);o(M,{name:"encode",anchor:"diffusers.ConsistencyDecoderVAE.encode",source:"https://github.com/huggingface/diffusers/blob/vr_14409/src/diffusers/models/autoencoders/consistency_decoder_vae.py#L185",parameters:[{name:"x",val:": Tensor"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.ConsistencyDecoderVAE.encode.x",description:"<strong>x</strong> (<code>torch.Tensor</code>) &#x2014; Input batch of images.",name:"x"},{anchor:"diffusers.ConsistencyDecoderVAE.encode.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to return a <code>ConsistencyDecoderVAEOutput</code>
instead of a plain tuple.`,name:"return_dict"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>
<p>The latent representations of the encoded images. If <code>return_dict</code> is True, a
<code>ConsistencyDecoderVAEOutput</code> is returned, otherwise a
plain <code>tuple</code> is returned.</p>
`}),s(2),t(d);var i=e(d,2),A=n(i);o(A,{name:"forward",anchor:"diffusers.ConsistencyDecoderVAE.forward",source:"https://github.com/huggingface/diffusers/blob/vr_14409/src/diffusers/models/autoencoders/consistency_decoder_vae.py#L336",parameters:[{name:"sample",val:": Tensor"},{name:"sample_posterior",val:": bool = False"},{name:"return_dict",val:": bool = True"},{name:"generator",val:": typing.Optional[torch.Generator] = None"}],parametersDescription:[{anchor:"diffusers.ConsistencyDecoderVAE.forward.sample",description:"<strong>sample</strong> (<code>torch.Tensor</code>) &#x2014; Input sample.",name:"sample"},{anchor:"diffusers.ConsistencyDecoderVAE.forward.sample_posterior",description:`<strong>sample_posterior</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to sample from the posterior.`,name:"sample_posterior"},{anchor:"diffusers.ConsistencyDecoderVAE.forward.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 <code>DecoderOutput</code> instead of a plain tuple.`,name:"return_dict"},{anchor:"diffusers.ConsistencyDecoderVAE.forward.generator",description:`<strong>generator</strong> (<code>torch.Generator</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
Generator to use for sampling.`,name:"generator"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>
<p>If return_dict is True, a <code>DecoderOutput</code> is returned, otherwise a plain <code>tuple</code> is returned.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>
<p><code>DecoderOutput</code> or <code>tuple</code></p>
`}),t(i);var l=e(i,2),V=n(l);o(V,{name:"set_default_attn_processor",anchor:"diffusers.ConsistencyDecoderVAE.set_default_attn_processor",source:"https://github.com/huggingface/diffusers/blob/vr_14409/src/diffusers/models/autoencoders/consistency_decoder_vae.py#L170",parameters:[]}),s(2),t(l);var y=e(l,2),k=n(y);o(k,{name:"tiled_encode",anchor:"diffusers.ConsistencyDecoderVAE.tiled_encode",source:"https://github.com/huggingface/diffusers/blob/vr_14409/src/diffusers/models/autoencoders/consistency_decoder_vae.py#L281",parameters:[{name:"x",val:": Tensor"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.ConsistencyDecoderVAE.tiled_encode.x",description:"<strong>x</strong> (<code>torch.Tensor</code>) &#x2014; Input batch of images.",name:"x"},{anchor:"diffusers.ConsistencyDecoderVAE.tiled_encode.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 <code>ConsistencyDecoderVAEOutput</code>
instead of a plain tuple.`,name:"return_dict"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>
<p>If return_dict is True, a <code>ConsistencyDecoderVAEOutput</code>
is returned, otherwise a plain <code>tuple</code> is returned.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>
<p><code>ConsistencyDecoderVAEOutput</code> or <code>tuple</code></p>
`}),s(4),t(y),t(a);var j=e(a,2);J(j,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/consistency_decoder_vae.md"}),s(2),u(T,f),N()}export{Q as component};

Xet Storage Details

Size:
13.1 kB
·
Xet hash:
98590d74ba91ade9fa89f55f3ff01b58c414822135b98ee2931b22192cb6203e

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.