import{S as ht,i as mt,s as vt,e as r,k as c,w as U,t as i,M as gt,c as n,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 m,oe,v,V,W,$,_e,G,we,re,h,Ve,q,be,ye,L,Ee,Qe,N,ke,$e,ne,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/v0.20.0/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/v0.20.0/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/v0.20.0/src/diffusers/models/vq_model.py#L146",returnDescription:`
<p>If return_dict is True, a <a
  href="/docs/diffusers/v0.20.0/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/v0.20.0/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/v0.20.0/src/diffusers/models/vq_model.py#L27"}}),{c(){m=r("meta"),oe=c(),v=r("h1"),V=r("a"),W=r("span"),U($.$$.fragment),_e=c(),G=r("span"),we=i("VQModel"),re=c(),h=r("p"),Ve=i("The VQ-VAE model was introduced in "),q=r("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=r("a"),Ee=i("AutoencoderKL"),Qe=i(", the "),N=r("a"),ke=i("VQModel"),$e=i(" works in a quantized latent space."),ne=c(),z=r("p"),qe=i("The abstract from the paper is:"),se=c(),I=r("p"),J=r("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=r("h2"),b=r("a"),j=r("span"),U(M.$$.fragment),Ae=c(),X=r("span"),Te=i("VQModel"),ie=c(),f=r("div"),U(A.$$.fragment),xe=c(),Y=r("p"),Oe=i("A VQ-VAE model for decoding latent representations."),De=c(),T=r("p"),Pe=i("This model inherits from "),S=r("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=r("div"),U(x.$$.fragment),Ie=c(),O=r("p"),Se=i("The "),K=r("a"),Ke=i("VQModel"),Ue=i(" forward method."),le=c(),_=r("h2"),E=r("a"),Z=r("span"),U(D.$$.fragment),Be=c(),ee=r("span"),Fe=i("VQEncoderOutput"),de=c(),w=r("div"),U(P.$$.fragment),He=c(),te=r("p"),Ce=i("Output of VQModel encoding method."),this.h()},l(e){const d=gt('[data-svelte="svelte-1phssyn"]',document.head);m=n(d,"META",{name:!0,content:!0}),d.forEach(o),oe=u(e),v=n(e,"H1",{class:!0});var ue=s(v);V=n(ue,"A",{id:!0,class:!0,href:!0});var Je=s(V);W=n(Je,"SPAN",{});var je=s(W);B($.$$.fragment,je),je.forEach(o),Je.forEach(o),_e=u(ue),G=n(ue,"SPAN",{});var Xe=s(G);we=l(Xe,"VQModel"),Xe.forEach(o),ue.forEach(o),re=u(e),h=n(e,"P",{});var Q=s(h);Ve=l(Q,"The VQ-VAE model was introduced in "),q=n(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=n(Q,"A",{href:!0});var Ze=s(L);Ee=l(Ze,"AutoencoderKL"),Ze.forEach(o),Qe=l(Q,", the "),N=n(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),ne=u(e),z=n(e,"P",{});var tt=s(z);qe=l(tt,"The abstract from the paper is:"),tt.forEach(o),se=u(e),I=n(e,"P",{});var ot=s(I);J=n(ot,"EM",{});var rt=s(J);Me=l(rt,"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."),rt.forEach(o),ot.forEach(o),ae=u(e),g=n(e,"H2",{class:!0});var pe=s(g);b=n(pe,"A",{id:!0,class:!0,href:!0});var nt=s(b);j=n(nt,"SPAN",{});var st=s(j);B(M.$$.fragment,st),st.forEach(o),nt.forEach(o),Ae=u(pe),X=n(pe,"SPAN",{});var at=s(X);Te=l(at,"VQModel"),at.forEach(o),pe.forEach(o),ie=u(e),f=n(e,"DIV",{class:!0});var k=s(f);B(A.$$.fragment,k),xe=u(k),Y=n(k,"P",{});var it=s(Y);Oe=l(it,"A VQ-VAE model for decoding latent representations."),it.forEach(o),De=u(k),T=n(k,"P",{});var fe=s(T);Pe=l(fe,"This model inherits from "),S=n(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=n(k,"DIV",{class:!0});var he=s(y);B(x.$$.fragment,he),Ie=u(he),O=n(he,"P",{});var me=s(O);Se=l(me,"The "),K=n(me,"A",{href:!0});var dt=s(K);Ke=l(dt,"VQModel"),dt.forEach(o),Ue=l(me," forward method."),me.forEach(o),he.forEach(o),k.forEach(o),le=u(e),_=n(e,"H2",{class:!0});var ve=s(_);E=n(ve,"A",{id:!0,class:!0,href:!0});var ct=s(E);Z=n(ct,"SPAN",{});var ut=s(Z);B(D.$$.fragment,ut),ut.forEach(o),ct.forEach(o),Be=u(ve),ee=n(ve,"SPAN",{});var pt=s(ee);Fe=l(pt,"VQEncoderOutput"),pt.forEach(o),ve.forEach(o),de=u(e),w=n(e,"DIV",{class:!0});var ge=s(w);B(P.$$.fragment,ge),He=u(ge),te=n(ge,"P",{});var ft=s(te);Ce=l(ft,"Output of VQModel encoding method."),ft.forEach(o),ge.forEach(o),this.h()},h(){a(m,"name","hf:doc:metadata"),a(m,"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/v0.20.0/en/api/models/autoencoderkl#diffusers.AutoencoderKL"),a(N,"href","/docs/diffusers/v0.20.0/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/v0.20.0/en/api/models/overview#diffusers.ModelMixin"),a(K,"href","/docs/diffusers/v0.20.0/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,m),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,re,d),p(e,h,d),t(h,Ve),t(h,q),t(q,be),t(h,ye),t(h,L),t(L,Ee),t(h,Qe),t(h,N),t(N,ke),t(h,$e),p(e,ne,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(m),e&&o(oe),e&&o(v),R($),e&&o(re),e&&o(h),e&&o(ne),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 ht{constructor(m){super();mt(this,m,yt,Vt,vt,{})}}export{$t as default,bt as metadata};
