import{s as Ce,n as je,o as Le}from"../chunks/scheduler.8c3d61f6.js";import{S as Oe,i as Ie,g as i,s as o,r as g,A as Ne,h as d,f as r,c as n,j as H,u as b,x as l,k as E,y as a,a as s,v as T,d as v,t as P,w as x}from"../chunks/index.589a98e8.js";import{D as G}from"../chunks/Docstring.27406313.js";import{H as we,E as ze}from"../chunks/EditOnGithub.e5a8d9cb.js";function De(_e){let c,R,U,B,$,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,ge="The abstract from the paper is:",K,C,be="<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,Te="A Prior Transformer model.",ae,u,O,me,A,ve='The <a href="/docs/diffusers/pr_8376/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a> forward method.',fe,_,I,ce,S,Pe="Sets the attention processor to use to compute attention.",pe,h,N,le,V,xe="Disables custom attention processors and sets the default attention implementation.",Y,z,$e="## PriorTransformerOutput[[diffusers.models.transformers.prior_transformer.PriorTransformerOutput]]",Z,p,D,ue,q,ye='The output of <a href="/docs/diffusers/pr_8376/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a>.',ee,k,re,W,te;return $=new we({props:{title:"PriorTransformer",local:"priortransformer",headingTag:"h1"}}),j=new we({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/vr_8376/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/pr_8376/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/vr_8376/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/pr_8376/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/pr_8376/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/vr_8376/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/vr_8376/src/diffusers/models/transformers/prior_transformer.py#L230"}}),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/vr_8376/src/diffusers/models/transformers/prior_transformer.py#L23"}}),k=new ze({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/prior_transformer.md"}}),{c(){c=i("meta"),R=o(),U=i("p"),B=o(),g($.$$.fragment),F=o(),y=i("p"),y.innerHTML=he,J=o(),w=i("p"),w.textContent=ge,K=o(),C=i("p"),C.innerHTML=be,Q=o(),g(j.$$.fragment),X=o(),m=i("div"),g(L.$$.fragment),de=o(),M=i("p"),M.textContent=Te,ae=o(),u=i("div"),g(O.$$.fragment),me=o(),A=i("p"),A.innerHTML=ve,fe=o(),_=i("div"),g(I.$$.fragment),ce=o(),S=i("p"),S.textContent=Pe,pe=o(),h=i("div"),g(N.$$.fragment),le=o(),V=i("p"),V.textContent=xe,Y=o(),z=i("p"),z.textContent=$e,Z=o(),p=i("div"),g(D.$$.fragment),ue=o(),q=i("p"),q.innerHTML=ye,ee=o(),g(k.$$.fragment),re=o(),W=i("p"),this.h()},l(e){const t=Ne("svelte-u9bgzb",document.head);c=d(t,"META",{name:!0,content:!0}),t.forEach(r),R=n(e),U=d(e,"P",{}),H(U).forEach(r),B=n(e),b($.$$.fragment,e),F=n(e),y=d(e,"P",{"data-svelte-h":!0}),l(y)!=="svelte-j0j2ni"&&(y.innerHTML=he),J=n(e),w=d(e,"P",{"data-svelte-h":!0}),l(w)!=="svelte-1cwsb16"&&(w.textContent=ge),K=n(e),C=d(e,"P",{"data-svelte-h":!0}),l(C)!=="svelte-ha34c8"&&(C.innerHTML=be),Q=n(e),b(j.$$.fragment,e),X=n(e),m=d(e,"DIV",{class:!0});var f=H(m);b(L.$$.fragment,f),de=n(f),M=d(f,"P",{"data-svelte-h":!0}),l(M)!=="svelte-jdqpwr"&&(M.textContent=Te),ae=n(f),u=d(f,"DIV",{class:!0});var oe=H(u);b(O.$$.fragment,oe),me=n(oe),A=d(oe,"P",{"data-svelte-h":!0}),l(A)!=="svelte-1ohn9nz"&&(A.innerHTML=ve),oe.forEach(r),fe=n(f),_=d(f,"DIV",{class:!0});var ne=H(_);b(I.$$.fragment,ne),ce=n(ne),S=d(ne,"P",{"data-svelte-h":!0}),l(S)!=="svelte-1o77hl2"&&(S.textContent=Pe),ne.forEach(r),pe=n(f),h=d(f,"DIV",{class:!0});var se=H(h);b(N.$$.fragment,se),le=n(se),V=d(se,"P",{"data-svelte-h":!0}),l(V)!=="svelte-1lxcwhv"&&(V.textContent=xe),se.forEach(r),f.forEach(r),Y=n(e),z=d(e,"P",{"data-svelte-h":!0}),l(z)!=="svelte-re3ptv"&&(z.textContent=$e),Z=n(e),p=d(e,"DIV",{class:!0});var ie=H(p);b(D.$$.fragment,ie),ue=n(ie),q=d(ie,"P",{"data-svelte-h":!0}),l(q)!=="svelte-14jz945"&&(q.innerHTML=ye),ie.forEach(r),ee=n(e),b(k.$$.fragment,e),re=n(e),W=d(e,"P",{}),H(W).forEach(r),this.h()},h(){E(c,"name","hf:doc:metadata"),E(c,"content",ke),E(u,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(h,"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){a(document.head,c),s(e,R,t),s(e,U,t),s(e,B,t),T($,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),T(j,e,t),s(e,X,t),s(e,m,t),T(L,m,null),a(m,de),a(m,M),a(m,ae),a(m,u),T(O,u,null),a(u,me),a(u,A),a(m,fe),a(m,_),T(I,_,null),a(_,ce),a(_,S),a(m,pe),a(m,h),T(N,h,null),a(h,le),a(h,V),s(e,Y,t),s(e,z,t),s(e,Z,t),s(e,p,t),T(D,p,null),a(p,ue),a(p,q),s(e,ee,t),T(k,e,t),s(e,re,t),s(e,W,t),te=!0},p:je,i(e){te||(v($.$$.fragment,e),v(j.$$.fragment,e),v(L.$$.fragment,e),v(O.$$.fragment,e),v(I.$$.fragment,e),v(N.$$.fragment,e),v(D.$$.fragment,e),v(k.$$.fragment,e),te=!0)},o(e){P($.$$.fragment,e),P(j.$$.fragment,e),P(L.$$.fragment,e),P(O.$$.fragment,e),P(I.$$.fragment,e),P(N.$$.fragment,e),P(D.$$.fragment,e),P(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(Z),r(p),r(ee),r(re),r(W)),r(c),x($,e),x(j,e),x(L),x(O),x(I),x(N),x(D),x(k,e)}}}const ke='{"title":"PriorTransformer","local":"priortransformer","sections":[{"title":"PriorTransformer","local":"diffusers.PriorTransformer","sections":[],"depth":2}],"depth":1}';function He(_e){return Le(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ve extends Oe{constructor(c){super(),Ie(this,c,He,De,Ce,{})}}export{Ve as component};
