import{s as ge,n as _e,o as ve}from"../chunks/scheduler.53228c21.js";import{S as be,i as $e,e as i,s,c as f,h as Ve,a as d,d as o,b as r,f as H,g as h,j as D,k as I,l,m as n,n as g,t as _,o as v,p as b}from"../chunks/index.100fac89.js";import{C as ye}from"../chunks/CopyLLMTxtMenu.b0ff86f3.js";import{D as ae}from"../chunks/Docstring.db856a1e.js";import{H as ie,E as we}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.136ef3fd.js";function Qe(de){let c,N,P,S,$,U,V,B,y,le='The VQ-VAE model was introduced in <a href="https://huggingface.co/papers/1711.00937" rel="nofollow">Neural Discrete Representation Learning</a> by Aaron van den Oord, Oriol Vinyals and Koray Kavukcuoglu. The model is used in 🤗 Diffusers to decode latent representations into images. Unlike <a href="/docs/diffusers/main/en/api/models/autoencoderkl#diffusers.AutoencoderKL">AutoencoderKL</a>, the <a href="/docs/diffusers/main/en/api/models/vq#diffusers.VQModel">VQModel</a> works in a quantized latent space.',K,w,ce="The abstract from the paper is:",F,Q,ue="<em>Learning useful representations without supervision remains a key challenge in machine learning. In this paper, we propose a simple yet powerful generative model that learns such discrete representations. Our model, the Vector Quantised-Variational AutoEncoder (VQ-VAE), differs from VAEs in two key ways: the encoder network outputs discrete, rather than continuous, codes; and the prior is learnt rather than static. In order to learn a discrete latent representation, we incorporate ideas from vector quantisation (VQ). Using the VQ method allows the model to circumvent issues of “posterior collapse” — where the latents are ignored when they are paired with a powerful autoregressive decoder — typically observed in the VAE framework. Pairing these representations with an autoregressive prior, the model can generate high quality images, videos, and speech as well as doing high quality speaker conversion and unsupervised learning of phonemes, providing further evidence of the utility of the learnt representations.</em>",R,x,j,a,M,te,L,me="A VQ-VAE model for decoding latent representations.",oe,O,pe=`This model inherits from <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin">ModelMixin</a>. Check the superclass documentation for it’s generic methods implemented
for all models (such as downloading or saving).`,ne,m,q,se,C,fe='The <a href="/docs/diffusers/main/en/api/models/vq#diffusers.VQModel">VQModel</a> forward method.',W,T,G,u,k,re,z,he="Output of VQModel encoding method.",J,E,X,A,Y;return $=new ye({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),V=new ie({props:{title:"VQModel",local:"vqmodel",headingTag:"h1"}}),x=new ie({props:{title:"VQModel",local:"diffusers.VQModel",headingTag:"h2"}}),M=new ae({props:{name:"class diffusers.VQModel",anchor:"diffusers.VQModel",parameters:[{name:"in_channels",val:": int = 3"},{name:"out_channels",val:": int = 3"},{name:"down_block_types",val:": typing.Tuple[str, ...] = ('DownEncoderBlock2D',)"},{name:"up_block_types",val:": typing.Tuple[str, ...] = ('UpDecoderBlock2D',)"},{name:"block_out_channels",val:": typing.Tuple[int, ...] = (64,)"},{name:"layers_per_block",val:": int = 1"},{name:"act_fn",val:": str = 'silu'"},{name:"latent_channels",val:": int = 3"},{name:"sample_size",val:": int = 32"},{name:"num_vq_embeddings",val:": int = 256"},{name:"norm_num_groups",val:": int = 32"},{name:"vq_embed_dim",val:": typing.Optional[int] = None"},{name:"scaling_factor",val:": float = 0.18215"},{name:"norm_type",val:": str = 'group'"},{name:"mid_block_add_attention",val:" = True"},{name:"lookup_from_codebook",val:" = False"},{name:"force_upcast",val:" = False"}],parametersDescription:[{anchor:"diffusers.VQModel.in_channels",description:"<strong>in_channels</strong> (int, <em>optional</em>, defaults to 3) &#x2014; Number of channels in the input image.",name:"in_channels"},{anchor:"diffusers.VQModel.out_channels",description:"<strong>out_channels</strong> (int,  <em>optional</em>, defaults to 3) &#x2014; Number of channels in the output.",name:"out_channels"},{anchor:"diffusers.VQModel.down_block_types",description:`<strong>down_block_types</strong> (<code>Tuple[str]</code>, <em>optional</em>, defaults to <code>(&quot;DownEncoderBlock2D&quot;,)</code>) &#x2014;
Tuple of downsample block types.`,name:"down_block_types"},{anchor:"diffusers.VQModel.up_block_types",description:`<strong>up_block_types</strong> (<code>Tuple[str]</code>, <em>optional</em>, defaults to <code>(&quot;UpDecoderBlock2D&quot;,)</code>) &#x2014;
Tuple of upsample block types.`,name:"up_block_types"},{anchor:"diffusers.VQModel.block_out_channels",description:`<strong>block_out_channels</strong> (<code>Tuple[int]</code>, <em>optional</em>, defaults to <code>(64,)</code>) &#x2014;
Tuple of block output channels.`,name:"block_out_channels"},{anchor:"diffusers.VQModel.layers_per_block",description:"<strong>layers_per_block</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) &#x2014; Number of layers per block.",name:"layers_per_block"},{anchor:"diffusers.VQModel.act_fn",description:"<strong>act_fn</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;silu&quot;</code>) &#x2014; The activation function to use.",name:"act_fn"},{anchor:"diffusers.VQModel.latent_channels",description:"<strong>latent_channels</strong> (<code>int</code>, <em>optional</em>, defaults to <code>3</code>) &#x2014; Number of channels in the latent space.",name:"latent_channels"},{anchor:"diffusers.VQModel.sample_size",description:"<strong>sample_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) &#x2014; Sample input size.",name:"sample_size"},{anchor:"diffusers.VQModel.num_vq_embeddings",description:"<strong>num_vq_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to <code>256</code>) &#x2014; Number of codebook vectors in the VQ-VAE.",name:"num_vq_embeddings"},{anchor:"diffusers.VQModel.norm_num_groups",description:"<strong>norm_num_groups</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) &#x2014; Number of groups for normalization layers.",name:"norm_num_groups"},{anchor:"diffusers.VQModel.vq_embed_dim",description:"<strong>vq_embed_dim</strong> (<code>int</code>, <em>optional</em>) &#x2014; Hidden dim of codebook vectors in the VQ-VAE.",name:"vq_embed_dim"},{anchor:"diffusers.VQModel.scaling_factor",description:`<strong>scaling_factor</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.18215</code>) &#x2014;
The component-wise standard deviation of the trained latent space computed using the first batch of the
training set. This is used to scale the latent space to have unit variance when training the diffusion
model. The latents are scaled with the formula <code>z = z * scaling_factor</code> before being passed to the
diffusion model. When decoding, the latents are scaled back to the original scale with the formula: <code>z = 1 / scaling_factor * z</code>. For more details, refer to sections 4.3.2 and D.1 of the <a href="https://huggingface.co/papers/2112.10752" rel="nofollow">High-Resolution Image
Synthesis with Latent Diffusion Models</a> paper.`,name:"scaling_factor"},{anchor:"diffusers.VQModel.norm_type",description:`<strong>norm_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;group&quot;</code>) &#x2014;
Type of normalization layer to use. Can be one of <code>&quot;group&quot;</code> or <code>&quot;spatial&quot;</code>.`,name:"norm_type"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/vq_model.py#L40"}}),q=new ae({props:{name:"forward",anchor:"diffusers.VQModel.forward",parameters:[{name:"sample",val:": Tensor"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.VQModel.forward.sample",description:"<strong>sample</strong> (<code>torch.Tensor</code>) &#x2014; Input sample.",name:"sample"},{anchor:"diffusers.VQModel.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 <a href="/docs/diffusers/main/en/api/models/vq#diffusers.models.autoencoders.vq_model.VQEncoderOutput">models.autoencoders.vq_model.VQEncoderOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/vq_model.py#L163",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>If return_dict is True, a <a
  href="/docs/diffusers/main/en/api/models/vq#diffusers.models.autoencoders.vq_model.VQEncoderOutput"
>VQEncoderOutput</a> is returned, otherwise a
plain <code>tuple</code> is returned.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/diffusers/main/en/api/models/vq#diffusers.models.autoencoders.vq_model.VQEncoderOutput"
>VQEncoderOutput</a> or <code>tuple</code></p>
`}}),T=new ie({props:{title:"VQEncoderOutput",local:"diffusers.models.autoencoders.vq_model.VQEncoderOutput",headingTag:"h2"}}),k=new ae({props:{name:"class diffusers.models.autoencoders.vq_model.VQEncoderOutput",anchor:"diffusers.models.autoencoders.vq_model.VQEncoderOutput",parameters:[{name:"latents",val:": Tensor"}],parametersDescription:[{anchor:"diffusers.models.autoencoders.vq_model.VQEncoderOutput.latents",description:`<strong>latents</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, height, width)</code>) &#x2014;
The encoded output sample from the last layer of the model.`,name:"latents"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/vq_model.py#L28"}}),E=new we({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/vq.md"}}),{c(){c=i("meta"),N=s(),P=i("p"),S=s(),f($.$$.fragment),U=s(),f(V.$$.fragment),B=s(),y=i("p"),y.innerHTML=le,K=s(),w=i("p"),w.textContent=ce,F=s(),Q=i("p"),Q.innerHTML=ue,R=s(),f(x.$$.fragment),j=s(),a=i("div"),f(M.$$.fragment),te=s(),L=i("p"),L.textContent=me,oe=s(),O=i("p"),O.innerHTML=pe,ne=s(),m=i("div"),f(q.$$.fragment),se=s(),C=i("p"),C.innerHTML=fe,W=s(),f(T.$$.fragment),G=s(),u=i("div"),f(k.$$.fragment),re=s(),z=i("p"),z.textContent=he,J=s(),f(E.$$.fragment),X=s(),A=i("p"),this.h()},l(e){const t=Ve("svelte-u9bgzb",document.head);c=d(t,"META",{name:!0,content:!0}),t.forEach(o),N=r(e),P=d(e,"P",{}),H(P).forEach(o),S=r(e),h($.$$.fragment,e),U=r(e),h(V.$$.fragment,e),B=r(e),y=d(e,"P",{"data-svelte-h":!0}),D(y)!=="svelte-1ie7sp3"&&(y.innerHTML=le),K=r(e),w=d(e,"P",{"data-svelte-h":!0}),D(w)!=="svelte-1cwsb16"&&(w.textContent=ce),F=r(e),Q=d(e,"P",{"data-svelte-h":!0}),D(Q)!=="svelte-331jgs"&&(Q.innerHTML=ue),R=r(e),h(x.$$.fragment,e),j=r(e),a=d(e,"DIV",{class:!0});var p=H(a);h(M.$$.fragment,p),te=r(p),L=d(p,"P",{"data-svelte-h":!0}),D(L)!=="svelte-1fe1n0y"&&(L.textContent=me),oe=r(p),O=d(p,"P",{"data-svelte-h":!0}),D(O)!=="svelte-1hyu2ru"&&(O.innerHTML=pe),ne=r(p),m=d(p,"DIV",{class:!0});var Z=H(m);h(q.$$.fragment,Z),se=r(Z),C=d(Z,"P",{"data-svelte-h":!0}),D(C)!=="svelte-1rgc5xe"&&(C.innerHTML=fe),Z.forEach(o),p.forEach(o),W=r(e),h(T.$$.fragment,e),G=r(e),u=d(e,"DIV",{class:!0});var ee=H(u);h(k.$$.fragment,ee),re=r(ee),z=d(ee,"P",{"data-svelte-h":!0}),D(z)!=="svelte-1u2gsdw"&&(z.textContent=he),ee.forEach(o),J=r(e),h(E.$$.fragment,e),X=r(e),A=d(e,"P",{}),H(A).forEach(o),this.h()},h(){I(c,"name","hf:doc:metadata"),I(c,"content",xe),I(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(a,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),I(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,t){l(document.head,c),n(e,N,t),n(e,P,t),n(e,S,t),g($,e,t),n(e,U,t),g(V,e,t),n(e,B,t),n(e,y,t),n(e,K,t),n(e,w,t),n(e,F,t),n(e,Q,t),n(e,R,t),g(x,e,t),n(e,j,t),n(e,a,t),g(M,a,null),l(a,te),l(a,L),l(a,oe),l(a,O),l(a,ne),l(a,m),g(q,m,null),l(m,se),l(m,C),n(e,W,t),g(T,e,t),n(e,G,t),n(e,u,t),g(k,u,null),l(u,re),l(u,z),n(e,J,t),g(E,e,t),n(e,X,t),n(e,A,t),Y=!0},p:_e,i(e){Y||(_($.$$.fragment,e),_(V.$$.fragment,e),_(x.$$.fragment,e),_(M.$$.fragment,e),_(q.$$.fragment,e),_(T.$$.fragment,e),_(k.$$.fragment,e),_(E.$$.fragment,e),Y=!0)},o(e){v($.$$.fragment,e),v(V.$$.fragment,e),v(x.$$.fragment,e),v(M.$$.fragment,e),v(q.$$.fragment,e),v(T.$$.fragment,e),v(k.$$.fragment,e),v(E.$$.fragment,e),Y=!1},d(e){e&&(o(N),o(P),o(S),o(U),o(B),o(y),o(K),o(w),o(F),o(Q),o(R),o(j),o(a),o(W),o(G),o(u),o(J),o(X),o(A)),o(c),b($,e),b(V,e),b(x,e),b(M),b(q),b(T,e),b(k),b(E,e)}}}const xe='{"title":"VQModel","local":"vqmodel","sections":[{"title":"VQModel","local":"diffusers.VQModel","sections":[],"depth":2},{"title":"VQEncoderOutput","local":"diffusers.models.autoencoders.vq_model.VQEncoderOutput","sections":[],"depth":2}],"depth":1}';function Me(de){return ve(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Le extends be{constructor(c){super(),$e(this,c,Me,Qe,ge,{})}}export{Le as component};
