import{s as Ce,n as je,o as Le}from"../chunks/scheduler.182ea377.js";import{S as Ie,i as Ne,g as i,s as o,r as h,A as Oe,h as d,f as t,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.abf12888.js";import{D as G}from"../chunks/Docstring.b0ac41bc.js";import{H as we,E as De}from"../chunks/EditOnGithub.9b8e78e4.js";function ke(_e){let f,R,U,B,$,F,y,ge='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,he="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,I,me,A,ve='The <a href="/docs/diffusers/v0.28.2/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a> forward method.',ce,_,N,fe,S,Pe="Sets the attention processor to use to compute attention.",pe,g,O,le,q,xe="Disables custom attention processors and sets the default attention implementation.",Y,D,$e="## PriorTransformerOutput[[diffusers.models.transformers.prior_transformer.PriorTransformerOutput]]",Z,p,k,ue,V,ye='The output of <a href="/docs/diffusers/v0.28.2/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a>.',ee,z,te,W,re;return $=new we({props:{title:"Prior Transformer",local:"prior-transformer",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/v0.28.2/src/diffusers/models/transformers/prior_transformer.py#L36"}}),I=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 <code>~models.prior_transformer.PriorTransformerOutput</code> instead of a plain
tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/v0.28.2/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 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/v0.28.2/src/diffusers/models/transformers/prior_transformer.py#L195"}}),O=new G({props:{name:"set_default_attn_processor",anchor:"diffusers.PriorTransformer.set_default_attn_processor",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.28.2/src/diffusers/models/transformers/prior_transformer.py#L230"}}),k=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/v0.28.2/src/diffusers/models/transformers/prior_transformer.py#L23"}}),z=new De({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/prior_transformer.md"}}),{c(){f=i("meta"),R=o(),U=i("p"),B=o(),h($.$$.fragment),F=o(),y=i("p"),y.innerHTML=ge,J=o(),w=i("p"),w.textContent=he,K=o(),C=i("p"),C.innerHTML=be,Q=o(),h(j.$$.fragment),X=o(),m=i("div"),h(L.$$.fragment),de=o(),M=i("p"),M.textContent=Te,ae=o(),u=i("div"),h(I.$$.fragment),me=o(),A=i("p"),A.innerHTML=ve,ce=o(),_=i("div"),h(N.$$.fragment),fe=o(),S=i("p"),S.textContent=Pe,pe=o(),g=i("div"),h(O.$$.fragment),le=o(),q=i("p"),q.textContent=xe,Y=o(),D=i("p"),D.textContent=$e,Z=o(),p=i("div"),h(k.$$.fragment),ue=o(),V=i("p"),V.innerHTML=ye,ee=o(),h(z.$$.fragment),te=o(),W=i("p"),this.h()},l(e){const r=Oe("svelte-u9bgzb",document.head);f=d(r,"META",{name:!0,content:!0}),r.forEach(t),R=n(e),U=d(e,"P",{}),H(U).forEach(t),B=n(e),b($.$$.fragment,e),F=n(e),y=d(e,"P",{"data-svelte-h":!0}),l(y)!=="svelte-j0j2ni"&&(y.innerHTML=ge),J=n(e),w=d(e,"P",{"data-svelte-h":!0}),l(w)!=="svelte-1cwsb16"&&(w.textContent=he),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 c=H(m);b(L.$$.fragment,c),de=n(c),M=d(c,"P",{"data-svelte-h":!0}),l(M)!=="svelte-jdqpwr"&&(M.textContent=Te),ae=n(c),u=d(c,"DIV",{class:!0});var oe=H(u);b(I.$$.fragment,oe),me=n(oe),A=d(oe,"P",{"data-svelte-h":!0}),l(A)!=="svelte-5u5png"&&(A.innerHTML=ve),oe.forEach(t),ce=n(c),_=d(c,"DIV",{class:!0});var ne=H(_);b(N.$$.fragment,ne),fe=n(ne),S=d(ne,"P",{"data-svelte-h":!0}),l(S)!=="svelte-1o77hl2"&&(S.textContent=Pe),ne.forEach(t),pe=n(c),g=d(c,"DIV",{class:!0});var se=H(g);b(O.$$.fragment,se),le=n(se),q=d(se,"P",{"data-svelte-h":!0}),l(q)!=="svelte-1lxcwhv"&&(q.textContent=xe),se.forEach(t),c.forEach(t),Y=n(e),D=d(e,"P",{"data-svelte-h":!0}),l(D)!=="svelte-re3ptv"&&(D.textContent=$e),Z=n(e),p=d(e,"DIV",{class:!0});var ie=H(p);b(k.$$.fragment,ie),ue=n(ie),V=d(ie,"P",{"data-svelte-h":!0}),l(V)!=="svelte-1w45j1q"&&(V.innerHTML=ye),ie.forEach(t),ee=n(e),b(z.$$.fragment,e),te=n(e),W=d(e,"P",{}),H(W).forEach(t),this.h()},h(){E(f,"name","hf:doc:metadata"),E(f,"content",ze),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(g,"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,r){a(document.head,f),s(e,R,r),s(e,U,r),s(e,B,r),T($,e,r),s(e,F,r),s(e,y,r),s(e,J,r),s(e,w,r),s(e,K,r),s(e,C,r),s(e,Q,r),T(j,e,r),s(e,X,r),s(e,m,r),T(L,m,null),a(m,de),a(m,M),a(m,ae),a(m,u),T(I,u,null),a(u,me),a(u,A),a(m,ce),a(m,_),T(N,_,null),a(_,fe),a(_,S),a(m,pe),a(m,g),T(O,g,null),a(g,le),a(g,q),s(e,Y,r),s(e,D,r),s(e,Z,r),s(e,p,r),T(k,p,null),a(p,ue),a(p,V),s(e,ee,r),T(z,e,r),s(e,te,r),s(e,W,r),re=!0},p:je,i(e){re||(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),re=!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),re=!1},d(e){e&&(t(R),t(U),t(B),t(F),t(y),t(J),t(w),t(K),t(C),t(Q),t(X),t(m),t(Y),t(D),t(Z),t(p),t(ee),t(te),t(W)),t(f),x($,e),x(j,e),x(L),x(I),x(N),x(O),x(k),x(z,e)}}}const ze='{"title":"Prior Transformer","local":"prior-transformer","sections":[{"title":"PriorTransformer","local":"diffusers.PriorTransformer","sections":[],"depth":2}],"depth":1}';function He(_e){return Le(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class qe extends Ie{constructor(f){super(),Ne(this,f,He,ke,Ce,{})}}export{qe as component};
