import{s as $e,n as ye,o as we}from"../chunks/scheduler.182ea377.js";import{S as Ce,i as je,g as d,s as o,r as g,A as Le,h as a,f as t,c as n,j as D,u as h,x as b,k as H,y as s,a as i,v as T,d as v,t as P,w as x}from"../chunks/index.abf12888.js";import{D as U}from"../chunks/Docstring.93f6f462.js";import{H as le}from"../chunks/Heading.16916d63.js";function Ie(ue){let f,W,V,R,$,B,y,_e='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.',G,w,ge="The abstract from the paper is:",J,C,he="<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>",K,j,Q,m,L,se,M,be="A Prior Transformer model.",ie,l,I,de,E,Te='The <a href="/docs/diffusers/v0.26.1/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a> forward method.',ae,u,N,me,A,ve="Sets the attention processor to use to compute attention.",ce,_,O,fe,S,Pe="Disables custom attention processors and sets the default attention implementation.",X,k,Y,p,z,pe,F,xe='The output of <a href="/docs/diffusers/v0.26.1/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a>.',Z,q,ee;return $=new le({props:{title:"Prior Transformer",local:"prior-transformer",headingTag:"h1"}}),j=new le({props:{title:"PriorTransformer",local:"diffusers.PriorTransformer",headingTag:"h2"}}),L=new U({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/v0.26.1/src/diffusers/models/transformers/prior_transformer.py#L36"}}),I=new U({props:{name:"forward",anchor:"diffusers.PriorTransformer.forward",parameters:[{name:"hidden_states",val:""},{name:"timestep",val:": Union"},{name:"proj_embedding",val:": FloatTensor"},{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.FloatTensor</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.FloatTensor</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.FloatTensor</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 <code>~models.prior_transformer.PriorTransformerOutput</code> instead of a plain
tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/v0.26.1/src/diffusers/models/transformers/prior_transformer.py#L245",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>If return_dict is True, a <code>~models.prior_transformer.PriorTransformerOutput</code> 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><code>~models.prior_transformer.PriorTransformerOutput</code> or <code>tuple</code></p>
`}}),N=new U({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/v0.26.1/src/diffusers/models/transformers/prior_transformer.py#L195"}}),O=new U({props:{name:"set_default_attn_processor",anchor:"diffusers.PriorTransformer.set_default_attn_processor",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.26.1/src/diffusers/models/transformers/prior_transformer.py#L230"}}),k=new le({props:{title:"PriorTransformerOutput",local:"diffusers.models.transformers.prior_transformer.PriorTransformerOutput",headingTag:"h2"}}),z=new U({props:{name:"class diffusers.models.transformers.prior_transformer.PriorTransformerOutput",anchor:"diffusers.models.transformers.prior_transformer.PriorTransformerOutput",parameters:[{name:"predicted_image_embedding",val:": FloatTensor"}],parametersDescription:[{anchor:"diffusers.models.transformers.prior_transformer.PriorTransformerOutput.predicted_image_embedding",description:`<strong>predicted_image_embedding</strong> (<code>torch.FloatTensor</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/v0.26.1/src/diffusers/models/transformers/prior_transformer.py#L23"}}),{c(){f=d("meta"),W=o(),V=d("p"),R=o(),g($.$$.fragment),B=o(),y=d("p"),y.innerHTML=_e,G=o(),w=d("p"),w.textContent=ge,J=o(),C=d("p"),C.innerHTML=he,K=o(),g(j.$$.fragment),Q=o(),m=d("div"),g(L.$$.fragment),se=o(),M=d("p"),M.textContent=be,ie=o(),l=d("div"),g(I.$$.fragment),de=o(),E=d("p"),E.innerHTML=Te,ae=o(),u=d("div"),g(N.$$.fragment),me=o(),A=d("p"),A.textContent=ve,ce=o(),_=d("div"),g(O.$$.fragment),fe=o(),S=d("p"),S.textContent=Pe,X=o(),g(k.$$.fragment),Y=o(),p=d("div"),g(z.$$.fragment),pe=o(),F=d("p"),F.innerHTML=xe,Z=o(),q=d("p"),this.h()},l(e){const r=Le("svelte-u9bgzb",document.head);f=a(r,"META",{name:!0,content:!0}),r.forEach(t),W=n(e),V=a(e,"P",{}),D(V).forEach(t),R=n(e),h($.$$.fragment,e),B=n(e),y=a(e,"P",{"data-svelte-h":!0}),b(y)!=="svelte-j0j2ni"&&(y.innerHTML=_e),G=n(e),w=a(e,"P",{"data-svelte-h":!0}),b(w)!=="svelte-1cwsb16"&&(w.textContent=ge),J=n(e),C=a(e,"P",{"data-svelte-h":!0}),b(C)!=="svelte-ha34c8"&&(C.innerHTML=he),K=n(e),h(j.$$.fragment,e),Q=n(e),m=a(e,"DIV",{class:!0});var c=D(m);h(L.$$.fragment,c),se=n(c),M=a(c,"P",{"data-svelte-h":!0}),b(M)!=="svelte-jdqpwr"&&(M.textContent=be),ie=n(c),l=a(c,"DIV",{class:!0});var te=D(l);h(I.$$.fragment,te),de=n(te),E=a(te,"P",{"data-svelte-h":!0}),b(E)!=="svelte-mf8tpz"&&(E.innerHTML=Te),te.forEach(t),ae=n(c),u=a(c,"DIV",{class:!0});var re=D(u);h(N.$$.fragment,re),me=n(re),A=a(re,"P",{"data-svelte-h":!0}),b(A)!=="svelte-1o77hl2"&&(A.textContent=ve),re.forEach(t),ce=n(c),_=a(c,"DIV",{class:!0});var oe=D(_);h(O.$$.fragment,oe),fe=n(oe),S=a(oe,"P",{"data-svelte-h":!0}),b(S)!=="svelte-1lxcwhv"&&(S.textContent=Pe),oe.forEach(t),c.forEach(t),X=n(e),h(k.$$.fragment,e),Y=n(e),p=a(e,"DIV",{class:!0});var ne=D(p);h(z.$$.fragment,ne),pe=n(ne),F=a(ne,"P",{"data-svelte-h":!0}),b(F)!=="svelte-1khsr37"&&(F.innerHTML=xe),ne.forEach(t),Z=n(e),q=a(e,"P",{}),D(q).forEach(t),this.h()},h(){H(f,"name","hf:doc:metadata"),H(f,"content",Ne),H(l,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(u,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(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,r){s(document.head,f),i(e,W,r),i(e,V,r),i(e,R,r),T($,e,r),i(e,B,r),i(e,y,r),i(e,G,r),i(e,w,r),i(e,J,r),i(e,C,r),i(e,K,r),T(j,e,r),i(e,Q,r),i(e,m,r),T(L,m,null),s(m,se),s(m,M),s(m,ie),s(m,l),T(I,l,null),s(l,de),s(l,E),s(m,ae),s(m,u),T(N,u,null),s(u,me),s(u,A),s(m,ce),s(m,_),T(O,_,null),s(_,fe),s(_,S),i(e,X,r),T(k,e,r),i(e,Y,r),i(e,p,r),T(z,p,null),s(p,pe),s(p,F),i(e,Z,r),i(e,q,r),ee=!0},p:ye,i(e){ee||(v($.$$.fragment,e),v(j.$$.fragment,e),v(L.$$.fragment,e),v(I.$$.fragment,e),v(N.$$.fragment,e),v(O.$$.fragment,e),v(k.$$.fragment,e),v(z.$$.fragment,e),ee=!0)},o(e){P($.$$.fragment,e),P(j.$$.fragment,e),P(L.$$.fragment,e),P(I.$$.fragment,e),P(N.$$.fragment,e),P(O.$$.fragment,e),P(k.$$.fragment,e),P(z.$$.fragment,e),ee=!1},d(e){e&&(t(W),t(V),t(R),t(B),t(y),t(G),t(w),t(J),t(C),t(K),t(Q),t(m),t(X),t(Y),t(p),t(Z),t(q)),t(f),x($,e),x(j,e),x(L),x(I),x(N),x(O),x(k,e),x(z)}}}const Ne='{"title":"Prior Transformer","local":"prior-transformer","sections":[{"title":"PriorTransformer","local":"diffusers.PriorTransformer","sections":[],"depth":2},{"title":"PriorTransformerOutput","local":"diffusers.models.transformers.prior_transformer.PriorTransformerOutput","sections":[],"depth":2}],"depth":1}';function Oe(ue){return we(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Me extends Ce{constructor(f){super(),je(this,f,Oe,Ie,$e,{})}}export{Me as component};
