Buckets:

download
raw
18.8 kB
import"../chunks/DsnmJJEf.js";import{i as U,h as A,C as I,H as f,D as s,E as J,s as B,a as W}from"../chunks/DBNuz8hP.js";import{p as G,o as P,s as e,f as y,a as p,b as R,c as t,d as m,n,r as i}from"../chunks/CQ2f15a1.js";import{E as X}from"../chunks/B8yaM6i0.js";const E='{"title":"VQDiffusionScheduler","local":"vqdiffusionscheduler","sections":[{"title":"VQDiffusionScheduler","local":"diffusers.VQDiffusionScheduler","sections":[],"depth":2},{"title":"VQDiffusionSchedulerOutput","local":"diffusers.schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput","sections":[],"depth":2}],"depth":1}';var N=m('<meta name="hf:doc:metadata"/>'),H=m("<p>Calculates the log probabilities for the predicted classes of the image at timestep <code>t-1</code>:</p> <!>",1),$=m(`<p></p> <!> <!> <p><code>VQDiffusionScheduler</code> converts the transformer model’s output into a sample for the unnoised image at the previous diffusion timestep. It was introduced in <a href="https://huggingface.co/papers/2111.14822" rel="nofollow">Vector Quantized Diffusion Model for Text-to-Image Synthesis</a> by Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, Baining Guo.</p> <p>The abstract from the paper is:</p> <p><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></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>A scheduler for vector quantized diffusion.</p> <p>This model inherits from <a href="/docs/diffusers/pr_15249/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a> and <a href="/docs/diffusers/pr_15249/en/api/configuration#diffusers.ConfigMixin">ConfigMixin</a>. Check the superclass documentation for the generic
methods the library implements for all schedulers such as loading and saving.</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>Apply the cumulative transition matrix at a timestep to log probabilities over non-mask classes.</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>Calculates the log probabilities of the rows from the (cumulative or non-cumulative) transition matrix for each
latent pixel in <code>x_t</code>.</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>Sets the discrete timesteps used for the diffusion chain (to be run before inference).</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>Predict the sample from the previous timestep by the reverse transition distribution. See <a href="/docs/diffusers/pr_15249/en/api/schedulers/vq_diffusion#diffusers.VQDiffusionScheduler.q_posterior">q_posterior()</a> for more details about how the distribution is computed.</p></div></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>Output class for the scheduler’s step function output.</p></div> <!> <p></p>`,1);function ee(V,w){G(w,!1),P(()=>{new URLSearchParams(window.location.search).get("fw")}),U();var _=$();A("ljw2yu",o=>{var h=N();B(h,"content",E),p(o,h)});var g=e(y(_),2);I(g,{containerStyle:"float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"});var v=e(g,2);f(v,{title:"VQDiffusionScheduler",local:"vqdiffusionscheduler",headingTag:"h1"});var b=e(v,8);f(b,{title:"VQDiffusionScheduler",local:"diffusers.VQDiffusionScheduler",headingTag:"h2"});var r=e(b,2),x=t(r);s(x,{name:"class diffusers.VQDiffusionScheduler",anchor:"diffusers.VQDiffusionScheduler",source:"https://github.com/huggingface/diffusers/blob/vr_15249/src/diffusers/schedulers/scheduling_vq_diffusion.py#L142",parameters:[{name:"num_vec_classes",val:": int"},{name:"num_train_timesteps",val:": int = 100"},{name:"alpha_cum_start",val:": float = 0.99999"},{name:"alpha_cum_end",val:": float = 9e-06"},{name:"gamma_cum_start",val:": float = 9e-06"},{name:"gamma_cum_end",val:": float = 0.99999"}],parametersDescription:[{anchor:"diffusers.VQDiffusionScheduler.num_vec_classes",description:`<strong>num_vec_classes</strong> (<code>int</code>) &#x2014;
The number of classes of the vector embeddings of the latent pixels. Includes the class for the masked
latent pixel.`,name:"num_vec_classes"},{anchor:"diffusers.VQDiffusionScheduler.num_train_timesteps",description:`<strong>num_train_timesteps</strong> (<code>int</code>, defaults to <code>100</code>) &#x2014;
The number of diffusion steps to train the model.`,name:"num_train_timesteps"},{anchor:"diffusers.VQDiffusionScheduler.alpha_cum_start",description:`<strong>alpha_cum_start</strong> (<code>float</code>, defaults to <code>0.99999</code>) &#x2014;
The starting cumulative alpha value.`,name:"alpha_cum_start"},{anchor:"diffusers.VQDiffusionScheduler.alpha_cum_end",description:`<strong>alpha_cum_end</strong> (<code>float</code>, defaults to <code>0.000009</code>) &#x2014;
The ending cumulative alpha value.`,name:"alpha_cum_end"},{anchor:"diffusers.VQDiffusionScheduler.gamma_cum_start",description:`<strong>gamma_cum_start</strong> (<code>float</code>, defaults to <code>0.000009</code>) &#x2014;
The starting cumulative gamma value.`,name:"gamma_cum_start"},{anchor:"diffusers.VQDiffusionScheduler.gamma_cum_end",description:`<strong>gamma_cum_end</strong> (<code>float</code>, defaults to <code>0.99999</code>) &#x2014;
The ending cumulative gamma value.`,name:"gamma_cum_end"}]});var a=e(x,6),q=t(a);s(q,{name:"apply_cumulative_transitions",anchor:"diffusers.VQDiffusionScheduler.apply_cumulative_transitions",source:"https://github.com/huggingface/diffusers/blob/vr_15249/src/diffusers/schedulers/scheduling_vq_diffusion.py#L491",parameters:[{name:"q",val:": Tensor"},{name:"t",val:": typing.Union[int, torch.Tensor]"}],parametersDescription:[{anchor:"diffusers.VQDiffusionScheduler.apply_cumulative_transitions.q",description:`<strong>q</strong> (<code>torch.Tensor</code> of shape <code>(batch size, num classes - 1, num latent pixels)</code>) &#x2014;
The log probabilities over the non-mask latent pixel classes.`,name:"q"},{anchor:"diffusers.VQDiffusionScheduler.apply_cumulative_transitions.t",description:`<strong>t</strong> (<code>int</code> or <code>torch.Tensor</code>) &#x2014;
The timestep that determines which cumulative transition matrix is used.`,name:"t"}],returnDescription:`
<p>The transitioned log probabilities with the mask class probabilities appended.</p>
`,returnType:`
<p><code>torch.Tensor</code> of shape <code>(batch size, num classes, num latent pixels)</code></p>
`}),n(2),i(a);var c=e(a,2),k=t(c);s(k,{name:"log_Q_t_transitioning_to_known_class",anchor:"diffusers.VQDiffusionScheduler.log_Q_t_transitioning_to_known_class",source:"https://github.com/huggingface/diffusers/blob/vr_15249/src/diffusers/schedulers/scheduling_vq_diffusion.py#L392",parameters:[{name:"t",val:": typing.Union[int, torch.Tensor]"},{name:"x_t",val:": LongTensor"},{name:"log_onehot_x_t",val:": Tensor"},{name:"cumulative",val:": bool"}],parametersDescription:[{anchor:"diffusers.VQDiffusionScheduler.log_Q_t_transitioning_to_known_class.t",description:`<strong>t</strong> (<code>int</code> or <code>torch.Tensor</code>) &#x2014;
The timestep that determines which transition matrix is used.`,name:"t"},{anchor:"diffusers.VQDiffusionScheduler.log_Q_t_transitioning_to_known_class.x_t",description:`<strong>x_t</strong> (<code>torch.LongTensor</code> of shape <code>(batch size, num latent pixels)</code>) &#x2014;
The classes of each latent pixel at time <code>t</code>.`,name:"x_t"},{anchor:"diffusers.VQDiffusionScheduler.log_Q_t_transitioning_to_known_class.log_onehot_x_t",description:`<strong>log_onehot_x_t</strong> (<code>torch.Tensor</code> of shape <code>(batch size, num classes, num latent pixels)</code>) &#x2014;
The log one-hot vectors of <code>x_t</code>.`,name:"log_onehot_x_t"},{anchor:"diffusers.VQDiffusionScheduler.log_Q_t_transitioning_to_known_class.cumulative",description:`<strong>cumulative</strong> (<code>bool</code>) &#x2014;
If cumulative is <code>False</code>, the single step transition matrix <code>t-1</code>-&gt;<code>t</code> is used. If cumulative is
<code>True</code>, the cumulative transition matrix <code>0</code>-&gt;<code>t</code> is used.`,name:"cumulative"}],returnDescription:`
<p>Each <em>column</em> of the returned matrix is a <em>row</em> of log probabilities of the complete probability
transition matrix. The tensor has shape <code>(batch size, num classes - 1, num latent pixels)</code> when
<code>cumulative</code> is <code>True</code> and shape <code>(batch size, num classes, num latent pixels)</code> otherwise.</p>
<p>When cumulative, the tensor has one fewer row because the initial latent pixel cannot be masked.</p>
<p>Where:</p>
<ul>
<li><code>q_n</code> is the probability distribution for the forward process of the <code>n</code>th latent pixel.</li>
<li>C_0 is a class of a latent pixel embedding</li>
<li>C_k is the class of the masked latent pixel</li>
</ul>
<p>non-cumulative result (omitting logarithms):</p>
<div class="code-block relative"><pre class=""><span class="hljs-built_in">q_0</span>(x_t | x_{t-<span class="hljs-number">1</span>} = C_0) ... <span class="hljs-built_in">q_n</span>(x_t | x_{t-<span class="hljs-number">1</span>} = C_0)
. . .
. . .
. . .
<span class="hljs-built_in">q_0</span>(x_t | x_{t-<span class="hljs-number">1</span>} = C_k) ... <span class="hljs-built_in">q_n</span>(x_t | x_{t-<span class="hljs-number">1</span>} = C_k)</pre></div>
<p>cumulative result (omitting logarithms):</p>
<div class="code-block relative"><pre class=""><span class="hljs-built_in">q_0_cumulative</span>(x_t | x_0 = C_0) ... <span class="hljs-built_in">q_n_cumulative</span>(x_t | x_0 = C_0)
. . .
. . .
. . .
<span class="hljs-built_in">q_0_cumulative</span>(x_t | x_0 = C_{k-<span class="hljs-number">1</span>}) ... <span class="hljs-built_in">q_n_cumulative</span>(x_t | x_0 = C_{k-<span class="hljs-number">1</span>})</pre></div>
`,returnType:`
<p><code>torch.Tensor</code></p>
`}),n(2),i(c);var d=e(c,2),D=t(d);s(D,{name:"q_posterior",anchor:"diffusers.VQDiffusionScheduler.q_posterior",source:"https://github.com/huggingface/diffusers/blob/vr_15249/src/diffusers/schedulers/scheduling_vq_diffusion.py#L281",parameters:[{name:"log_p_x_0",val:": Tensor"},{name:"x_t",val:": LongTensor"},{name:"t",val:": typing.Union[int, torch.Tensor]"}],parametersDescription:[{anchor:"diffusers.VQDiffusionScheduler.q_posterior.log_p_x_0",description:`<strong>log_p_x_0</strong> (<code>torch.Tensor</code> of shape <code>(batch size, num classes - 1, num latent pixels)</code>) &#x2014;
The log probabilities for the predicted classes of the initial latent pixels. Does not include a
prediction for the masked class as the initial unnoised image cannot be masked.`,name:"log_p_x_0"},{anchor:"diffusers.VQDiffusionScheduler.q_posterior.x_t",description:`<strong>x_t</strong> (<code>torch.LongTensor</code> of shape <code>(batch size, num latent pixels)</code>) &#x2014;
The classes of each latent pixel at time <code>t</code>.`,name:"x_t"},{anchor:"diffusers.VQDiffusionScheduler.q_posterior.t",description:`<strong>t</strong> (<code>int</code> or <code>torch.Tensor</code>) &#x2014;
The timestep that determines which transition matrix is used.`,name:"t"}],returnDescription:`
<p>The log probabilities for the predicted classes of the image at timestep <code>t-1</code>.</p>
`,returnType:`
<p><code>torch.Tensor</code> of shape <code>(batch size, num classes, num latent pixels)</code></p>
`});var C=e(D,2);X(C,{anchor:"diffusers.VQDiffusionScheduler.q_posterior.example",children:(o,h)=>{var S=H(),O=e(y(S),2);W(O,{code:"cCh4XyU3QnQtMSU3RCUyMCU3QyUyMHhfdCklMjAlM0QlMjBzdW0oJTIwcSh4X3QlMjAlN0MlMjB4XyU3QnQtMSU3RCklMjAqJTIwcSh4XyU3QnQtMSU3RCUyMCU3QyUyMHhfMCklMjAqJTIwcCh4XzApJTIwJTJGJTIwcSh4X3QlMjAlN0MlMjB4XzApJTIwKQ==",highlighted:'p(x_{t-<span class="hljs-number">1</span>} | x_t) = sum( <span class="hljs-string">q(x_t | x_{t-1})</span> * <span class="hljs-string">q(x_{t-1} | x_0)</span> * p(x_0) / <span class="hljs-string">q(x_t | x_0)</span> )',lang:"",wrap:!1}),p(o,S)},$$slots:{default:!0}}),i(d);var l=e(d,2),M=t(l);s(M,{name:"set_timesteps",anchor:"diffusers.VQDiffusionScheduler.set_timesteps",source:"https://github.com/huggingface/diffusers/blob/vr_15249/src/diffusers/schedulers/scheduling_vq_diffusion.py#L214",parameters:[{name:"num_inference_steps",val:": int"},{name:"device",val:": typing.Union[str, torch.device, NoneType] = None"}],parametersDescription:[{anchor:"diffusers.VQDiffusionScheduler.set_timesteps.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>) &#x2014;
The number of diffusion steps used when generating samples with a pre-trained model.`,name:"num_inference_steps"},{anchor:"diffusers.VQDiffusionScheduler.set_timesteps.device",description:`<strong>device</strong> (<code>str</code> or <code>torch.device</code>, <em>optional</em>) &#x2014;
The device to which the timesteps and diffusion process parameters (alpha, beta, gamma) should be moved
to.`,name:"device"}]}),n(2),i(l);var T=e(l,2),j=t(T);s(j,{name:"step",anchor:"diffusers.VQDiffusionScheduler.step",source:"https://github.com/huggingface/diffusers/blob/vr_15249/src/diffusers/schedulers/scheduling_vq_diffusion.py#L236",parameters:[{name:"model_output",val:": Tensor"},{name:"timestep",val:": typing.Union[int, torch.Tensor]"},{name:"sample",val:": LongTensor"},{name:"generator",val:": typing.Optional[torch.Generator] = None"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.VQDiffusionScheduler.step.model_output",description:`<strong>model_output</strong> (<code>torch.Tensor</code> of shape <code>(batch size, num classes - 1, num latent pixels)</code>) &#x2014;
The log probabilities for the predicted classes of the initial latent pixels. Does not include a
prediction for the masked class as the initial unnoised image cannot be masked.`,name:"model_output"},{anchor:"diffusers.VQDiffusionScheduler.step.timestep",description:`<strong>timestep</strong> (<code>int</code> or <code>torch.Tensor</code>) &#x2014;
The timestep that determines which transition matrices are used.`,name:"timestep"},{anchor:"diffusers.VQDiffusionScheduler.step.sample",description:`<strong>sample</strong> (<code>torch.LongTensor</code> of shape <code>(batch size, num latent pixels)</code>) &#x2014;
The classes of each latent pixel at the current timestep.`,name:"sample"},{anchor:"diffusers.VQDiffusionScheduler.step.generator",description:`<strong>generator</strong> (<code>torch.Generator</code>, <em>optional</em>) &#x2014;
A random number generator for the noise applied to <code>p(x_{t-1} | x_t)</code> before it is sampled from.`,name:"generator"},{anchor:"diffusers.VQDiffusionScheduler.step.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/pr_15249/en/api/schedulers/vq_diffusion#diffusers.schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput">VQDiffusionSchedulerOutput</a> or
<code>tuple</code>.`,name:"return_dict"}],returnDescription:`
<p>If return_dict is <code>True</code>, <a
href="/docs/diffusers/pr_15249/en/api/schedulers/vq_diffusion#diffusers.schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput"
>VQDiffusionSchedulerOutput</a> is
returned, otherwise a tuple is returned where the first element is the sample tensor.</p>
`,returnType:`
<p><a
href="/docs/diffusers/pr_15249/en/api/schedulers/vq_diffusion#diffusers.schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput"
>VQDiffusionSchedulerOutput</a> or <code>tuple[torch.LongTensor]</code></p>
`}),n(2),i(T),i(r);var Q=e(r,2);f(Q,{title:"VQDiffusionSchedulerOutput",local:"diffusers.schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput",headingTag:"h2"});var u=e(Q,2),z=t(u);s(z,{name:"class diffusers.schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput",anchor:"diffusers.schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput",source:"https://github.com/huggingface/diffusers/blob/vr_15249/src/diffusers/schedulers/scheduling_vq_diffusion.py#L27",parameters:[{name:"prev_sample",val:": LongTensor"}],parametersDescription:[{anchor:"diffusers.schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput.prev_sample",description:`<strong>prev_sample</strong> (<code>torch.LongTensor</code> of shape <code>(batch size, num latent pixels)</code>) &#x2014;
The computed sample at the previous timestep. <code>prev_sample</code> should be used as the next model input in the
denoising loop.`,name:"prev_sample"}]}),n(2),i(u);var L=e(u,2);J(L,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/schedulers/vq_diffusion.md"}),n(2),p(V,_),R()}export{ee as component};

Xet Storage Details

Size:
18.8 kB
·
Xet hash:
a34153012c0d9fe3f450e0d3d6879a2544fe7ba24345555d296d753587eddd28

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