import{s as $e,n as Pe,o as ve}from"../chunks/scheduler.53228c21.js";import{S as ye,i as xe,e as s,s as n,c,h as we,a as d,d as t,b as i,f as S,g as l,j as M,k as q,l as m,m as o,n as u,t as g,o as _,p as h}from"../chunks/index.100fac89.js";import{C as Ce}from"../chunks/CopyLLMTxtMenu.20a72e0e.js";import{D as ne}from"../chunks/Docstring.49101787.js";import{H as pe,E as je}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.4d82655d.js";function Le(ce){let f,W,V,B,P,G,v,R,y,le='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.',U,x,ue="The abstract from the paper is:",F,w,ge="<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>",J,C,K,a,j,ie,H,_e="A Prior Transformer model.",se,b,L,de,k,he='The <a href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a> forward method.',ae,T,O,me,D,be="Disables custom attention processors and sets the default attention implementation.",Q,N,X,p,I,fe,E,Te='The output of <a href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a>.',Y,z,Z,A,ee;return P=new Ce({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),v=new pe({props:{title:"PriorTransformer",local:"priortransformer",headingTag:"h1"}}),C=new pe({props:{title:"PriorTransformer",local:"diffusers.PriorTransformer",headingTag:"h2"}}),j=new ne({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://huggingface.co/papers/2204.06125" rel="nofollow">https://huggingface.co/papers/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#L35"}}),L=new ne({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:": Tensor"},{name:"encoder_hidden_states",val:": typing.Optional[torch.Tensor] = 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.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#L184",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>
`}}),O=new ne({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#L169"}}),N=new pe({props:{title:"PriorTransformerOutput",local:"diffusers.models.transformers.prior_transformer.PriorTransformerOutput",headingTag:"h2"}}),I=new ne({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"}}),z=new je({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/prior_transformer.md"}}),{c(){f=s("meta"),W=n(),V=s("p"),B=n(),c(P.$$.fragment),G=n(),c(v.$$.fragment),R=n(),y=s("p"),y.innerHTML=le,U=n(),x=s("p"),x.textContent=ue,F=n(),w=s("p"),w.innerHTML=ge,J=n(),c(C.$$.fragment),K=n(),a=s("div"),c(j.$$.fragment),ie=n(),H=s("p"),H.textContent=_e,se=n(),b=s("div"),c(L.$$.fragment),de=n(),k=s("p"),k.innerHTML=he,ae=n(),T=s("div"),c(O.$$.fragment),me=n(),D=s("p"),D.textContent=be,Q=n(),c(N.$$.fragment),X=n(),p=s("div"),c(I.$$.fragment),fe=n(),E=s("p"),E.innerHTML=Te,Y=n(),c(z.$$.fragment),Z=n(),A=s("p"),this.h()},l(e){const r=we("svelte-u9bgzb",document.head);f=d(r,"META",{name:!0,content:!0}),r.forEach(t),W=i(e),V=d(e,"P",{}),S(V).forEach(t),B=i(e),l(P.$$.fragment,e),G=i(e),l(v.$$.fragment,e),R=i(e),y=d(e,"P",{"data-svelte-h":!0}),M(y)!=="svelte-j0j2ni"&&(y.innerHTML=le),U=i(e),x=d(e,"P",{"data-svelte-h":!0}),M(x)!=="svelte-1cwsb16"&&(x.textContent=ue),F=i(e),w=d(e,"P",{"data-svelte-h":!0}),M(w)!=="svelte-ha34c8"&&(w.innerHTML=ge),J=i(e),l(C.$$.fragment,e),K=i(e),a=d(e,"DIV",{class:!0});var $=S(a);l(j.$$.fragment,$),ie=i($),H=d($,"P",{"data-svelte-h":!0}),M(H)!=="svelte-jdqpwr"&&(H.textContent=_e),se=i($),b=d($,"DIV",{class:!0});var re=S(b);l(L.$$.fragment,re),de=i(re),k=d(re,"P",{"data-svelte-h":!0}),M(k)!=="svelte-h5z70v"&&(k.innerHTML=he),re.forEach(t),ae=i($),T=d($,"DIV",{class:!0});var te=S(T);l(O.$$.fragment,te),me=i(te),D=d(te,"P",{"data-svelte-h":!0}),M(D)!=="svelte-1lxcwhv"&&(D.textContent=be),te.forEach(t),$.forEach(t),Q=i(e),l(N.$$.fragment,e),X=i(e),p=d(e,"DIV",{class:!0});var oe=S(p);l(I.$$.fragment,oe),fe=i(oe),E=d(oe,"P",{"data-svelte-h":!0}),M(E)!=="svelte-1lr1yjr"&&(E.innerHTML=Te),oe.forEach(t),Y=i(e),l(z.$$.fragment,e),Z=i(e),A=d(e,"P",{}),S(A).forEach(t),this.h()},h(){q(f,"name","hf:doc:metadata"),q(f,"content",Oe),q(b,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),q(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),q(a,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),q(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){m(document.head,f),o(e,W,r),o(e,V,r),o(e,B,r),u(P,e,r),o(e,G,r),u(v,e,r),o(e,R,r),o(e,y,r),o(e,U,r),o(e,x,r),o(e,F,r),o(e,w,r),o(e,J,r),u(C,e,r),o(e,K,r),o(e,a,r),u(j,a,null),m(a,ie),m(a,H),m(a,se),m(a,b),u(L,b,null),m(b,de),m(b,k),m(a,ae),m(a,T),u(O,T,null),m(T,me),m(T,D),o(e,Q,r),u(N,e,r),o(e,X,r),o(e,p,r),u(I,p,null),m(p,fe),m(p,E),o(e,Y,r),u(z,e,r),o(e,Z,r),o(e,A,r),ee=!0},p:Pe,i(e){ee||(g(P.$$.fragment,e),g(v.$$.fragment,e),g(C.$$.fragment,e),g(j.$$.fragment,e),g(L.$$.fragment,e),g(O.$$.fragment,e),g(N.$$.fragment,e),g(I.$$.fragment,e),g(z.$$.fragment,e),ee=!0)},o(e){_(P.$$.fragment,e),_(v.$$.fragment,e),_(C.$$.fragment,e),_(j.$$.fragment,e),_(L.$$.fragment,e),_(O.$$.fragment,e),_(N.$$.fragment,e),_(I.$$.fragment,e),_(z.$$.fragment,e),ee=!1},d(e){e&&(t(W),t(V),t(B),t(G),t(R),t(y),t(U),t(x),t(F),t(w),t(J),t(K),t(a),t(Q),t(X),t(p),t(Y),t(Z),t(A)),t(f),h(P,e),h(v,e),h(C,e),h(j),h(L),h(O),h(N,e),h(I),h(z,e)}}}const Oe='{"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 Ne(ce){return ve(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class De extends ye{constructor(f){super(),xe(this,f,Ne,Le,$e,{})}}export{De as component};
