import{s as xe,n as $e,o as Ae}from"../chunks/scheduler.182ea377.js";import{S as we,i as Ce,g as d,s as o,r as g,A as Le,h as a,f as t,c as n,j as F,u as h,x as b,k as V,y as s,a as i,v as P,d as T,t as v,w as y}from"../chunks/index.abf12888.js";import{D as E}from"../chunks/Docstring.93f6f462.js";import{H as le}from"../chunks/Heading.16916d63.js";function je(ue){let f,X,K,q,x,U,$,_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.',W,A,ge="The abstract from the paper is:",B,w,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>",G,C,J,m,L,se,z,be="A Prior Transformer model.",ie,l,j,de,k,Pe='The <a href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a> forward method.',ae,u,O,me,H,Te="Sets the attention processor to use to compute attention.",ce,_,I,fe,M,ve="Disables custom attention processors and sets the default attention implementation.",Q,N,Y,p,D,pe,S,ye='The output of <a href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a>.',Z,R,ee;return x=new le({props:{title:"Prior Transformer",local:"prior-transformer",headingTag:"h1"}}),C=new le({props:{title:"PriorTransformer",local:"diffusers.PriorTransformer",headingTag:"h2"}}),L=new E({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:": typing.Optional[str] = None"},{name:"embedding_proj_norm_type",val:": typing.Optional[str] = None"},{name:"encoder_hid_proj_type",val:": typing.Optional[str] = 'linear'"},{name:"added_emb_type",val:": typing.Optional[str] = 'prd'"},{name:"time_embed_dim",val:": typing.Optional[int] = None"},{name:"embedding_proj_dim",val:": typing.Optional[int] = None"},{name:"clip_embed_dim",val:": typing.Optional[int] = 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/prior_transformer.py#L36"}}),j=new E({props:{name:"forward",anchor:"diffusers.PriorTransformer.forward",parameters:[{name:"hidden_states",val:""},{name:"timestep",val:": typing.Union[torch.Tensor, float, int]"},{name:"proj_embedding",val:": FloatTensor"},{name:"encoder_hidden_states",val:": typing.Optional[torch.FloatTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.BoolTensor] = 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 <a href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.models.prior_transformer.PriorTransformerOutput">PriorTransformerOutput</a> instead of a plain
tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/prior_transformer.py#L247",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.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.prior_transformer.PriorTransformerOutput"
>PriorTransformerOutput</a> or <code>tuple</code></p>
`}}),O=new E({props:{name:"set_attn_processor",anchor:"diffusers.PriorTransformer.set_attn_processor",parameters:[{name:"processor",val:": typing.Union[diffusers.models.attention_processor.AttnProcessor, diffusers.models.attention_processor.AttnProcessor2_0, diffusers.models.attention_processor.XFormersAttnProcessor, diffusers.models.attention_processor.SlicedAttnProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor, diffusers.models.attention_processor.SlicedAttnAddedKVProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor2_0, diffusers.models.attention_processor.XFormersAttnAddedKVProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor, diffusers.models.attention_processor.CustomDiffusionXFormersAttnProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor2_0, diffusers.models.attention_processor.LoRAAttnProcessor, diffusers.models.attention_processor.LoRAAttnProcessor2_0, diffusers.models.attention_processor.LoRAXFormersAttnProcessor, diffusers.models.attention_processor.LoRAAttnAddedKVProcessor, typing.Dict[str, typing.Union[diffusers.models.attention_processor.AttnProcessor, diffusers.models.attention_processor.AttnProcessor2_0, diffusers.models.attention_processor.XFormersAttnProcessor, diffusers.models.attention_processor.SlicedAttnProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor, diffusers.models.attention_processor.SlicedAttnAddedKVProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor2_0, diffusers.models.attention_processor.XFormersAttnAddedKVProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor, diffusers.models.attention_processor.CustomDiffusionXFormersAttnProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor2_0, diffusers.models.attention_processor.LoRAAttnProcessor, diffusers.models.attention_processor.LoRAAttnProcessor2_0, diffusers.models.attention_processor.LoRAXFormersAttnProcessor, diffusers.models.attention_processor.LoRAAttnAddedKVProcessor]]]"},{name:"_remove_lora",val:" = False"}],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/prior_transformer.py#L195"}}),I=new E({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/prior_transformer.py#L232"}}),N=new le({props:{title:"PriorTransformerOutput",local:"diffusers.models.prior_transformer.PriorTransformerOutput",headingTag:"h2"}}),D=new E({props:{name:"class diffusers.models.prior_transformer.PriorTransformerOutput",anchor:"diffusers.models.prior_transformer.PriorTransformerOutput",parameters:[{name:"predicted_image_embedding",val:": FloatTensor"}],parametersDescription:[{anchor:"diffusers.models.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/main/src/diffusers/models/prior_transformer.py#L24"}}),{c(){f=d("meta"),X=o(),K=d("p"),q=o(),g(x.$$.fragment),U=o(),$=d("p"),$.innerHTML=_e,W=o(),A=d("p"),A.textContent=ge,B=o(),w=d("p"),w.innerHTML=he,G=o(),g(C.$$.fragment),J=o(),m=d("div"),g(L.$$.fragment),se=o(),z=d("p"),z.textContent=be,ie=o(),l=d("div"),g(j.$$.fragment),de=o(),k=d("p"),k.innerHTML=Pe,ae=o(),u=d("div"),g(O.$$.fragment),me=o(),H=d("p"),H.textContent=Te,ce=o(),_=d("div"),g(I.$$.fragment),fe=o(),M=d("p"),M.textContent=ve,Q=o(),g(N.$$.fragment),Y=o(),p=d("div"),g(D.$$.fragment),pe=o(),S=d("p"),S.innerHTML=ye,Z=o(),R=d("p"),this.h()},l(e){const r=Le("svelte-u9bgzb",document.head);f=a(r,"META",{name:!0,content:!0}),r.forEach(t),X=n(e),K=a(e,"P",{}),F(K).forEach(t),q=n(e),h(x.$$.fragment,e),U=n(e),$=a(e,"P",{"data-svelte-h":!0}),b($)!=="svelte-1t92tiq"&&($.innerHTML=_e),W=n(e),A=a(e,"P",{"data-svelte-h":!0}),b(A)!=="svelte-1cwsb16"&&(A.textContent=ge),B=n(e),w=a(e,"P",{"data-svelte-h":!0}),b(w)!=="svelte-ha34c8"&&(w.innerHTML=he),G=n(e),h(C.$$.fragment,e),J=n(e),m=a(e,"DIV",{class:!0});var c=F(m);h(L.$$.fragment,c),se=n(c),z=a(c,"P",{"data-svelte-h":!0}),b(z)!=="svelte-jdqpwr"&&(z.textContent=be),ie=n(c),l=a(c,"DIV",{class:!0});var te=F(l);h(j.$$.fragment,te),de=n(te),k=a(te,"P",{"data-svelte-h":!0}),b(k)!=="svelte-h5z70v"&&(k.innerHTML=Pe),te.forEach(t),ae=n(c),u=a(c,"DIV",{class:!0});var re=F(u);h(O.$$.fragment,re),me=n(re),H=a(re,"P",{"data-svelte-h":!0}),b(H)!=="svelte-1o77hl2"&&(H.textContent=Te),re.forEach(t),ce=n(c),_=a(c,"DIV",{class:!0});var oe=F(_);h(I.$$.fragment,oe),fe=n(oe),M=a(oe,"P",{"data-svelte-h":!0}),b(M)!=="svelte-1lxcwhv"&&(M.textContent=ve),oe.forEach(t),c.forEach(t),Q=n(e),h(N.$$.fragment,e),Y=n(e),p=a(e,"DIV",{class:!0});var ne=F(p);h(D.$$.fragment,ne),pe=n(ne),S=a(ne,"P",{"data-svelte-h":!0}),b(S)!=="svelte-1lr1yjr"&&(S.innerHTML=ye),ne.forEach(t),Z=n(e),R=a(e,"P",{}),F(R).forEach(t),this.h()},h(){V(f,"name","hf:doc:metadata"),V(f,"content",Oe),V(l,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),V(u,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),V(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),V(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),V(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,X,r),i(e,K,r),i(e,q,r),P(x,e,r),i(e,U,r),i(e,$,r),i(e,W,r),i(e,A,r),i(e,B,r),i(e,w,r),i(e,G,r),P(C,e,r),i(e,J,r),i(e,m,r),P(L,m,null),s(m,se),s(m,z),s(m,ie),s(m,l),P(j,l,null),s(l,de),s(l,k),s(m,ae),s(m,u),P(O,u,null),s(u,me),s(u,H),s(m,ce),s(m,_),P(I,_,null),s(_,fe),s(_,M),i(e,Q,r),P(N,e,r),i(e,Y,r),i(e,p,r),P(D,p,null),s(p,pe),s(p,S),i(e,Z,r),i(e,R,r),ee=!0},p:$e,i(e){ee||(T(x.$$.fragment,e),T(C.$$.fragment,e),T(L.$$.fragment,e),T(j.$$.fragment,e),T(O.$$.fragment,e),T(I.$$.fragment,e),T(N.$$.fragment,e),T(D.$$.fragment,e),ee=!0)},o(e){v(x.$$.fragment,e),v(C.$$.fragment,e),v(L.$$.fragment,e),v(j.$$.fragment,e),v(O.$$.fragment,e),v(I.$$.fragment,e),v(N.$$.fragment,e),v(D.$$.fragment,e),ee=!1},d(e){e&&(t(X),t(K),t(q),t(U),t($),t(W),t(A),t(B),t(w),t(G),t(J),t(m),t(Q),t(Y),t(p),t(Z),t(R)),t(f),y(x,e),y(C,e),y(L),y(j),y(O),y(I),y(N,e),y(D)}}}const Oe='{"title":"Prior Transformer","local":"prior-transformer","sections":[{"title":"PriorTransformer","local":"diffusers.PriorTransformer","sections":[],"depth":2},{"title":"PriorTransformerOutput","local":"diffusers.models.prior_transformer.PriorTransformerOutput","sections":[],"depth":2}],"depth":1}';function Ie(ue){return Ae(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ze extends we{constructor(f){super(),Ce(this,f,Ie,je,xe,{})}}export{ze as component};
