import{s as we,n as Ce,o as je}from"../chunks/scheduler.8c3d61f6.js";import{S as Le,i as Oe,g as d,s as o,r as l,A as Ie,h as a,f as r,c as n,j as H,u,x as $,k as E,y as i,a as s,v as _,d as g,t as h,w as b}from"../chunks/index.da70eac4.js";import{D as G}from"../chunks/Docstring.ee4b6913.js";import{H as _e,E as Ne}from"../chunks/EditOnGithub.1e64e623.js";function ze(ge){let c,R,U,B,x,F,y,he='The Prior Transformer was originally introduced in <a href="https://huggingface.co/papers/2204.06125" rel="nofollow">Hierarchical Text-Conditional Image Generation with CLIP Latents</a> by Ramesh et al. It is used to predict CLIP image embeddings from CLIP text embeddings; image embeddings are predicted through a denoising diffusion process.',J,w,be="The abstract from the paper is:",K,C,Te="<em>Contrastive models like CLIP have been shown to learn robust representations of images that capture both semantics and style. To leverage these representations for image generation, we propose a two-stage model: a prior that generates a CLIP image embedding given a text caption, and a decoder that generates an image conditioned on the image embedding. We show that explicitly generating image representations improves image diversity with minimal loss in photorealism and caption similarity. Our decoders conditioned on image representations can also produce variations of an image that preserve both its semantics and style, while varying the non-essential details absent from the image representation. Moreover, the joint embedding space of CLIP enables language-guided image manipulations in a zero-shot fashion. We use diffusion models for the decoder and experiment with both autoregressive and diffusion models for the prior, finding that the latter are computationally more efficient and produce higher-quality samples.</em>",Q,j,X,m,L,de,M,ve="A Prior Transformer model.",ae,T,O,me,A,Pe='The <a href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a> forward method.',fe,v,I,ce,S,$e="Sets the attention processor to use to compute attention.",pe,P,N,le,V,xe="Disables custom attention processors and sets the default attention implementation.",Y,z,Z,p,D,ue,q,ye='The output of <a href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a>.',ee,k,re,W,te;return x=new _e({props:{title:"PriorTransformer",local:"priortransformer",headingTag:"h1"}}),j=new _e({props:{title:"PriorTransformer",local:"diffusers.PriorTransformer",headingTag:"h2"}}),L=new G({props:{name:"class diffusers.PriorTransformer",anchor:"diffusers.PriorTransformer",parameters:[{name:"num_attention_heads",val:": int = 32"},{name:"attention_head_dim",val:": int = 64"},{name:"num_layers",val:": int = 20"},{name:"embedding_dim",val:": int = 768"},{name:"num_embeddings",val:" = 77"},{name:"additional_embeddings",val:" = 4"},{name:"dropout",val:": float = 0.0"},{name:"time_embed_act_fn",val:": str = 'silu'"},{name:"norm_in_type",val:": Optional = None"},{name:"embedding_proj_norm_type",val:": Optional = None"},{name:"encoder_hid_proj_type",val:": Optional = 'linear'"},{name:"added_emb_type",val:": Optional = 'prd'"},{name:"time_embed_dim",val:": Optional = None"},{name:"embedding_proj_dim",val:": Optional = None"},{name:"clip_embed_dim",val:": Optional = None"}],parametersDescription:[{anchor:"diffusers.PriorTransformer.num_attention_heads",description:"<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 32) &#x2014; The number of heads to use for multi-head attention.",name:"num_attention_heads"},{anchor:"diffusers.PriorTransformer.attention_head_dim",description:"<strong>attention_head_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014; The number of channels in each head.",name:"attention_head_dim"},{anchor:"diffusers.PriorTransformer.num_layers",description:"<strong>num_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 20) &#x2014; The number of layers of Transformer blocks to use.",name:"num_layers"},{anchor:"diffusers.PriorTransformer.embedding_dim",description:"<strong>embedding_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 768) &#x2014; The dimension of the model input <code>hidden_states</code>",name:"embedding_dim"},{anchor:"diffusers.PriorTransformer.num_embeddings",description:`<strong>num_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to 77) &#x2014;
The number of embeddings of the model input <code>hidden_states</code>`,name:"num_embeddings"},{anchor:"diffusers.PriorTransformer.additional_embeddings",description:`<strong>additional_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014; The number of additional tokens appended to the
projected <code>hidden_states</code>. The actual length of the used <code>hidden_states</code> is <code>num_embeddings + additional_embeddings</code>.`,name:"additional_embeddings"},{anchor:"diffusers.PriorTransformer.dropout",description:"<strong>dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014; The dropout probability to use.",name:"dropout"},{anchor:"diffusers.PriorTransformer.time_embed_act_fn",description:`<strong>time_embed_act_fn</strong> (<code>str</code>, <em>optional</em>, defaults to &#x2018;silu&#x2019;) &#x2014;
The activation function to use to create timestep embeddings.`,name:"time_embed_act_fn"},{anchor:"diffusers.PriorTransformer.norm_in_type",description:`<strong>norm_in_type</strong> (<code>str</code>, <em>optional</em>, defaults to None) &#x2014; The normalization layer to apply on hidden states before
passing to Transformer blocks. Set it to <code>None</code> if normalization is not needed.`,name:"norm_in_type"},{anchor:"diffusers.PriorTransformer.embedding_proj_norm_type",description:`<strong>embedding_proj_norm_type</strong> (<code>str</code>, <em>optional</em>, defaults to None) &#x2014;
The normalization layer to apply on the input <code>proj_embedding</code>. Set it to <code>None</code> if normalization is not
needed.`,name:"embedding_proj_norm_type"},{anchor:"diffusers.PriorTransformer.encoder_hid_proj_type",description:`<strong>encoder_hid_proj_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>linear</code>) &#x2014;
The projection layer to apply on the input <code>encoder_hidden_states</code>. Set it to <code>None</code> if
<code>encoder_hidden_states</code> is <code>None</code>.`,name:"encoder_hid_proj_type"},{anchor:"diffusers.PriorTransformer.added_emb_type",description:`<strong>added_emb_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>prd</code>) &#x2014; Additional embeddings to condition the model.
Choose from <code>prd</code> or <code>None</code>. if choose <code>prd</code>, it will prepend a token indicating the (quantized) dot
product between the text embedding and image embedding as proposed in the unclip paper
<a href="https://arxiv.org/abs/2204.06125" rel="nofollow">https://arxiv.org/abs/2204.06125</a> If it is <code>None</code>, no additional embeddings will be prepended.`,name:"added_emb_type"},{anchor:"diffusers.PriorTransformer.time_embed_dim",description:"<strong>time_embed_dim</strong> (<code>int, *optional*, defaults to None) -- The dimension of timestep embeddings. If None, will be set to </code>num_attention_heads * attention_head_dim`",name:"time_embed_dim"},{anchor:"diffusers.PriorTransformer.embedding_proj_dim",description:`<strong>embedding_proj_dim</strong> (<code>int</code>, <em>optional</em>, default to None) &#x2014;
The dimension of <code>proj_embedding</code>. If None, will be set to <code>embedding_dim</code>.`,name:"embedding_proj_dim"},{anchor:"diffusers.PriorTransformer.clip_embed_dim",description:`<strong>clip_embed_dim</strong> (<code>int</code>, <em>optional</em>, default to None) &#x2014;
The dimension of the output. If None, will be set to <code>embedding_dim</code>.`,name:"clip_embed_dim"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/transformers/prior_transformer.py#L36"}}),O=new G({props:{name:"forward",anchor:"diffusers.PriorTransformer.forward",parameters:[{name:"hidden_states",val:""},{name:"timestep",val:": Union"},{name:"proj_embedding",val:": Tensor"},{name:"encoder_hidden_states",val:": Optional = None"},{name:"attention_mask",val:": Optional = None"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.PriorTransformer.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, embedding_dim)</code>) &#x2014;
The currently predicted image embeddings.`,name:"hidden_states"},{anchor:"diffusers.PriorTransformer.forward.timestep",description:`<strong>timestep</strong> (<code>torch.LongTensor</code>) &#x2014;
Current denoising step.`,name:"timestep"},{anchor:"diffusers.PriorTransformer.forward.proj_embedding",description:`<strong>proj_embedding</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, embedding_dim)</code>) &#x2014;
Projected embedding vector the denoising process is conditioned on.`,name:"proj_embedding"},{anchor:"diffusers.PriorTransformer.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_embeddings, embedding_dim)</code>) &#x2014;
Hidden states of the text embeddings the denoising process is conditioned on.`,name:"encoder_hidden_states"},{anchor:"diffusers.PriorTransformer.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, num_embeddings)</code>) &#x2014;
Text mask for the text embeddings.`,name:"attention_mask"},{anchor:"diffusers.PriorTransformer.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/prior_transformer#diffusers.models.transformers.prior_transformer.PriorTransformerOutput">PriorTransformerOutput</a> instead of
a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/transformers/prior_transformer.py#L245",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>If return_dict is True, a <a
  href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.models.transformers.prior_transformer.PriorTransformerOutput"
>PriorTransformerOutput</a> is
returned, otherwise a tuple is returned where the first element is the sample tensor.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.models.transformers.prior_transformer.PriorTransformerOutput"
>PriorTransformerOutput</a> or <code>tuple</code></p>
`}}),I=new G({props:{name:"set_attn_processor",anchor:"diffusers.PriorTransformer.set_attn_processor",parameters:[{name:"processor",val:": Union"}],parametersDescription:[{anchor:"diffusers.PriorTransformer.set_attn_processor.processor",description:`<strong>processor</strong> (<code>dict</code> of <code>AttentionProcessor</code> or only <code>AttentionProcessor</code>) &#x2014;
The instantiated processor class or a dictionary of processor classes that will be set as the processor
for <strong>all</strong> <code>Attention</code> layers.</p>
<p>If <code>processor</code> is a dict, the key needs to define the path to the corresponding cross attention
processor. This is strongly recommended when setting trainable attention processors.`,name:"processor"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/transformers/prior_transformer.py#L195"}}),N=new G({props:{name:"set_default_attn_processor",anchor:"diffusers.PriorTransformer.set_default_attn_processor",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/transformers/prior_transformer.py#L230"}}),z=new _e({props:{title:"PriorTransformerOutput",local:"diffusers.models.transformers.prior_transformer.PriorTransformerOutput",headingTag:"h2"}}),D=new G({props:{name:"class diffusers.models.transformers.prior_transformer.PriorTransformerOutput",anchor:"diffusers.models.transformers.prior_transformer.PriorTransformerOutput",parameters:[{name:"predicted_image_embedding",val:": Tensor"}],parametersDescription:[{anchor:"diffusers.models.transformers.prior_transformer.PriorTransformerOutput.predicted_image_embedding",description:`<strong>predicted_image_embedding</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, embedding_dim)</code>) &#x2014;
The predicted CLIP image embedding conditioned on the CLIP text embedding input.`,name:"predicted_image_embedding"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/transformers/prior_transformer.py#L23"}}),k=new Ne({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/prior_transformer.md"}}),{c(){c=d("meta"),R=o(),U=d("p"),B=o(),l(x.$$.fragment),F=o(),y=d("p"),y.innerHTML=he,J=o(),w=d("p"),w.textContent=be,K=o(),C=d("p"),C.innerHTML=Te,Q=o(),l(j.$$.fragment),X=o(),m=d("div"),l(L.$$.fragment),de=o(),M=d("p"),M.textContent=ve,ae=o(),T=d("div"),l(O.$$.fragment),me=o(),A=d("p"),A.innerHTML=Pe,fe=o(),v=d("div"),l(I.$$.fragment),ce=o(),S=d("p"),S.textContent=$e,pe=o(),P=d("div"),l(N.$$.fragment),le=o(),V=d("p"),V.textContent=xe,Y=o(),l(z.$$.fragment),Z=o(),p=d("div"),l(D.$$.fragment),ue=o(),q=d("p"),q.innerHTML=ye,ee=o(),l(k.$$.fragment),re=o(),W=d("p"),this.h()},l(e){const t=Ie("svelte-u9bgzb",document.head);c=a(t,"META",{name:!0,content:!0}),t.forEach(r),R=n(e),U=a(e,"P",{}),H(U).forEach(r),B=n(e),u(x.$$.fragment,e),F=n(e),y=a(e,"P",{"data-svelte-h":!0}),$(y)!=="svelte-j0j2ni"&&(y.innerHTML=he),J=n(e),w=a(e,"P",{"data-svelte-h":!0}),$(w)!=="svelte-1cwsb16"&&(w.textContent=be),K=n(e),C=a(e,"P",{"data-svelte-h":!0}),$(C)!=="svelte-ha34c8"&&(C.innerHTML=Te),Q=n(e),u(j.$$.fragment,e),X=n(e),m=a(e,"DIV",{class:!0});var f=H(m);u(L.$$.fragment,f),de=n(f),M=a(f,"P",{"data-svelte-h":!0}),$(M)!=="svelte-jdqpwr"&&(M.textContent=ve),ae=n(f),T=a(f,"DIV",{class:!0});var oe=H(T);u(O.$$.fragment,oe),me=n(oe),A=a(oe,"P",{"data-svelte-h":!0}),$(A)!=="svelte-h5z70v"&&(A.innerHTML=Pe),oe.forEach(r),fe=n(f),v=a(f,"DIV",{class:!0});var ne=H(v);u(I.$$.fragment,ne),ce=n(ne),S=a(ne,"P",{"data-svelte-h":!0}),$(S)!=="svelte-1o77hl2"&&(S.textContent=$e),ne.forEach(r),pe=n(f),P=a(f,"DIV",{class:!0});var se=H(P);u(N.$$.fragment,se),le=n(se),V=a(se,"P",{"data-svelte-h":!0}),$(V)!=="svelte-1lxcwhv"&&(V.textContent=xe),se.forEach(r),f.forEach(r),Y=n(e),u(z.$$.fragment,e),Z=n(e),p=a(e,"DIV",{class:!0});var ie=H(p);u(D.$$.fragment,ie),ue=n(ie),q=a(ie,"P",{"data-svelte-h":!0}),$(q)!=="svelte-1lr1yjr"&&(q.innerHTML=ye),ie.forEach(r),ee=n(e),u(k.$$.fragment,e),re=n(e),W=a(e,"P",{}),H(W).forEach(r),this.h()},h(){E(c,"name","hf:doc:metadata"),E(c,"content",De),E(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(P,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(p,"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){i(document.head,c),s(e,R,t),s(e,U,t),s(e,B,t),_(x,e,t),s(e,F,t),s(e,y,t),s(e,J,t),s(e,w,t),s(e,K,t),s(e,C,t),s(e,Q,t),_(j,e,t),s(e,X,t),s(e,m,t),_(L,m,null),i(m,de),i(m,M),i(m,ae),i(m,T),_(O,T,null),i(T,me),i(T,A),i(m,fe),i(m,v),_(I,v,null),i(v,ce),i(v,S),i(m,pe),i(m,P),_(N,P,null),i(P,le),i(P,V),s(e,Y,t),_(z,e,t),s(e,Z,t),s(e,p,t),_(D,p,null),i(p,ue),i(p,q),s(e,ee,t),_(k,e,t),s(e,re,t),s(e,W,t),te=!0},p:Ce,i(e){te||(g(x.$$.fragment,e),g(j.$$.fragment,e),g(L.$$.fragment,e),g(O.$$.fragment,e),g(I.$$.fragment,e),g(N.$$.fragment,e),g(z.$$.fragment,e),g(D.$$.fragment,e),g(k.$$.fragment,e),te=!0)},o(e){h(x.$$.fragment,e),h(j.$$.fragment,e),h(L.$$.fragment,e),h(O.$$.fragment,e),h(I.$$.fragment,e),h(N.$$.fragment,e),h(z.$$.fragment,e),h(D.$$.fragment,e),h(k.$$.fragment,e),te=!1},d(e){e&&(r(R),r(U),r(B),r(F),r(y),r(J),r(w),r(K),r(C),r(Q),r(X),r(m),r(Y),r(Z),r(p),r(ee),r(re),r(W)),r(c),b(x,e),b(j,e),b(L),b(O),b(I),b(N),b(z,e),b(D),b(k,e)}}}const De='{"title":"PriorTransformer","local":"priortransformer","sections":[{"title":"PriorTransformer","local":"diffusers.PriorTransformer","sections":[],"depth":2},{"title":"PriorTransformerOutput","local":"diffusers.models.transformers.prior_transformer.PriorTransformerOutput","sections":[],"depth":2}],"depth":1}';function ke(ge){return je(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends Le{constructor(c){super(),Oe(this,c,ke,ze,we,{})}}export{Se as component};
