import{s as we,o as De,n as Te}from"../chunks/scheduler.182ea377.js";import{S as Ve,i as Qe,g as r,s as o,r as v,A as Ce,h as l,f as n,c as a,j as F,u as b,x as u,k as N,y as d,a as i,v as x,d as $,t as P,w as y}from"../chunks/index.abf12888.js";import{T as Ie}from"../chunks/Tip.230e2334.js";import{D as se}from"../chunks/Docstring.93f6f462.js";import{H as me}from"../chunks/Heading.16916d63.js";function Le(W){let s,w='Make sure to check out the Schedulers <a href="/using-diffusers/schedulers">guide</a> to learn how to explore the tradeoff between scheduler speed and quality, and see the <a href="/using-diffusers/loading#reuse-components-across-pipelines">reuse components across pipelines</a> section to learn how to efficiently load the same components into multiple pipelines.';return{c(){s=r("p"),s.innerHTML=w},l(p){s=l(p,"P",{"data-svelte-h":!0}),u(s)!=="svelte-5fcsv6"&&(s.innerHTML=w)},m(p,O){i(p,s,O)},p:Te,d(p){p&&n(s)}}}function ke(W){let s,w,p,O,D,R,T,ge='<a href="https://huggingface.co/papers/2111.14822" rel="nofollow">Vector Quantized Diffusion Model for Text-to-Image Synthesis</a> is by Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, Baining Guo.',j,V,he="The abstract from the paper is:",B,Q,_e="<em>We present the vector quantized diffusion (VQ-Diffusion) model for text-to-image generation. This method is based on a vector quantized variational autoencoder (VQ-VAE) whose latent space is modeled by a conditional variant of the recently developed Denoising Diffusion Probabilistic Model (DDPM). We find that this latent-space method is well-suited for text-to-image generation tasks because it not only eliminates the unidirectional bias with existing methods but also allows us to incorporate a mask-and-replace diffusion strategy to avoid the accumulation of errors, which is a serious problem with existing methods. Our experiments show that the VQ-Diffusion produces significantly better text-to-image generation results when compared with conventional autoregressive (AR) models with similar numbers of parameters. Compared with previous GAN-based text-to-image methods, our VQ-Diffusion can handle more complex scenes and improve the synthesized image quality by a large margin. Finally, we show that the image generation computation in our method can be made highly efficient by reparameterization. With traditional AR methods, the text-to-image generation time increases linearly with the output image resolution and hence is quite time consuming even for normal size images. The VQ-Diffusion allows us to achieve a better trade-off between quality and speed. Our experiments indicate that the VQ-Diffusion model with the reparameterization is fifteen times faster than traditional AR methods while achieving a better image quality.</em>",J,C,ve='The original codebase can be found at <a href="https://github.com/microsoft/VQ-Diffusion" rel="nofollow">microsoft/VQ-Diffusion</a>.',Y,g,Z,I,K,c,L,re,A,be="Pipeline for text-to-image generation using VQ Diffusion.",le,H,xe=`This model inherits from <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`,ce,h,k,de,E,$e="The call function to the pipeline for generation.",fe,_,M,pe,G,Pe=`Truncates <code>log_p_x_0</code> such that for each column vector, the total cumulative probability is <code>truncation_rate</code>
The lowest probabilities that would increase the cumulative probability above <code>truncation_rate</code> are set to
zero.`,X,q,ee,m,z,ue,S,ye="Output class for image pipelines.",te,U,ne;return D=new me({props:{title:"VQ Diffusion",local:"vq-diffusion",headingTag:"h1"}}),g=new Ie({props:{$$slots:{default:[Le]},$$scope:{ctx:W}}}),I=new me({props:{title:"VQDiffusionPipeline",local:"diffusers.VQDiffusionPipeline",headingTag:"h2"}}),L=new se({props:{name:"class diffusers.VQDiffusionPipeline",anchor:"diffusers.VQDiffusionPipeline",parameters:[{name:"vqvae",val:": VQModel"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"transformer",val:": Transformer2DModel"},{name:"scheduler",val:": VQDiffusionScheduler"},{name:"learned_classifier_free_sampling_embeddings",val:": LearnedClassifierFreeSamplingEmbeddings"}],parametersDescription:[{anchor:"diffusers.VQDiffusionPipeline.vqvae",description:`<strong>vqvae</strong> (<a href="/docs/diffusers/main/en/api/models/vq#diffusers.VQModel">VQModel</a>) &#x2014;
Vector Quantized Variational Auto-Encoder (VAE) model to encode and decode images to and from latent
representations.`,name:"vqvae"},{anchor:"diffusers.VQDiffusionPipeline.text_encoder",description:`<strong>text_encoder</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIPTextModel</a>) &#x2014;
Frozen text-encoder (<a href="https://huggingface.co/openai/clip-vit-base-patch32" rel="nofollow">clip-vit-base-patch32</a>).`,name:"text_encoder"},{anchor:"diffusers.VQDiffusionPipeline.tokenizer",description:`<strong>tokenizer</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>) &#x2014;
A <code>CLIPTokenizer</code> to tokenize text.`,name:"tokenizer"},{anchor:"diffusers.VQDiffusionPipeline.transformer",description:`<strong>transformer</strong> (<a href="/docs/diffusers/main/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>) &#x2014;
A conditional <code>Transformer2DModel</code> to denoise the encoded image latents.`,name:"transformer"},{anchor:"diffusers.VQDiffusionPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/vq_diffusion#diffusers.VQDiffusionScheduler">VQDiffusionScheduler</a>) &#x2014;
A scheduler to be used in combination with <code>transformer</code> to denoise the encoded image latents.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/vq_diffusion/pipeline_vq_diffusion.py#L52"}}),k=new se({props:{name:"__call__",anchor:"diffusers.VQDiffusionPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]]"},{name:"num_inference_steps",val:": int = 100"},{name:"guidance_scale",val:": float = 5.0"},{name:"truncation_rate",val:": float = 1.0"},{name:"num_images_per_prompt",val:": int = 1"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",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"}],parametersDescription:[{anchor:"diffusers.VQDiffusionPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>) &#x2014;
The prompt or prompts to guide image generation.`,name:"prompt"},{anchor:"diffusers.VQDiffusionPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 100) &#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.VQDiffusionPipeline.__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.VQDiffusionPipeline.__call__.truncation_rate",description:`<strong>truncation_rate</strong> (<code>float</code>, <em>optional</em>, defaults to 1.0 (equivalent to no truncation)) &#x2014;
Used to &#x201C;truncate&#x201D; the predicted classes for x_0 such that the cumulative probability for a pixel is at
most <code>truncation_rate</code>. The lowest probabilities that would increase the cumulative probability above
<code>truncation_rate</code> are set to zero.`,name:"truncation_rate"},{anchor:"diffusers.VQDiffusionPipeline.__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.VQDiffusionPipeline.__call__.generator",description:`<strong>generator</strong> (<code>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.VQDiffusionPipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code> of shape (batch), <em>optional</em>) &#x2014;
Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
generation. Must be valid embedding indices.If not provided, a latents tensor will be generated of
completely masked latent pixels.`,name:"latents"},{anchor:"diffusers.VQDiffusionPipeline.__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.VQDiffusionPipeline.__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/main/en/api/pipelines/unclip#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"diffusers.VQDiffusionPipeline.__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.VQDiffusionPipeline.__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"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/vq_diffusion/pipeline_vq_diffusion.py#L163",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/main/en/api/pipelines/unclip#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> is returned, otherwise a <code>tuple</code> is
returned where the first element is a list with the generated images.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/diffusers/main/en/api/pipelines/unclip#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> or <code>tuple</code></p>
`}}),M=new se({props:{name:"truncate",anchor:"diffusers.VQDiffusionPipeline.truncate",parameters:[{name:"log_p_x_0",val:": FloatTensor"},{name:"truncation_rate",val:": float"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/vq_diffusion/pipeline_vq_diffusion.py#L304"}}),q=new me({props:{title:"ImagePipelineOutput",local:"diffusers.ImagePipelineOutput",headingTag:"h2"}}),z=new se({props:{name:"class diffusers.ImagePipelineOutput",anchor:"diffusers.ImagePipelineOutput",parameters:[{name:"images",val:": typing.Union[typing.List[PIL.Image.Image], numpy.ndarray]"}],parametersDescription:[{anchor:"diffusers.ImagePipelineOutput.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"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L112"}}),{c(){s=r("meta"),w=o(),p=r("p"),O=o(),v(D.$$.fragment),R=o(),T=r("p"),T.innerHTML=ge,j=o(),V=r("p"),V.textContent=he,B=o(),Q=r("p"),Q.innerHTML=_e,J=o(),C=r("p"),C.innerHTML=ve,Y=o(),v(g.$$.fragment),Z=o(),v(I.$$.fragment),K=o(),c=r("div"),v(L.$$.fragment),re=o(),A=r("p"),A.textContent=be,le=o(),H=r("p"),H.innerHTML=xe,ce=o(),h=r("div"),v(k.$$.fragment),de=o(),E=r("p"),E.textContent=$e,fe=o(),_=r("div"),v(M.$$.fragment),pe=o(),G=r("p"),G.innerHTML=Pe,X=o(),v(q.$$.fragment),ee=o(),m=r("div"),v(z.$$.fragment),ue=o(),S=r("p"),S.textContent=ye,te=o(),U=r("p"),this.h()},l(e){const t=Ce("svelte-u9bgzb",document.head);s=l(t,"META",{name:!0,content:!0}),t.forEach(n),w=a(e),p=l(e,"P",{}),F(p).forEach(n),O=a(e),b(D.$$.fragment,e),R=a(e),T=l(e,"P",{"data-svelte-h":!0}),u(T)!=="svelte-13ff88n"&&(T.innerHTML=ge),j=a(e),V=l(e,"P",{"data-svelte-h":!0}),u(V)!=="svelte-1cwsb16"&&(V.textContent=he),B=a(e),Q=l(e,"P",{"data-svelte-h":!0}),u(Q)!=="svelte-688iix"&&(Q.innerHTML=_e),J=a(e),C=l(e,"P",{"data-svelte-h":!0}),u(C)!=="svelte-m9svd3"&&(C.innerHTML=ve),Y=a(e),b(g.$$.fragment,e),Z=a(e),b(I.$$.fragment,e),K=a(e),c=l(e,"DIV",{class:!0});var f=F(c);b(L.$$.fragment,f),re=a(f),A=l(f,"P",{"data-svelte-h":!0}),u(A)!=="svelte-1pya4f8"&&(A.textContent=be),le=a(f),H=l(f,"P",{"data-svelte-h":!0}),u(H)!=="svelte-496sm0"&&(H.innerHTML=xe),ce=a(f),h=l(f,"DIV",{class:!0});var ie=F(h);b(k.$$.fragment,ie),de=a(ie),E=l(ie,"P",{"data-svelte-h":!0}),u(E)!=="svelte-50j04k"&&(E.textContent=$e),ie.forEach(n),fe=a(f),_=l(f,"DIV",{class:!0});var oe=F(_);b(M.$$.fragment,oe),pe=a(oe),G=l(oe,"P",{"data-svelte-h":!0}),u(G)!=="svelte-wg6j8k"&&(G.innerHTML=Pe),oe.forEach(n),f.forEach(n),X=a(e),b(q.$$.fragment,e),ee=a(e),m=l(e,"DIV",{class:!0});var ae=F(m);b(z.$$.fragment,ae),ue=a(ae),S=l(ae,"P",{"data-svelte-h":!0}),u(S)!=="svelte-19wetgi"&&(S.textContent=ye),ae.forEach(n),te=a(e),U=l(e,"P",{}),F(U).forEach(n),this.h()},h(){N(s,"name","hf:doc:metadata"),N(s,"content",Me),N(h,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),N(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),N(c,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),N(m,"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,t){d(document.head,s),i(e,w,t),i(e,p,t),i(e,O,t),x(D,e,t),i(e,R,t),i(e,T,t),i(e,j,t),i(e,V,t),i(e,B,t),i(e,Q,t),i(e,J,t),i(e,C,t),i(e,Y,t),x(g,e,t),i(e,Z,t),x(I,e,t),i(e,K,t),i(e,c,t),x(L,c,null),d(c,re),d(c,A),d(c,le),d(c,H),d(c,ce),d(c,h),x(k,h,null),d(h,de),d(h,E),d(c,fe),d(c,_),x(M,_,null),d(_,pe),d(_,G),i(e,X,t),x(q,e,t),i(e,ee,t),i(e,m,t),x(z,m,null),d(m,ue),d(m,S),i(e,te,t),i(e,U,t),ne=!0},p(e,[t]){const f={};t&2&&(f.$$scope={dirty:t,ctx:e}),g.$set(f)},i(e){ne||($(D.$$.fragment,e),$(g.$$.fragment,e),$(I.$$.fragment,e),$(L.$$.fragment,e),$(k.$$.fragment,e),$(M.$$.fragment,e),$(q.$$.fragment,e),$(z.$$.fragment,e),ne=!0)},o(e){P(D.$$.fragment,e),P(g.$$.fragment,e),P(I.$$.fragment,e),P(L.$$.fragment,e),P(k.$$.fragment,e),P(M.$$.fragment,e),P(q.$$.fragment,e),P(z.$$.fragment,e),ne=!1},d(e){e&&(n(w),n(p),n(O),n(R),n(T),n(j),n(V),n(B),n(Q),n(J),n(C),n(Y),n(Z),n(K),n(c),n(X),n(ee),n(m),n(te),n(U)),n(s),y(D,e),y(g,e),y(I,e),y(L),y(k),y(M),y(q,e),y(z)}}}const Me='{"title":"VQ Diffusion","local":"vq-diffusion","sections":[{"title":"VQDiffusionPipeline","local":"diffusers.VQDiffusionPipeline","sections":[],"depth":2},{"title":"ImagePipelineOutput","local":"diffusers.ImagePipelineOutput","sections":[],"depth":2}],"depth":1}';function qe(W){return De(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ge extends Ve{constructor(s){super(),Qe(this,s,qe,ke,we,{})}}export{Ge as component};
