import{S as mt,i as ht,s as vt,e as n,k as c,w as U,t as i,M as gt,c as r,d as o,m as u,a as s,x as B,h as l,b as a,G as t,g as p,y as F,L as _t,q as H,o as C,B as R,v as wt}from"../../../chunks/vendor-hf-doc-builder.js";import{D as Re}from"../../../chunks/Docstring-hf-doc-builder.js";import{I as We}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function Vt(Ge){let h,oe,v,V,W,$,_e,G,we,ne,m,Ve,q,be,ye,L,Ee,Qe,N,ke,$e,re,z,qe,se,I,J,Me,ae,g,b,j,M,Ae,X,Te,ie,f,A,xe,Y,Oe,De,T,Pe,S,Le,Ne,ze,y,x,Ie,O,Se,K,Ke,Ue,le,_,E,Z,D,Be,ee,Fe,de,w,P,He,te,Ce,ce;return $=new We({}),M=new We({}),A=new Re({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'"}],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.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.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://arxiv.org/abs/2112.10752" rel="nofollow">High-Resolution Image
Synthesis with Latent Diffusion Models</a> paper.`,name:"scaling_factor"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/vq_model.py#L39"}}),x=new Re({props:{name:"forward",anchor:"diffusers.VQModel.forward",parameters:[{name:"sample",val:": FloatTensor"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.VQModel.forward.sample",description:"<strong>sample</strong> (<code>torch.FloatTensor</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.vq_model.VQEncoderOutput">models.vq_model.VQEncoderOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/vq_model.py#L146",returnDescription:`
<p>If return_dict is True, a <a
  href="/docs/diffusers/main/en/api/models/vq#diffusers.models.vq_model.VQEncoderOutput"
>VQEncoderOutput</a> is returned, otherwise a plain <code>tuple</code>
is returned.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/main/en/api/models/vq#diffusers.models.vq_model.VQEncoderOutput"
>VQEncoderOutput</a> or <code>tuple</code></p>
`}}),D=new We({}),P=new Re({props:{name:"class diffusers.models.vq_model.VQEncoderOutput",anchor:"diffusers.models.vq_model.VQEncoderOutput",parameters:[{name:"latents",val:": FloatTensor"}],parametersDescription:[{anchor:"diffusers.models.vq_model.VQEncoderOutput.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</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/vq_model.py#L27"}}),{c(){h=n("meta"),oe=c(),v=n("h1"),V=n("a"),W=n("span"),U($.$$.fragment),_e=c(),G=n("span"),we=i("VQModel"),ne=c(),m=n("p"),Ve=i("The VQ-VAE model was introduced in "),q=n("a"),be=i("Neural Discrete Representation Learning"),ye=i(" by Aaron van den Oord, Oriol Vinyals and Koray Kavukcuoglu. The model is used in \u{1F917} Diffusers to decode latent representations into images. Unlike "),L=n("a"),Ee=i("AutoencoderKL"),Qe=i(", the "),N=n("a"),ke=i("VQModel"),$e=i(" works in a quantized latent space."),re=c(),z=n("p"),qe=i("The abstract from the paper is:"),se=c(),I=n("p"),J=n("em"),Me=i("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 \u201Cposterior collapse\u201D \u2014 where the latents are ignored when they are paired with a powerful autoregressive decoder \u2014 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."),ae=c(),g=n("h2"),b=n("a"),j=n("span"),U(M.$$.fragment),Ae=c(),X=n("span"),Te=i("VQModel"),ie=c(),f=n("div"),U(A.$$.fragment),xe=c(),Y=n("p"),Oe=i("A VQ-VAE model for decoding latent representations."),De=c(),T=n("p"),Pe=i("This model inherits from "),S=n("a"),Le=i("ModelMixin"),Ne=i(`. Check the superclass documentation for it\u2019s generic methods implemented
for all models (such as downloading or saving).`),ze=c(),y=n("div"),U(x.$$.fragment),Ie=c(),O=n("p"),Se=i("The "),K=n("a"),Ke=i("VQModel"),Ue=i(" forward method."),le=c(),_=n("h2"),E=n("a"),Z=n("span"),U(D.$$.fragment),Be=c(),ee=n("span"),Fe=i("VQEncoderOutput"),de=c(),w=n("div"),U(P.$$.fragment),He=c(),te=n("p"),Ce=i("Output of VQModel encoding method."),this.h()},l(e){const d=gt('[data-svelte="svelte-1phssyn"]',document.head);h=r(d,"META",{name:!0,content:!0}),d.forEach(o),oe=u(e),v=r(e,"H1",{class:!0});var ue=s(v);V=r(ue,"A",{id:!0,class:!0,href:!0});var Je=s(V);W=r(Je,"SPAN",{});var je=s(W);B($.$$.fragment,je),je.forEach(o),Je.forEach(o),_e=u(ue),G=r(ue,"SPAN",{});var Xe=s(G);we=l(Xe,"VQModel"),Xe.forEach(o),ue.forEach(o),ne=u(e),m=r(e,"P",{});var Q=s(m);Ve=l(Q,"The VQ-VAE model was introduced in "),q=r(Q,"A",{href:!0,rel:!0});var Ye=s(q);be=l(Ye,"Neural Discrete Representation Learning"),Ye.forEach(o),ye=l(Q," by Aaron van den Oord, Oriol Vinyals and Koray Kavukcuoglu. The model is used in \u{1F917} Diffusers to decode latent representations into images. Unlike "),L=r(Q,"A",{href:!0});var Ze=s(L);Ee=l(Ze,"AutoencoderKL"),Ze.forEach(o),Qe=l(Q,", the "),N=r(Q,"A",{href:!0});var et=s(N);ke=l(et,"VQModel"),et.forEach(o),$e=l(Q," works in a quantized latent space."),Q.forEach(o),re=u(e),z=r(e,"P",{});var tt=s(z);qe=l(tt,"The abstract from the paper is:"),tt.forEach(o),se=u(e),I=r(e,"P",{});var ot=s(I);J=r(ot,"EM",{});var nt=s(J);Me=l(nt,"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 \u201Cposterior collapse\u201D \u2014 where the latents are ignored when they are paired with a powerful autoregressive decoder \u2014 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."),nt.forEach(o),ot.forEach(o),ae=u(e),g=r(e,"H2",{class:!0});var pe=s(g);b=r(pe,"A",{id:!0,class:!0,href:!0});var rt=s(b);j=r(rt,"SPAN",{});var st=s(j);B(M.$$.fragment,st),st.forEach(o),rt.forEach(o),Ae=u(pe),X=r(pe,"SPAN",{});var at=s(X);Te=l(at,"VQModel"),at.forEach(o),pe.forEach(o),ie=u(e),f=r(e,"DIV",{class:!0});var k=s(f);B(A.$$.fragment,k),xe=u(k),Y=r(k,"P",{});var it=s(Y);Oe=l(it,"A VQ-VAE model for decoding latent representations."),it.forEach(o),De=u(k),T=r(k,"P",{});var fe=s(T);Pe=l(fe,"This model inherits from "),S=r(fe,"A",{href:!0});var lt=s(S);Le=l(lt,"ModelMixin"),lt.forEach(o),Ne=l(fe,`. Check the superclass documentation for it\u2019s generic methods implemented
for all models (such as downloading or saving).`),fe.forEach(o),ze=u(k),y=r(k,"DIV",{class:!0});var me=s(y);B(x.$$.fragment,me),Ie=u(me),O=r(me,"P",{});var he=s(O);Se=l(he,"The "),K=r(he,"A",{href:!0});var dt=s(K);Ke=l(dt,"VQModel"),dt.forEach(o),Ue=l(he," forward method."),he.forEach(o),me.forEach(o),k.forEach(o),le=u(e),_=r(e,"H2",{class:!0});var ve=s(_);E=r(ve,"A",{id:!0,class:!0,href:!0});var ct=s(E);Z=r(ct,"SPAN",{});var ut=s(Z);B(D.$$.fragment,ut),ut.forEach(o),ct.forEach(o),Be=u(ve),ee=r(ve,"SPAN",{});var pt=s(ee);Fe=l(pt,"VQEncoderOutput"),pt.forEach(o),ve.forEach(o),de=u(e),w=r(e,"DIV",{class:!0});var ge=s(w);B(P.$$.fragment,ge),He=u(ge),te=r(ge,"P",{});var ft=s(te);Ce=l(ft,"Output of VQModel encoding method."),ft.forEach(o),ge.forEach(o),this.h()},h(){a(h,"name","hf:doc:metadata"),a(h,"content",JSON.stringify(bt)),a(V,"id","vqmodel"),a(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"),a(V,"href","#vqmodel"),a(v,"class","relative group"),a(q,"href","https://huggingface.co/papers/1711.00937"),a(q,"rel","nofollow"),a(L,"href","/docs/diffusers/main/en/api/models/autoencoderkl#diffusers.AutoencoderKL"),a(N,"href","/docs/diffusers/main/en/api/models/vq#diffusers.VQModel"),a(b,"id","diffusers.VQModel"),a(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"),a(b,"href","#diffusers.VQModel"),a(g,"class","relative group"),a(S,"href","/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin"),a(K,"href","/docs/diffusers/main/en/api/models/vq#diffusers.VQModel"),a(y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(f,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(E,"id","diffusers.models.vq_model.VQEncoderOutput"),a(E,"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"),a(E,"href","#diffusers.models.vq_model.VQEncoderOutput"),a(_,"class","relative group"),a(w,"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,d){t(document.head,h),p(e,oe,d),p(e,v,d),t(v,V),t(V,W),F($,W,null),t(v,_e),t(v,G),t(G,we),p(e,ne,d),p(e,m,d),t(m,Ve),t(m,q),t(q,be),t(m,ye),t(m,L),t(L,Ee),t(m,Qe),t(m,N),t(N,ke),t(m,$e),p(e,re,d),p(e,z,d),t(z,qe),p(e,se,d),p(e,I,d),t(I,J),t(J,Me),p(e,ae,d),p(e,g,d),t(g,b),t(b,j),F(M,j,null),t(g,Ae),t(g,X),t(X,Te),p(e,ie,d),p(e,f,d),F(A,f,null),t(f,xe),t(f,Y),t(Y,Oe),t(f,De),t(f,T),t(T,Pe),t(T,S),t(S,Le),t(T,Ne),t(f,ze),t(f,y),F(x,y,null),t(y,Ie),t(y,O),t(O,Se),t(O,K),t(K,Ke),t(O,Ue),p(e,le,d),p(e,_,d),t(_,E),t(E,Z),F(D,Z,null),t(_,Be),t(_,ee),t(ee,Fe),p(e,de,d),p(e,w,d),F(P,w,null),t(w,He),t(w,te),t(te,Ce),ce=!0},p:_t,i(e){ce||(H($.$$.fragment,e),H(M.$$.fragment,e),H(A.$$.fragment,e),H(x.$$.fragment,e),H(D.$$.fragment,e),H(P.$$.fragment,e),ce=!0)},o(e){C($.$$.fragment,e),C(M.$$.fragment,e),C(A.$$.fragment,e),C(x.$$.fragment,e),C(D.$$.fragment,e),C(P.$$.fragment,e),ce=!1},d(e){o(h),e&&o(oe),e&&o(v),R($),e&&o(ne),e&&o(m),e&&o(re),e&&o(z),e&&o(se),e&&o(I),e&&o(ae),e&&o(g),R(M),e&&o(ie),e&&o(f),R(A),R(x),e&&o(le),e&&o(_),R(D),e&&o(de),e&&o(w),R(P)}}}const bt={local:"vqmodel",sections:[{local:"diffusers.VQModel",title:"VQModel"},{local:"diffusers.models.vq_model.VQEncoderOutput",title:"VQEncoderOutput"}],title:"VQModel"};function yt(Ge){return wt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class $t extends mt{constructor(h){super();ht(this,h,yt,Vt,vt,{})}}export{$t as default,bt as metadata};
