import{S as $l,i as Wl,s as Dl,e as n,k as p,w as u,t as s,M as Pl,c as a,d as i,m as f,a as o,x as h,h as r,b as l,N as Xl,G as t,g as m,y as g,L as kl,q as _,o as b,B as v,v as Vl}from"../../../chunks/vendor-hf-doc-builder.js";import{D as $}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as rt}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as F}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function Bl(Ss){let W,Gi,D,S,Dt,we,An,Pt,Ln,$i,Q,Hn,ye,qn,On,Wi,Y,Kn,Ue,ea,ta,Di,lt,Xt,ia,Pi,dt,na,Xi,z,pt,xe,aa,oa,sa,ft,Me,ra,la,ki,mt,da,Vi,A,Te,kt,pa,fa,Ee,ma,ca,Ze,Vt,ua,ha,Je,ga,Bi,L,_a,Ie,ba,va,Ci,P,H,Bt,je,wa,Ct,ya,Ni,q,Nt,Z,ct,Ua,xa,ut,Ma,Ta,ht,Ea,Za,gt,Ja,Ia,Rt,J,_t,Ge,ja,Ga,y,Ft,$a,Wa,St,Da,Pa,Qt,Xa,ka,Va,Ba,Yt,Ca,Na,zt,Ra,Fa,At,Sa,Qa,Lt,Ya,za,bt,$e,Aa,La,vt,We,wt,Qs,Ri,X,O,Ht,De,Ha,qt,qa,Fi,yt,Oa,Si,k,K,Ot,Pe,Ka,Kt,eo,Qi,ee,to,Ut,io,no,Yi,Xe,zi,xt,ao,Ai,te,oo,Mt,so,ro,Li,ke,Hi,ie,lo,Tt,po,fo,qi,Et,mo,Oi,Ve,Ki,V,ne,ei,Be,co,ti,uo,en,Zt,ho,tn,Ce,nn,U,go,ii,_o,bo,ni,vo,wo,ai,yo,Uo,oi,xo,Mo,Jt,To,Eo,an,B,ae,si,Ne,Zo,ri,Jo,on,It,Io,sn,Re,rn,M,jo,li,Go,$o,di,Wo,Do,pi,Po,Xo,jt,ko,Vo,ln,C,oe,fi,Fe,Bo,mi,Co,dn,Gt,No,pn,Se,fn,N,se,ci,Qe,Ro,ui,Fo,mn,$t,So,cn,Ye,un,R,re,hi,ze,Qo,gi,Yo,hn,c,Ae,zo,Le,Ao,He,Lo,Ho,qo,qe,Oo,Wt,Ko,es,ts,le,Oe,is,_i,ns,as,de,Ke,os,T,ss,bi,rs,ls,vi,ds,ps,wi,fs,ms,yi,cs,us,hs,pe,et,gs,I,_s,Ui,bs,vs,xi,ws,ys,Mi,Us,xs,Ms,fe,tt,Ts,Ti,Es,Zs,me,it,Js,Ei,Is,js,ce,nt,Gs,Zi,$s,Ws,ue,at,Ds,Ji,Ps,Xs,he,ot,ks,Ii,Vs,Bs,ge,st,Cs,ji,Ns,gn;return we=new F({}),je=new F({}),De=new F({}),Pe=new F({}),Xe=new rt({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwVW5pRGlmZnVzZXJQaXBlbGluZSUwQSUwQWRldmljZSUyMCUzRCUyMCUyMmN1ZGElMjIlMEFtb2RlbF9pZF9vcl9wYXRoJTIwJTNEJTIwJTIydGh1LW1sJTJGdW5pZGlmZnVzZXItdjElMjIlMEFwaXBlJTIwJTNEJTIwVW5pRGlmZnVzZXJQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWRfb3JfcGF0aCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlLnRvKGRldmljZSklMEElMEElMjMlMjBVbmNvbmRpdGlvbmFsJTIwaW1hZ2UlMjBhbmQlMjB0ZXh0JTIwZ2VuZXJhdGlvbi4lMjBUaGUlMjBnZW5lcmF0aW9uJTIwdGFzayUyMGlzJTIwYXV0b21hdGljYWxseSUyMGluZmVycmVkLiUwQXNhbXBsZSUyMCUzRCUyMHBpcGUobnVtX2luZmVyZW5jZV9zdGVwcyUzRDIwJTJDJTIwZ3VpZGFuY2Vfc2NhbGUlM0Q4LjApJTBBaW1hZ2UlMjAlM0QlMjBzYW1wbGUuaW1hZ2VzJTVCMCU1RCUwQXRleHQlMjAlM0QlMjBzYW1wbGUudGV4dCU1QjAlNUQlMEFpbWFnZS5zYXZlKCUyMnVuaWRpZmZ1c2VyX2pvaW50X3NhbXBsZV9pbWFnZS5wbmclMjIpJTBBcHJpbnQodGV4dCk=",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UniDiffuserPipeline

device = <span class="hljs-string">&quot;cuda&quot;</span>
model_id_or_path = <span class="hljs-string">&quot;thu-ml/unidiffuser-v1&quot;</span>
pipe = UniDiffuserPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe.to(device)

<span class="hljs-comment"># Unconditional image and text generation. The generation task is automatically inferred.</span>
sample = pipe(num_inference_steps=<span class="hljs-number">20</span>, guidance_scale=<span class="hljs-number">8.0</span>)
image = sample.images[<span class="hljs-number">0</span>]
text = sample.text[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;unidiffuser_joint_sample_image.png&quot;</span>)
<span class="hljs-built_in">print</span>(text)`}}),ke=new rt({props:{code:"JTIzJTIwRXF1aXZhbGVudCUyMHRvJTIwdGhlJTIwYWJvdmUuJTBBcGlwZS5zZXRfam9pbnRfbW9kZSgpJTBBc2FtcGxlJTIwJTNEJTIwcGlwZShudW1faW5mZXJlbmNlX3N0ZXBzJTNEMjAlMkMlMjBndWlkYW5jZV9zY2FsZSUzRDguMCk=",highlighted:`<span class="hljs-comment"># Equivalent to the above.</span>
pipe.set_joint_mode()
sample = pipe(num_inference_steps=<span class="hljs-number">20</span>, guidance_scale=<span class="hljs-number">8.0</span>)`}}),Ve=new rt({props:{code:"JTIzJTIwVW5saWtlJTIwb3RoZXIlMjBnZW5lcmF0aW9uJTIwdGFza3MlMkMlMjBpbWFnZS1vbmx5JTIwYW5kJTIwdGV4dC1vbmx5JTIwZ2VuZXJhdGlvbiUyMGRvbid0JTIwdXNlJTIwY2xhc3NpZmllci1mcmVlJTIwZ3VpZGFuY2UlMEElMjMlMjBJbWFnZS1vbmx5JTIwZ2VuZXJhdGlvbiUwQXBpcGUuc2V0X2ltYWdlX21vZGUoKSUwQXNhbXBsZV9pbWFnZSUyMCUzRCUyMHBpcGUobnVtX2luZmVyZW5jZV9zdGVwcyUzRDIwKS5pbWFnZXMlNUIwJTVEJTBBJTIzJTIwVGV4dC1vbmx5JTIwZ2VuZXJhdGlvbiUwQXBpcGUuc2V0X3RleHRfbW9kZSgpJTBBc2FtcGxlX3RleHQlMjAlM0QlMjBwaXBlKG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyMCkudGV4dCU1QjAlNUQ=",highlighted:`<span class="hljs-comment"># Unlike other generation tasks, image-only and text-only generation don&#x27;t use classifier-free guidance</span>
<span class="hljs-comment"># Image-only generation</span>
pipe.set_image_mode()
sample_image = pipe(num_inference_steps=<span class="hljs-number">20</span>).images[<span class="hljs-number">0</span>]
<span class="hljs-comment"># Text-only generation</span>
pipe.set_text_mode()
sample_text = pipe(num_inference_steps=<span class="hljs-number">20</span>).text[<span class="hljs-number">0</span>]`}}),Be=new F({}),Ce=new rt({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwVW5pRGlmZnVzZXJQaXBlbGluZSUwQSUwQWRldmljZSUyMCUzRCUyMCUyMmN1ZGElMjIlMEFtb2RlbF9pZF9vcl9wYXRoJTIwJTNEJTIwJTIydGh1LW1sJTJGdW5pZGlmZnVzZXItdjElMjIlMEFwaXBlJTIwJTNEJTIwVW5pRGlmZnVzZXJQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWRfb3JfcGF0aCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlLnRvKGRldmljZSklMEElMEElMjMlMjBUZXh0LXRvLWltYWdlJTIwZ2VuZXJhdGlvbiUwQXByb21wdCUyMCUzRCUyMCUyMmFuJTIwZWxlcGhhbnQlMjB1bmRlciUyMHRoZSUyMHNlYSUyMiUwQSUwQXNhbXBsZSUyMCUzRCUyMHBpcGUocHJvbXB0JTNEcHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDIwJTJDJTIwZ3VpZGFuY2Vfc2NhbGUlM0Q4LjApJTBBdDJpX2ltYWdlJTIwJTNEJTIwc2FtcGxlLmltYWdlcyU1QjAlNUQlMEF0MmlfaW1hZ2Uuc2F2ZSglMjJ1bmlkaWZmdXNlcl90ZXh0MmltZ19zYW1wbGVfaW1hZ2UucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UniDiffuserPipeline

device = <span class="hljs-string">&quot;cuda&quot;</span>
model_id_or_path = <span class="hljs-string">&quot;thu-ml/unidiffuser-v1&quot;</span>
pipe = UniDiffuserPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe.to(device)

<span class="hljs-comment"># Text-to-image generation</span>
prompt = <span class="hljs-string">&quot;an elephant under the sea&quot;</span>

sample = pipe(prompt=prompt, num_inference_steps=<span class="hljs-number">20</span>, guidance_scale=<span class="hljs-number">8.0</span>)
t2i_image = sample.images[<span class="hljs-number">0</span>]
t2i_image.save(<span class="hljs-string">&quot;unidiffuser_text2img_sample_image.png&quot;</span>)`}}),Ne=new F({}),Re=new rt({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwVW5pRGlmZnVzZXJQaXBlbGluZSUwQWZyb20lMjBkaWZmdXNlcnMudXRpbHMlMjBpbXBvcnQlMjBsb2FkX2ltYWdlJTBBJTBBZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUwQW1vZGVsX2lkX29yX3BhdGglMjAlM0QlMjAlMjJ0aHUtbWwlMkZ1bmlkaWZmdXNlci12MSUyMiUwQXBpcGUlMjAlM0QlMjBVbmlEaWZmdXNlclBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZF9vcl9wYXRoJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KSUwQXBpcGUudG8oZGV2aWNlKSUwQSUwQSUyMyUyMEltYWdlLXRvLXRleHQlMjBnZW5lcmF0aW9uJTBBaW1hZ2VfdXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyRmRhdGFzZXRzJTJGaGYtaW50ZXJuYWwtdGVzdGluZyUyRmRpZmZ1c2Vycy1pbWFnZXMlMkZyZXNvbHZlJTJGbWFpbiUyRnVuaWRpZmZ1c2VyJTJGdW5pZGlmZnVzZXJfZXhhbXBsZV9pbWFnZS5qcGclMjIlMEFpbml0X2ltYWdlJTIwJTNEJTIwbG9hZF9pbWFnZShpbWFnZV91cmwpLnJlc2l6ZSgoNTEyJTJDJTIwNTEyKSklMEElMEFzYW1wbGUlMjAlM0QlMjBwaXBlKGltYWdlJTNEaW5pdF9pbWFnZSUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyMCUyQyUyMGd1aWRhbmNlX3NjYWxlJTNEOC4wKSUwQWkydF90ZXh0JTIwJTNEJTIwc2FtcGxlLnRleHQlNUIwJTVEJTBBcHJpbnQoaTJ0X3RleHQp",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UniDiffuserPipeline
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image

device = <span class="hljs-string">&quot;cuda&quot;</span>
model_id_or_path = <span class="hljs-string">&quot;thu-ml/unidiffuser-v1&quot;</span>
pipe = UniDiffuserPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe.to(device)

<span class="hljs-comment"># Image-to-text generation</span>
image_url = <span class="hljs-string">&quot;https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/unidiffuser/unidiffuser_example_image.jpg&quot;</span>
init_image = load_image(image_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))

sample = pipe(image=init_image, num_inference_steps=<span class="hljs-number">20</span>, guidance_scale=<span class="hljs-number">8.0</span>)
i2t_text = sample.text[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(i2t_text)`}}),Fe=new F({}),Se=new rt({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwVW5pRGlmZnVzZXJQaXBlbGluZSUwQWZyb20lMjBkaWZmdXNlcnMudXRpbHMlMjBpbXBvcnQlMjBsb2FkX2ltYWdlJTBBJTBBZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUwQW1vZGVsX2lkX29yX3BhdGglMjAlM0QlMjAlMjJ0aHUtbWwlMkZ1bmlkaWZmdXNlci12MSUyMiUwQXBpcGUlMjAlM0QlMjBVbmlEaWZmdXNlclBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZF9vcl9wYXRoJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KSUwQXBpcGUudG8oZGV2aWNlKSUwQSUwQSUyMyUyMEltYWdlJTIwdmFyaWF0aW9uJTIwY2FuJTIwYmUlMjBwZXJmb3JtZWQlMjB3aXRoJTIwYSUyMGltYWdlLXRvLXRleHQlMjBnZW5lcmF0aW9uJTIwZm9sbG93ZWQlMjBieSUyMGElMjB0ZXh0LXRvLWltYWdlJTIwZ2VuZXJhdGlvbiUzQSUwQSUyMyUyMDEuJTIwSW1hZ2UtdG8tdGV4dCUyMGdlbmVyYXRpb24lMEFpbWFnZV91cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZoZi1pbnRlcm5hbC10ZXN0aW5nJTJGZGlmZnVzZXJzLWltYWdlcyUyRnJlc29sdmUlMkZtYWluJTJGdW5pZGlmZnVzZXIlMkZ1bmlkaWZmdXNlcl9leGFtcGxlX2ltYWdlLmpwZyUyMiUwQWluaXRfaW1hZ2UlMjAlM0QlMjBsb2FkX2ltYWdlKGltYWdlX3VybCkucmVzaXplKCg1MTIlMkMlMjA1MTIpKSUwQSUwQXNhbXBsZSUyMCUzRCUyMHBpcGUoaW1hZ2UlM0Rpbml0X2ltYWdlJTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDIwJTJDJTIwZ3VpZGFuY2Vfc2NhbGUlM0Q4LjApJTBBaTJ0X3RleHQlMjAlM0QlMjBzYW1wbGUudGV4dCU1QjAlNUQlMEFwcmludChpMnRfdGV4dCklMEElMEElMjMlMjAyLiUyMFRleHQtdG8taW1hZ2UlMjBnZW5lcmF0aW9uJTBBc2FtcGxlJTIwJTNEJTIwcGlwZShwcm9tcHQlM0RpMnRfdGV4dCUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyMCUyQyUyMGd1aWRhbmNlX3NjYWxlJTNEOC4wKSUwQWZpbmFsX2ltYWdlJTIwJTNEJTIwc2FtcGxlLmltYWdlcyU1QjAlNUQlMEFmaW5hbF9pbWFnZS5zYXZlKCUyMnVuaWRpZmZ1c2VyX2ltYWdlX3ZhcmlhdGlvbl9zYW1wbGUucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UniDiffuserPipeline
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image

device = <span class="hljs-string">&quot;cuda&quot;</span>
model_id_or_path = <span class="hljs-string">&quot;thu-ml/unidiffuser-v1&quot;</span>
pipe = UniDiffuserPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe.to(device)

<span class="hljs-comment"># Image variation can be performed with a image-to-text generation followed by a text-to-image generation:</span>
<span class="hljs-comment"># 1. Image-to-text generation</span>
image_url = <span class="hljs-string">&quot;https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/unidiffuser/unidiffuser_example_image.jpg&quot;</span>
init_image = load_image(image_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))

sample = pipe(image=init_image, num_inference_steps=<span class="hljs-number">20</span>, guidance_scale=<span class="hljs-number">8.0</span>)
i2t_text = sample.text[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(i2t_text)

<span class="hljs-comment"># 2. Text-to-image generation</span>
sample = pipe(prompt=i2t_text, num_inference_steps=<span class="hljs-number">20</span>, guidance_scale=<span class="hljs-number">8.0</span>)
final_image = sample.images[<span class="hljs-number">0</span>]
final_image.save(<span class="hljs-string">&quot;unidiffuser_image_variation_sample.png&quot;</span>)`}}),Qe=new F({}),Ye=new rt({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwVW5pRGlmZnVzZXJQaXBlbGluZSUwQSUwQWRldmljZSUyMCUzRCUyMCUyMmN1ZGElMjIlMEFtb2RlbF9pZF9vcl9wYXRoJTIwJTNEJTIwJTIydGh1LW1sJTJGdW5pZGlmZnVzZXItdjElMjIlMEFwaXBlJTIwJTNEJTIwVW5pRGlmZnVzZXJQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWRfb3JfcGF0aCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlLnRvKGRldmljZSklMEElMEElMjMlMjBUZXh0JTIwdmFyaWF0aW9uJTIwY2FuJTIwYmUlMjBwZXJmb3JtZWQlMjB3aXRoJTIwYSUyMHRleHQtdG8taW1hZ2UlMjBnZW5lcmF0aW9uJTIwZm9sbG93ZWQlMjBieSUyMGElMjBpbWFnZS10by10ZXh0JTIwZ2VuZXJhdGlvbiUzQSUwQSUyMyUyMDEuJTIwVGV4dC10by1pbWFnZSUyMGdlbmVyYXRpb24lMEFwcm9tcHQlMjAlM0QlMjAlMjJhbiUyMGVsZXBoYW50JTIwdW5kZXIlMjB0aGUlMjBzZWElMjIlMEElMEFzYW1wbGUlMjAlM0QlMjBwaXBlKHByb21wdCUzRHByb21wdCUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyMCUyQyUyMGd1aWRhbmNlX3NjYWxlJTNEOC4wKSUwQXQyaV9pbWFnZSUyMCUzRCUyMHNhbXBsZS5pbWFnZXMlNUIwJTVEJTBBdDJpX2ltYWdlLnNhdmUoJTIydW5pZGlmZnVzZXJfdGV4dDJpbWdfc2FtcGxlX2ltYWdlLnBuZyUyMiklMEElMEElMjMlMjAyLiUyMEltYWdlLXRvLXRleHQlMjBnZW5lcmF0aW9uJTBBc2FtcGxlJTIwJTNEJTIwcGlwZShpbWFnZSUzRHQyaV9pbWFnZSUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyMCUyQyUyMGd1aWRhbmNlX3NjYWxlJTNEOC4wKSUwQWZpbmFsX3Byb21wdCUyMCUzRCUyMHNhbXBsZS50ZXh0JTVCMCU1RCUwQXByaW50KGZpbmFsX3Byb21wdCk=",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UniDiffuserPipeline

device = <span class="hljs-string">&quot;cuda&quot;</span>
model_id_or_path = <span class="hljs-string">&quot;thu-ml/unidiffuser-v1&quot;</span>
pipe = UniDiffuserPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe.to(device)

<span class="hljs-comment"># Text variation can be performed with a text-to-image generation followed by a image-to-text generation:</span>
<span class="hljs-comment"># 1. Text-to-image generation</span>
prompt = <span class="hljs-string">&quot;an elephant under the sea&quot;</span>

sample = pipe(prompt=prompt, num_inference_steps=<span class="hljs-number">20</span>, guidance_scale=<span class="hljs-number">8.0</span>)
t2i_image = sample.images[<span class="hljs-number">0</span>]
t2i_image.save(<span class="hljs-string">&quot;unidiffuser_text2img_sample_image.png&quot;</span>)

<span class="hljs-comment"># 2. Image-to-text generation</span>
sample = pipe(image=t2i_image, num_inference_steps=<span class="hljs-number">20</span>, guidance_scale=<span class="hljs-number">8.0</span>)
final_prompt = sample.text[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(final_prompt)`}}),ze=new F({}),Ae=new $({props:{name:"class diffusers.UniDiffuserPipeline",anchor:"diffusers.UniDiffuserPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"image_encoder",val:": CLIPVisionModelWithProjection"},{name:"image_processor",val:": CLIPImageProcessor"},{name:"clip_tokenizer",val:": CLIPTokenizer"},{name:"text_decoder",val:": UniDiffuserTextDecoder"},{name:"text_tokenizer",val:": GPT2Tokenizer"},{name:"unet",val:": UniDiffuserModel"},{name:"scheduler",val:": KarrasDiffusionSchedulers"}],parametersDescription:[{anchor:"diffusers.UniDiffuserPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.18.0/en/api/models/autoencoderkl#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations. This
is part of the UniDiffuser image representation, along with the CLIP vision encoding.`,name:"vae"},{anchor:"diffusers.UniDiffuserPipeline.text_encoder",description:`<strong>text_encoder</strong> (<code>CLIPTextModel</code>) &#x2014;
Frozen text-encoder. Similar to Stable Diffusion, UniDiffuser uses the text portion of
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIP</a> to encode text
prompts.`,name:"text_encoder"},{anchor:"diffusers.UniDiffuserPipeline.image_encoder",description:`<strong>image_encoder</strong> (<code>CLIPVisionModel</code>) &#x2014;
UniDiffuser uses the vision portion of
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPVisionModel" rel="nofollow">CLIP</a> to encode
images as part of its image representation, along with the VAE latent representation.`,name:"image_encoder"},{anchor:"diffusers.UniDiffuserPipeline.image_processor",description:`<strong>image_processor</strong> (<code>CLIPImageProcessor</code>) &#x2014;
CLIP image processor of class
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPImageProcessor" rel="nofollow">CLIPImageProcessor</a>,
used to preprocess the image before CLIP encoding it with <code>image_encoder</code>.`,name:"image_processor"},{anchor:"diffusers.UniDiffuserPipeline.clip_tokenizer",description:`<strong>clip_tokenizer</strong> (<code>CLIPTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a> which
is used to tokenizer a prompt before encoding it with <code>text_encoder</code>.`,name:"clip_tokenizer"},{anchor:"diffusers.UniDiffuserPipeline.text_decoder",description:`<strong>text_decoder</strong> (<code>UniDiffuserTextDecoder</code>) &#x2014;
Frozen text decoder. This is a GPT-style model which is used to generate text from the UniDiffuser
embedding.`,name:"text_decoder"},{anchor:"diffusers.UniDiffuserPipeline.text_tokenizer",description:`<strong>text_tokenizer</strong> (<code>GPT2Tokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/model_doc/gpt2#transformers.GPT2Tokenizer" rel="nofollow">GPT2Tokenizer</a> which
is used along with the <code>text_decoder</code> to decode text for text generation.`,name:"text_tokenizer"},{anchor:"diffusers.UniDiffuserPipeline.unet",description:`<strong>unet</strong> (<code>UniDiffuserModel</code>) &#x2014;
UniDiffuser uses a <a href="https://github.com/baofff/U-ViT" rel="nofollow">U-ViT</a> model architecture, which is similar to a
<a href="/docs/diffusers/v0.18.0/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> with U-Net-style skip connections between transformer layers.`,name:"unet"},{anchor:"diffusers.UniDiffuserPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.18.0/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image and/or text latents. The
original UniDiffuser paper uses the <a href="/docs/diffusers/v0.18.0/en/api/schedulers/multistep_dpm_solver#diffusers.DPMSolverMultistepScheduler">DPMSolverMultistepScheduler</a> scheduler.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L82"}}),Oe=new $({props:{name:"__call__",anchor:"diffusers.UniDiffuserPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image, NoneType] = None"},{name:"height",val:": typing.Optional[int] = None"},{name:"width",val:": typing.Optional[int] = None"},{name:"data_type",val:": typing.Optional[int] = 1"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 8.0"},{name:"negative_prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"num_prompts_per_image",val:": typing.Optional[int] = 1"},{name:"eta",val:": float = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"vae_latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"clip_latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": int = 1"}],parametersDescription:[{anchor:"diffusers.UniDiffuserPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>
instead. Required for text-conditioned image generation (<code>text2img</code>) mode.`,name:"prompt"},{anchor:"diffusers.UniDiffuserPipeline.__call__.image",description:`<strong>image</strong> (<code>torch.FloatTensor</code> or <code>PIL.Image.Image</code>, <em>optional</em>) &#x2014;
<code>Image</code>, or tensor representing an image batch. Required for image-conditioned text generation
(<code>img2text</code>) mode.`,name:"image"},{anchor:"diffusers.UniDiffuserPipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to <code>self.unet.config.sample_size * self.vae_scale_factor</code>) &#x2014;
The height in pixels of the generated image.`,name:"height"},{anchor:"diffusers.UniDiffuserPipeline.__call__.width",description:`<strong>width</strong> (<code>int</code>, <em>optional</em>, defaults to <code>self.unet.config.sample_size * self.vae_scale_factor</code>) &#x2014;
The width in pixels of the generated image.`,name:"width"},{anchor:"diffusers.UniDiffuserPipeline.__call__.data_type",description:`<strong>data_type</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The data type (either 0 or 1). Only used if you are loading a checkpoint which supports a data type
embedding; this is added for compatibility with the UniDiffuser-v1 checkpoint.`,name:"data_type"},{anchor:"diffusers.UniDiffuserPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.UniDiffuserPipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 8.0) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality. Note that the original <a href="https://arxiv.org/pdf/2303.06555.pdf" rel="nofollow">UniDiffuser
paper</a> uses a different definition of the guidance scale <code>w&apos;</code>,
which satisfies <code>w = w&apos; + 1</code>.`,name:"guidance_scale"},{anchor:"diffusers.UniDiffuserPipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. If not defined, one has to pass
<code>negative_prompt_embeds</code> instead. Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code> is
less than <code>1</code>). Used in text-conditioned image generation (<code>text2img</code>) mode.`,name:"negative_prompt"},{anchor:"diffusers.UniDiffuserPipeline.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate per prompt. Used in <code>text2img</code> (text-conditioned image generation) and
<code>img</code> mode. If the mode is joint and both <code>num_images_per_prompt</code> and <code>num_prompts_per_image</code> are
supplied, <code>min(num_images_per_prompt, num_prompts_per_image)</code> samples will be generated.`,name:"num_images_per_prompt"},{anchor:"diffusers.UniDiffuserPipeline.__call__.num_prompts_per_image",description:`<strong>num_prompts_per_image</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of prompts to generate per image. Used in <code>img2text</code> (image-conditioned text generation) and
<code>text</code> mode. If the mode is joint and both <code>num_images_per_prompt</code> and <code>num_prompts_per_image</code> are
supplied, <code>min(num_images_per_prompt, num_prompts_per_image)</code> samples will be generated.`,name:"num_prompts_per_image"},{anchor:"diffusers.UniDiffuserPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) in the DDIM paper: <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">https://arxiv.org/abs/2010.02502</a>. Only applies to
<a href="/docs/diffusers/v0.18.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.UniDiffuserPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.UniDiffuserPipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for joint
image-text generation. Can be used to tweak the same generation with different prompts. If not
provided, a latents tensor will be generated by sampling using the supplied random <code>generator</code>. Note
that this is assumed to be a full set of VAE, CLIP, and text latents, if supplied, this will override
the value of <code>prompt_latents</code>, <code>vae_latents</code>, and <code>clip_latents</code>.`,name:"latents"},{anchor:"diffusers.UniDiffuserPipeline.__call__.prompt_latents",description:`<strong>prompt_latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for text
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will be generated by sampling using the supplied random <code>generator</code>.`,name:"prompt_latents"},{anchor:"diffusers.UniDiffuserPipeline.__call__.vae_latents",description:`<strong>vae_latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will be generated by sampling using the supplied random <code>generator</code>.`,name:"vae_latents"},{anchor:"diffusers.UniDiffuserPipeline.__call__.clip_latents",description:`<strong>clip_latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will be generated by sampling using the supplied random <code>generator</code>.`,name:"clip_latents"},{anchor:"diffusers.UniDiffuserPipeline.__call__.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument. Used in text-conditioned
image generation (<code>text2img</code>) mode.`,name:"prompt_embeds"},{anchor:"diffusers.UniDiffuserPipeline.__call__.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument. Used in text-conditioned image generation (<code>text2img</code>) mode.`,name:"negative_prompt_embeds"},{anchor:"diffusers.UniDiffuserPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.UniDiffuserPipeline.__call__.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/v0.18.0/en/api/outputs#diffusers.ImageTextPipelineOutput">ImageTextPipelineOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"diffusers.UniDiffuserPipeline.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.UniDiffuserPipeline.__call__.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L1084",returnDescription:`
<p><a
  href="/docs/diffusers/v0.18.0/en/api/outputs#diffusers.ImageTextPipelineOutput"
>pipelines.unidiffuser.ImageTextPipelineOutput</a> if <code>return_dict</code> is True, otherwise a <code>tuple</code>. When
returning a tuple, the first element is a list with the generated images, and the second element is a list
of generated texts.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/v0.18.0/en/api/outputs#diffusers.ImageTextPipelineOutput"
>ImageTextPipelineOutput</a> or <code>tuple</code></p>
`}}),Ke=new $({props:{name:"enable_model_cpu_offload",anchor:"diffusers.UniDiffuserPipeline.enable_model_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L204"}}),et=new $({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.UniDiffuserPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L177"}}),tt=new $({props:{name:"reset_mode",anchor:"diffusers.UniDiffuserPipeline.reset_mode",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L348"}}),it=new $({props:{name:"set_image_mode",anchor:"diffusers.UniDiffuserPipeline.set_image_mode",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L332"}}),nt=new $({props:{name:"set_image_to_text_mode",anchor:"diffusers.UniDiffuserPipeline.set_image_to_text_mode",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L340"}}),at=new $({props:{name:"set_joint_mode",anchor:"diffusers.UniDiffuserPipeline.set_joint_mode",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L344"}}),ot=new $({props:{name:"set_text_mode",anchor:"diffusers.UniDiffuserPipeline.set_text_mode",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L328"}}),st=new $({props:{name:"set_text_to_image_mode",anchor:"diffusers.UniDiffuserPipeline.set_text_to_image_mode",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/unidiffuser/pipeline_unidiffuser.py#L336"}}),{c(){W=n("meta"),Gi=p(),D=n("h1"),S=n("a"),Dt=n("span"),u(we.$$.fragment),An=p(),Pt=n("span"),Ln=s("UniDiffuser"),$i=p(),Q=n("p"),Hn=s("The UniDiffuser model was proposed in "),ye=n("a"),qn=s("One Transformer Fits All Distributions in Multi-Modal Diffusion at Scale"),On=s(" by Fan Bao, Shen Nie, Kaiwen Xue, Chongxuan Li, Shi Pu, Yaole Wang, Gang Yue, Yue Cao, Hang Su, Jun Zhu."),Wi=p(),Y=n("p"),Kn=s("The abstract of the "),Ue=n("a"),ea=s("paper"),ta=s(" is the following:"),Di=p(),lt=n("p"),Xt=n("em"),ia=s("This paper proposes a unified diffusion framework (dubbed UniDiffuser) to fit all distributions relevant to a set of multi-modal data in one model. Our key insight is \u2014 learning diffusion models for marginal, conditional, and joint distributions can be unified as predicting the noise in the perturbed data, where the perturbation levels (i.e. timesteps) can be different for different modalities. Inspired by the unified view, UniDiffuser learns all distributions simultaneously with a minimal modification to the original diffusion model \u2014 perturbs data in all modalities instead of a single modality, inputs individual timesteps in different modalities, and predicts the noise of all modalities instead of a single modality. UniDiffuser is parameterized by a transformer for diffusion models to handle input types of different modalities. Implemented on large-scale paired image-text data, UniDiffuser is able to perform image, text, text-to-image, image-to-text, and image-text pair generation by setting proper timesteps without additional overhead. In particular, UniDiffuser is able to produce perceptually realistic samples in all tasks and its quantitative results (e.g., the FID and CLIP score) are not only superior to existing general-purpose models but also comparable to the bespoken models (e.g., Stable Diffusion and DALL-E 2) in representative tasks (e.g., text-to-image generation)."),Pi=p(),dt=n("p"),na=s("Resources:"),Xi=p(),z=n("ul"),pt=n("li"),xe=n("a"),aa=s("Paper"),oa=s("."),sa=p(),ft=n("li"),Me=n("a"),ra=s("Original Code"),la=s("."),ki=p(),mt=n("p"),da=s("Available Checkpoints are:"),Vi=p(),A=n("ul"),Te=n("li"),kt=n("em"),pa=s("UniDiffuser-v0 (512x512 resolution)"),fa=p(),Ee=n("a"),ma=s("thu-ml/unidiffuser-v0"),ca=p(),Ze=n("li"),Vt=n("em"),ua=s("UniDiffuser-v1 (512x512 resolution)"),ha=p(),Je=n("a"),ga=s("thu-ml/unidiffuser-v1"),Bi=p(),L=n("p"),_a=s("This pipeline was contributed by our community member "),Ie=n("a"),ba=s("dg845"),va=s("."),Ci=p(),P=n("h2"),H=n("a"),Bt=n("span"),u(je.$$.fragment),wa=p(),Ct=n("span"),ya=s("Available Pipelines:"),Ni=p(),q=n("table"),Nt=n("thead"),Z=n("tr"),ct=n("th"),Ua=s("Pipeline"),xa=p(),ut=n("th"),Ma=s("Tasks"),Ta=p(),ht=n("th"),Ea=s("Demo"),Za=p(),gt=n("th"),Ja=s("Colab"),Ia=p(),Rt=n("tbody"),J=n("tr"),_t=n("td"),Ge=n("a"),ja=s("UniDiffuserPipeline"),Ga=p(),y=n("td"),Ft=n("em"),$a=s("Joint Image-Text Gen"),Wa=s(", "),St=n("em"),Da=s("Text-to-Image"),Pa=s(", "),Qt=n("em"),Xa=s("Image-to-Text"),ka=s(","),Va=n("br"),Ba=p(),Yt=n("em"),Ca=s("Image Gen"),Na=s(", "),zt=n("em"),Ra=s("Text Gen"),Fa=s(", "),At=n("em"),Sa=s("Image Variation"),Qa=s(", "),Lt=n("em"),Ya=s("Text Variation"),za=p(),bt=n("td"),$e=n("a"),Aa=s("\u{1F917} Spaces"),La=p(),vt=n("td"),We=n("a"),wt=n("img"),Ri=p(),X=n("h2"),O=n("a"),Ht=n("span"),u(De.$$.fragment),Ha=p(),qt=n("span"),qa=s("Usage Examples"),Fi=p(),yt=n("p"),Oa=s("Because the UniDiffuser model is trained to model the joint distribution of (image, text) pairs, it is capable of performing a diverse range of generation tasks."),Si=p(),k=n("h3"),K=n("a"),Ot=n("span"),u(Pe.$$.fragment),Ka=p(),Kt=n("span"),eo=s("Unconditional Image and Text Generation"),Qi=p(),ee=n("p"),to=s("Unconditional generation (where we start from only latents sampled from a standard Gaussian prior) from a "),Ut=n("a"),io=s("UniDiffuserPipeline"),no=s(" will produce a (image, text) pair:"),Yi=p(),u(Xe.$$.fragment),zi=p(),xt=n("p"),ao=s("This is also called \u201Cjoint\u201D generation in the UniDiffusers paper, since we are sampling from the joint image-text distribution."),Ai=p(),te=n("p"),oo=s(`Note that the generation task is inferred from the inputs used when calling the pipeline.
It is also possible to manually specify the unconditional generation task (\u201Cmode\u201D) manually with `),Mt=n("a"),so=s("UniDiffuserPipeline.set_joint_mode()"),ro=s(":"),Li=p(),u(ke.$$.fragment),Hi=p(),ie=n("p"),lo=s(`When the mode is set manually, subsequent calls to the pipeline will use the set mode without attempting the infer the mode.
You can reset the mode with `),Tt=n("a"),po=s("UniDiffuserPipeline.reset_mode()"),fo=s(", after which the pipeline will once again infer the mode."),qi=p(),Et=n("p"),mo=s("You can also generate only an image or only text (which the UniDiffuser paper calls \u201Cmarginal\u201D generation since we sample from the marginal distribution of images and text, respectively):"),Oi=p(),u(Ve.$$.fragment),Ki=p(),V=n("h3"),ne=n("a"),ei=n("span"),u(Be.$$.fragment),co=p(),ti=n("span"),uo=s("Text-to-Image Generation"),en=p(),Zt=n("p"),ho=s(`UniDiffuser is also capable of sampling from conditional distributions; that is, the distribution of images conditioned on a text prompt or the distribution of texts conditioned on an image.
Here is an example of sampling from the conditional image distribution (text-to-image generation or text-conditioned image generation):`),tn=p(),u(Ce.$$.fragment),nn=p(),U=n("p"),go=s("The "),ii=n("code"),_o=s("text2img"),bo=s(" mode requires that either an input "),ni=n("code"),vo=s("prompt"),wo=s(" or "),ai=n("code"),yo=s("prompt_embeds"),Uo=s(" be supplied. You can set the "),oi=n("code"),xo=s("text2img"),Mo=s(" mode manually with "),Jt=n("a"),To=s("UniDiffuserPipeline.set_text_to_image_mode()"),Eo=s("."),an=p(),B=n("h3"),ae=n("a"),si=n("span"),u(Ne.$$.fragment),Zo=p(),ri=n("span"),Jo=s("Image-to-Text Generation"),on=p(),It=n("p"),Io=s("Similarly, UniDiffuser can also produce text samples given an image (image-to-text or image-conditioned text generation):"),sn=p(),u(Re.$$.fragment),rn=p(),M=n("p"),jo=s("The "),li=n("code"),Go=s("img2text"),$o=s(" mode requires that an input "),di=n("code"),Wo=s("image"),Do=s(" be supplied. You can set the "),pi=n("code"),Po=s("img2text"),Xo=s(" mode manually with "),jt=n("a"),ko=s("UniDiffuserPipeline.set_image_to_text_mode()"),Vo=s("."),ln=p(),C=n("h3"),oe=n("a"),fi=n("span"),u(Fe.$$.fragment),Bo=p(),mi=n("span"),Co=s("Image Variation"),dn=p(),Gt=n("p"),No=s(`The UniDiffuser authors suggest performing image variation through a \u201Cround-trip\u201D generation method, where given an input image, we first perform an image-to-text generation, and the perform a text-to-image generation on the outputs of the first generation.
This produces a new image which is semantically similar to the input image:`),pn=p(),u(Se.$$.fragment),fn=p(),N=n("h3"),se=n("a"),ci=n("span"),u(Qe.$$.fragment),Ro=p(),ui=n("span"),Fo=s("Text Variation"),mn=p(),$t=n("p"),So=s("Similarly, text variation can be performed on an input prompt with a text-to-image generation followed by a image-to-text generation:"),cn=p(),u(Ye.$$.fragment),un=p(),R=n("h2"),re=n("a"),hi=n("span"),u(ze.$$.fragment),Qo=p(),gi=n("span"),Yo=s("UniDiffuserPipeline"),hn=p(),c=n("div"),u(Ae.$$.fragment),zo=p(),Le=n("p"),Ao=s("Pipeline for a bimodal image-text "),He=n("a"),Lo=s("UniDiffuser"),Ho=s(` model, which supports
unconditional text and image generation, text-conditioned image generation, image-conditioned text generation, and
joint image-text generation.`),qo=p(),qe=n("p"),Oo=s("This model inherits from "),Wt=n("a"),Ko=s("DiffusionPipeline"),es=s(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),ts=p(),le=n("div"),u(Oe.$$.fragment),is=p(),_i=n("p"),ns=s("Function invoked when calling the pipeline for generation."),as=p(),de=n("div"),u(Ke.$$.fragment),os=p(),T=n("p"),ss=s(`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),bi=n("code"),rs=s("enable_sequential_cpu_offload"),ls=s(", this method moves one whole model at a time to the GPU when its "),vi=n("code"),ds=s("forward"),ps=s(`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),wi=n("code"),fs=s("enable_sequential_cpu_offload"),ms=s(", but performance is much better due to the iterative execution of the "),yi=n("code"),cs=s("unet"),us=s("."),hs=p(),pe=n("div"),u(et.$$.fragment),gs=p(),I=n("p"),_s=s(`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),Ui=n("code"),bs=s("torch.device('meta')"),vs=s(" and loaded to GPU only when their specific submodule has its "),xi=n("code"),ws=s("forward"),ys=s(` method called.
Note that offloading happens on a submodule basis. Memory savings are higher than with
`),Mi=n("code"),Us=s("enable_model_cpu_offload"),xs=s(", but performance is lower."),Ms=p(),fe=n("div"),u(tt.$$.fragment),Ts=p(),Ti=n("p"),Es=s("Removes a manually set mode; after calling this, the pipeline will infer the mode from inputs."),Zs=p(),me=n("div"),u(it.$$.fragment),Js=p(),Ei=n("p"),Is=s("Manually set the generation mode to unconditional (\u201Cmarginal\u201D) image generation."),js=p(),ce=n("div"),u(nt.$$.fragment),Gs=p(),Zi=n("p"),$s=s("Manually set the generation mode to image-conditioned text generation."),Ws=p(),ue=n("div"),u(at.$$.fragment),Ds=p(),Ji=n("p"),Ps=s("Manually set the generation mode to unconditional joint image-text generation."),Xs=p(),he=n("div"),u(ot.$$.fragment),ks=p(),Ii=n("p"),Vs=s("Manually set the generation mode to unconditional (\u201Cmarginal\u201D) text generation."),Bs=p(),ge=n("div"),u(st.$$.fragment),Cs=p(),ji=n("p"),Ns=s("Manually set the generation mode to text-conditioned image generation."),this.h()},l(e){const d=Pl('[data-svelte="svelte-1phssyn"]',document.head);W=a(d,"META",{name:!0,content:!0}),d.forEach(i),Gi=f(e),D=a(e,"H1",{class:!0});var _n=o(D);S=a(_n,"A",{id:!0,class:!0,href:!0});var Ys=o(S);Dt=a(Ys,"SPAN",{});var zs=o(Dt);h(we.$$.fragment,zs),zs.forEach(i),Ys.forEach(i),An=f(_n),Pt=a(_n,"SPAN",{});var As=o(Pt);Ln=r(As,"UniDiffuser"),As.forEach(i),_n.forEach(i),$i=f(e),Q=a(e,"P",{});var bn=o(Q);Hn=r(bn,"The UniDiffuser model was proposed in "),ye=a(bn,"A",{href:!0,rel:!0});var Ls=o(ye);qn=r(Ls,"One Transformer Fits All Distributions in Multi-Modal Diffusion at Scale"),Ls.forEach(i),On=r(bn," by Fan Bao, Shen Nie, Kaiwen Xue, Chongxuan Li, Shi Pu, Yaole Wang, Gang Yue, Yue Cao, Hang Su, Jun Zhu."),bn.forEach(i),Wi=f(e),Y=a(e,"P",{});var vn=o(Y);Kn=r(vn,"The abstract of the "),Ue=a(vn,"A",{href:!0,rel:!0});var Hs=o(Ue);ea=r(Hs,"paper"),Hs.forEach(i),ta=r(vn," is the following:"),vn.forEach(i),Di=f(e),lt=a(e,"P",{});var qs=o(lt);Xt=a(qs,"EM",{});var Os=o(Xt);ia=r(Os,"This paper proposes a unified diffusion framework (dubbed UniDiffuser) to fit all distributions relevant to a set of multi-modal data in one model. Our key insight is \u2014 learning diffusion models for marginal, conditional, and joint distributions can be unified as predicting the noise in the perturbed data, where the perturbation levels (i.e. timesteps) can be different for different modalities. Inspired by the unified view, UniDiffuser learns all distributions simultaneously with a minimal modification to the original diffusion model \u2014 perturbs data in all modalities instead of a single modality, inputs individual timesteps in different modalities, and predicts the noise of all modalities instead of a single modality. UniDiffuser is parameterized by a transformer for diffusion models to handle input types of different modalities. Implemented on large-scale paired image-text data, UniDiffuser is able to perform image, text, text-to-image, image-to-text, and image-text pair generation by setting proper timesteps without additional overhead. In particular, UniDiffuser is able to produce perceptually realistic samples in all tasks and its quantitative results (e.g., the FID and CLIP score) are not only superior to existing general-purpose models but also comparable to the bespoken models (e.g., Stable Diffusion and DALL-E 2) in representative tasks (e.g., text-to-image generation)."),Os.forEach(i),qs.forEach(i),Pi=f(e),dt=a(e,"P",{});var Ks=o(dt);na=r(Ks,"Resources:"),Ks.forEach(i),Xi=f(e),z=a(e,"UL",{});var wn=o(z);pt=a(wn,"LI",{});var Rs=o(pt);xe=a(Rs,"A",{href:!0,rel:!0});var er=o(xe);aa=r(er,"Paper"),er.forEach(i),oa=r(Rs,"."),Rs.forEach(i),sa=f(wn),ft=a(wn,"LI",{});var Fs=o(ft);Me=a(Fs,"A",{href:!0,rel:!0});var tr=o(Me);ra=r(tr,"Original Code"),tr.forEach(i),la=r(Fs,"."),Fs.forEach(i),wn.forEach(i),ki=f(e),mt=a(e,"P",{});var ir=o(mt);da=r(ir,"Available Checkpoints are:"),ir.forEach(i),Vi=f(e),A=a(e,"UL",{});var yn=o(A);Te=a(yn,"LI",{});var Un=o(Te);kt=a(Un,"EM",{});var nr=o(kt);pa=r(nr,"UniDiffuser-v0 (512x512 resolution)"),nr.forEach(i),fa=f(Un),Ee=a(Un,"A",{href:!0,rel:!0});var ar=o(Ee);ma=r(ar,"thu-ml/unidiffuser-v0"),ar.forEach(i),Un.forEach(i),ca=f(yn),Ze=a(yn,"LI",{});var xn=o(Ze);Vt=a(xn,"EM",{});var or=o(Vt);ua=r(or,"UniDiffuser-v1 (512x512 resolution)"),or.forEach(i),ha=f(xn),Je=a(xn,"A",{href:!0,rel:!0});var sr=o(Je);ga=r(sr,"thu-ml/unidiffuser-v1"),sr.forEach(i),xn.forEach(i),yn.forEach(i),Bi=f(e),L=a(e,"P",{});var Mn=o(L);_a=r(Mn,"This pipeline was contributed by our community member "),Ie=a(Mn,"A",{href:!0,rel:!0});var rr=o(Ie);ba=r(rr,"dg845"),rr.forEach(i),va=r(Mn,"."),Mn.forEach(i),Ci=f(e),P=a(e,"H2",{class:!0});var Tn=o(P);H=a(Tn,"A",{id:!0,class:!0,href:!0});var lr=o(H);Bt=a(lr,"SPAN",{});var dr=o(Bt);h(je.$$.fragment,dr),dr.forEach(i),lr.forEach(i),wa=f(Tn),Ct=a(Tn,"SPAN",{});var pr=o(Ct);ya=r(pr,"Available Pipelines:"),pr.forEach(i),Tn.forEach(i),Ni=f(e),q=a(e,"TABLE",{});var En=o(q);Nt=a(En,"THEAD",{});var fr=o(Nt);Z=a(fr,"TR",{});var _e=o(Z);ct=a(_e,"TH",{align:!0});var mr=o(ct);Ua=r(mr,"Pipeline"),mr.forEach(i),xa=f(_e),ut=a(_e,"TH",{align:!0});var cr=o(ut);Ma=r(cr,"Tasks"),cr.forEach(i),Ta=f(_e),ht=a(_e,"TH",{align:!0});var ur=o(ht);Ea=r(ur,"Demo"),ur.forEach(i),Za=f(_e),gt=a(_e,"TH",{align:!0});var hr=o(gt);Ja=r(hr,"Colab"),hr.forEach(i),_e.forEach(i),fr.forEach(i),Ia=f(En),Rt=a(En,"TBODY",{});var gr=o(Rt);J=a(gr,"TR",{});var be=o(J);_t=a(be,"TD",{align:!0});var _r=o(_t);Ge=a(_r,"A",{href:!0,rel:!0});var br=o(Ge);ja=r(br,"UniDiffuserPipeline"),br.forEach(i),_r.forEach(i),Ga=f(be),y=a(be,"TD",{align:!0});var x=o(y);Ft=a(x,"EM",{});var vr=o(Ft);$a=r(vr,"Joint Image-Text Gen"),vr.forEach(i),Wa=r(x,", "),St=a(x,"EM",{});var wr=o(St);Da=r(wr,"Text-to-Image"),wr.forEach(i),Pa=r(x,", "),Qt=a(x,"EM",{});var yr=o(Qt);Xa=r(yr,"Image-to-Text"),yr.forEach(i),ka=r(x,","),Va=a(x,"BR",{}),Ba=f(x),Yt=a(x,"EM",{});var Ur=o(Yt);Ca=r(Ur,"Image Gen"),Ur.forEach(i),Na=r(x,", "),zt=a(x,"EM",{});var xr=o(zt);Ra=r(xr,"Text Gen"),xr.forEach(i),Fa=r(x,", "),At=a(x,"EM",{});var Mr=o(At);Sa=r(Mr,"Image Variation"),Mr.forEach(i),Qa=r(x,", "),Lt=a(x,"EM",{});var Tr=o(Lt);Ya=r(Tr,"Text Variation"),Tr.forEach(i),x.forEach(i),za=f(be),bt=a(be,"TD",{align:!0});var Er=o(bt);$e=a(Er,"A",{href:!0,rel:!0});var Zr=o($e);Aa=r(Zr,"\u{1F917} Spaces"),Zr.forEach(i),Er.forEach(i),La=f(be),vt=a(be,"TD",{align:!0});var Jr=o(vt);We=a(Jr,"A",{href:!0,rel:!0});var Ir=o(We);wt=a(Ir,"IMG",{src:!0,alt:!0}),Ir.forEach(i),Jr.forEach(i),be.forEach(i),gr.forEach(i),En.forEach(i),Ri=f(e),X=a(e,"H2",{class:!0});var Zn=o(X);O=a(Zn,"A",{id:!0,class:!0,href:!0});var jr=o(O);Ht=a(jr,"SPAN",{});var Gr=o(Ht);h(De.$$.fragment,Gr),Gr.forEach(i),jr.forEach(i),Ha=f(Zn),qt=a(Zn,"SPAN",{});var $r=o(qt);qa=r($r,"Usage Examples"),$r.forEach(i),Zn.forEach(i),Fi=f(e),yt=a(e,"P",{});var Wr=o(yt);Oa=r(Wr,"Because the UniDiffuser model is trained to model the joint distribution of (image, text) pairs, it is capable of performing a diverse range of generation tasks."),Wr.forEach(i),Si=f(e),k=a(e,"H3",{class:!0});var Jn=o(k);K=a(Jn,"A",{id:!0,class:!0,href:!0});var Dr=o(K);Ot=a(Dr,"SPAN",{});var Pr=o(Ot);h(Pe.$$.fragment,Pr),Pr.forEach(i),Dr.forEach(i),Ka=f(Jn),Kt=a(Jn,"SPAN",{});var Xr=o(Kt);eo=r(Xr,"Unconditional Image and Text Generation"),Xr.forEach(i),Jn.forEach(i),Qi=f(e),ee=a(e,"P",{});var In=o(ee);to=r(In,"Unconditional generation (where we start from only latents sampled from a standard Gaussian prior) from a "),Ut=a(In,"A",{href:!0});var kr=o(Ut);io=r(kr,"UniDiffuserPipeline"),kr.forEach(i),no=r(In," will produce a (image, text) pair:"),In.forEach(i),Yi=f(e),h(Xe.$$.fragment,e),zi=f(e),xt=a(e,"P",{});var Vr=o(xt);ao=r(Vr,"This is also called \u201Cjoint\u201D generation in the UniDiffusers paper, since we are sampling from the joint image-text distribution."),Vr.forEach(i),Ai=f(e),te=a(e,"P",{});var jn=o(te);oo=r(jn,`Note that the generation task is inferred from the inputs used when calling the pipeline.
It is also possible to manually specify the unconditional generation task (\u201Cmode\u201D) manually with `),Mt=a(jn,"A",{href:!0});var Br=o(Mt);so=r(Br,"UniDiffuserPipeline.set_joint_mode()"),Br.forEach(i),ro=r(jn,":"),jn.forEach(i),Li=f(e),h(ke.$$.fragment,e),Hi=f(e),ie=a(e,"P",{});var Gn=o(ie);lo=r(Gn,`When the mode is set manually, subsequent calls to the pipeline will use the set mode without attempting the infer the mode.
You can reset the mode with `),Tt=a(Gn,"A",{href:!0});var Cr=o(Tt);po=r(Cr,"UniDiffuserPipeline.reset_mode()"),Cr.forEach(i),fo=r(Gn,", after which the pipeline will once again infer the mode."),Gn.forEach(i),qi=f(e),Et=a(e,"P",{});var Nr=o(Et);mo=r(Nr,"You can also generate only an image or only text (which the UniDiffuser paper calls \u201Cmarginal\u201D generation since we sample from the marginal distribution of images and text, respectively):"),Nr.forEach(i),Oi=f(e),h(Ve.$$.fragment,e),Ki=f(e),V=a(e,"H3",{class:!0});var $n=o(V);ne=a($n,"A",{id:!0,class:!0,href:!0});var Rr=o(ne);ei=a(Rr,"SPAN",{});var Fr=o(ei);h(Be.$$.fragment,Fr),Fr.forEach(i),Rr.forEach(i),co=f($n),ti=a($n,"SPAN",{});var Sr=o(ti);uo=r(Sr,"Text-to-Image Generation"),Sr.forEach(i),$n.forEach(i),en=f(e),Zt=a(e,"P",{});var Qr=o(Zt);ho=r(Qr,`UniDiffuser is also capable of sampling from conditional distributions; that is, the distribution of images conditioned on a text prompt or the distribution of texts conditioned on an image.
Here is an example of sampling from the conditional image distribution (text-to-image generation or text-conditioned image generation):`),Qr.forEach(i),tn=f(e),h(Ce.$$.fragment,e),nn=f(e),U=a(e,"P",{});var E=o(U);go=r(E,"The "),ii=a(E,"CODE",{});var Yr=o(ii);_o=r(Yr,"text2img"),Yr.forEach(i),bo=r(E," mode requires that either an input "),ni=a(E,"CODE",{});var zr=o(ni);vo=r(zr,"prompt"),zr.forEach(i),wo=r(E," or "),ai=a(E,"CODE",{});var Ar=o(ai);yo=r(Ar,"prompt_embeds"),Ar.forEach(i),Uo=r(E," be supplied. You can set the "),oi=a(E,"CODE",{});var Lr=o(oi);xo=r(Lr,"text2img"),Lr.forEach(i),Mo=r(E," mode manually with "),Jt=a(E,"A",{href:!0});var Hr=o(Jt);To=r(Hr,"UniDiffuserPipeline.set_text_to_image_mode()"),Hr.forEach(i),Eo=r(E,"."),E.forEach(i),an=f(e),B=a(e,"H3",{class:!0});var Wn=o(B);ae=a(Wn,"A",{id:!0,class:!0,href:!0});var qr=o(ae);si=a(qr,"SPAN",{});var Or=o(si);h(Ne.$$.fragment,Or),Or.forEach(i),qr.forEach(i),Zo=f(Wn),ri=a(Wn,"SPAN",{});var Kr=o(ri);Jo=r(Kr,"Image-to-Text Generation"),Kr.forEach(i),Wn.forEach(i),on=f(e),It=a(e,"P",{});var el=o(It);Io=r(el,"Similarly, UniDiffuser can also produce text samples given an image (image-to-text or image-conditioned text generation):"),el.forEach(i),sn=f(e),h(Re.$$.fragment,e),rn=f(e),M=a(e,"P",{});var j=o(M);jo=r(j,"The "),li=a(j,"CODE",{});var tl=o(li);Go=r(tl,"img2text"),tl.forEach(i),$o=r(j," mode requires that an input "),di=a(j,"CODE",{});var il=o(di);Wo=r(il,"image"),il.forEach(i),Do=r(j," be supplied. You can set the "),pi=a(j,"CODE",{});var nl=o(pi);Po=r(nl,"img2text"),nl.forEach(i),Xo=r(j," mode manually with "),jt=a(j,"A",{href:!0});var al=o(jt);ko=r(al,"UniDiffuserPipeline.set_image_to_text_mode()"),al.forEach(i),Vo=r(j,"."),j.forEach(i),ln=f(e),C=a(e,"H3",{class:!0});var Dn=o(C);oe=a(Dn,"A",{id:!0,class:!0,href:!0});var ol=o(oe);fi=a(ol,"SPAN",{});var sl=o(fi);h(Fe.$$.fragment,sl),sl.forEach(i),ol.forEach(i),Bo=f(Dn),mi=a(Dn,"SPAN",{});var rl=o(mi);Co=r(rl,"Image Variation"),rl.forEach(i),Dn.forEach(i),dn=f(e),Gt=a(e,"P",{});var ll=o(Gt);No=r(ll,`The UniDiffuser authors suggest performing image variation through a \u201Cround-trip\u201D generation method, where given an input image, we first perform an image-to-text generation, and the perform a text-to-image generation on the outputs of the first generation.
This produces a new image which is semantically similar to the input image:`),ll.forEach(i),pn=f(e),h(Se.$$.fragment,e),fn=f(e),N=a(e,"H3",{class:!0});var Pn=o(N);se=a(Pn,"A",{id:!0,class:!0,href:!0});var dl=o(se);ci=a(dl,"SPAN",{});var pl=o(ci);h(Qe.$$.fragment,pl),pl.forEach(i),dl.forEach(i),Ro=f(Pn),ui=a(Pn,"SPAN",{});var fl=o(ui);Fo=r(fl,"Text Variation"),fl.forEach(i),Pn.forEach(i),mn=f(e),$t=a(e,"P",{});var ml=o($t);So=r(ml,"Similarly, text variation can be performed on an input prompt with a text-to-image generation followed by a image-to-text generation:"),ml.forEach(i),cn=f(e),h(Ye.$$.fragment,e),un=f(e),R=a(e,"H2",{class:!0});var Xn=o(R);re=a(Xn,"A",{id:!0,class:!0,href:!0});var cl=o(re);hi=a(cl,"SPAN",{});var ul=o(hi);h(ze.$$.fragment,ul),ul.forEach(i),cl.forEach(i),Qo=f(Xn),gi=a(Xn,"SPAN",{});var hl=o(gi);Yo=r(hl,"UniDiffuserPipeline"),hl.forEach(i),Xn.forEach(i),hn=f(e),c=a(e,"DIV",{class:!0});var w=o(c);h(Ae.$$.fragment,w),zo=f(w),Le=a(w,"P",{});var kn=o(Le);Ao=r(kn,"Pipeline for a bimodal image-text "),He=a(kn,"A",{href:!0,rel:!0});var gl=o(He);Lo=r(gl,"UniDiffuser"),gl.forEach(i),Ho=r(kn,` model, which supports
unconditional text and image generation, text-conditioned image generation, image-conditioned text generation, and
joint image-text generation.`),kn.forEach(i),qo=f(w),qe=a(w,"P",{});var Vn=o(qe);Oo=r(Vn,"This model inherits from "),Wt=a(Vn,"A",{href:!0});var _l=o(Wt);Ko=r(_l,"DiffusionPipeline"),_l.forEach(i),es=r(Vn,`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),Vn.forEach(i),ts=f(w),le=a(w,"DIV",{class:!0});var Bn=o(le);h(Oe.$$.fragment,Bn),is=f(Bn),_i=a(Bn,"P",{});var bl=o(_i);ns=r(bl,"Function invoked when calling the pipeline for generation."),bl.forEach(i),Bn.forEach(i),as=f(w),de=a(w,"DIV",{class:!0});var Cn=o(de);h(Ke.$$.fragment,Cn),os=f(Cn),T=a(Cn,"P",{});var G=o(T);ss=r(G,`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),bi=a(G,"CODE",{});var vl=o(bi);rs=r(vl,"enable_sequential_cpu_offload"),vl.forEach(i),ls=r(G,", this method moves one whole model at a time to the GPU when its "),vi=a(G,"CODE",{});var wl=o(vi);ds=r(wl,"forward"),wl.forEach(i),ps=r(G,`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),wi=a(G,"CODE",{});var yl=o(wi);fs=r(yl,"enable_sequential_cpu_offload"),yl.forEach(i),ms=r(G,", but performance is much better due to the iterative execution of the "),yi=a(G,"CODE",{});var Ul=o(yi);cs=r(Ul,"unet"),Ul.forEach(i),us=r(G,"."),G.forEach(i),Cn.forEach(i),hs=f(w),pe=a(w,"DIV",{class:!0});var Nn=o(pe);h(et.$$.fragment,Nn),gs=f(Nn),I=a(Nn,"P",{});var ve=o(I);_s=r(ve,`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),Ui=a(ve,"CODE",{});var xl=o(Ui);bs=r(xl,"torch.device('meta')"),xl.forEach(i),vs=r(ve," and loaded to GPU only when their specific submodule has its "),xi=a(ve,"CODE",{});var Ml=o(xi);ws=r(Ml,"forward"),Ml.forEach(i),ys=r(ve,` method called.
Note that offloading happens on a submodule basis. Memory savings are higher than with
`),Mi=a(ve,"CODE",{});var Tl=o(Mi);Us=r(Tl,"enable_model_cpu_offload"),Tl.forEach(i),xs=r(ve,", but performance is lower."),ve.forEach(i),Nn.forEach(i),Ms=f(w),fe=a(w,"DIV",{class:!0});var Rn=o(fe);h(tt.$$.fragment,Rn),Ts=f(Rn),Ti=a(Rn,"P",{});var El=o(Ti);Es=r(El,"Removes a manually set mode; after calling this, the pipeline will infer the mode from inputs."),El.forEach(i),Rn.forEach(i),Zs=f(w),me=a(w,"DIV",{class:!0});var Fn=o(me);h(it.$$.fragment,Fn),Js=f(Fn),Ei=a(Fn,"P",{});var Zl=o(Ei);Is=r(Zl,"Manually set the generation mode to unconditional (\u201Cmarginal\u201D) image generation."),Zl.forEach(i),Fn.forEach(i),js=f(w),ce=a(w,"DIV",{class:!0});var Sn=o(ce);h(nt.$$.fragment,Sn),Gs=f(Sn),Zi=a(Sn,"P",{});var Jl=o(Zi);$s=r(Jl,"Manually set the generation mode to image-conditioned text generation."),Jl.forEach(i),Sn.forEach(i),Ws=f(w),ue=a(w,"DIV",{class:!0});var Qn=o(ue);h(at.$$.fragment,Qn),Ds=f(Qn),Ji=a(Qn,"P",{});var Il=o(Ji);Ps=r(Il,"Manually set the generation mode to unconditional joint image-text generation."),Il.forEach(i),Qn.forEach(i),Xs=f(w),he=a(w,"DIV",{class:!0});var Yn=o(he);h(ot.$$.fragment,Yn),ks=f(Yn),Ii=a(Yn,"P",{});var jl=o(Ii);Vs=r(jl,"Manually set the generation mode to unconditional (\u201Cmarginal\u201D) text generation."),jl.forEach(i),Yn.forEach(i),Bs=f(w),ge=a(w,"DIV",{class:!0});var zn=o(ge);h(st.$$.fragment,zn),Cs=f(zn),ji=a(zn,"P",{});var Gl=o(ji);Ns=r(Gl,"Manually set the generation mode to text-conditioned image generation."),Gl.forEach(i),zn.forEach(i),w.forEach(i),this.h()},h(){l(W,"name","hf:doc:metadata"),l(W,"content",JSON.stringify(Cl)),l(S,"id","unidiffuser"),l(S,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(S,"href","#unidiffuser"),l(D,"class","relative group"),l(ye,"href","https://arxiv.org/abs/2303.06555"),l(ye,"rel","nofollow"),l(Ue,"href","https://arxiv.org/abs/2303.06555"),l(Ue,"rel","nofollow"),l(xe,"href","https://arxiv.org/abs/2303.06555"),l(xe,"rel","nofollow"),l(Me,"href","https://github.com/thu-ml/unidiffuser"),l(Me,"rel","nofollow"),l(Ee,"href","https://huggingface.co/thu-ml/unidiffuser-v0"),l(Ee,"rel","nofollow"),l(Je,"href","https://huggingface.co/thu-ml/unidiffuser-v1"),l(Je,"rel","nofollow"),l(Ie,"href","https://github.com/dg845"),l(Ie,"rel","nofollow"),l(H,"id","available-pipelines"),l(H,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(H,"href","#available-pipelines"),l(P,"class","relative group"),l(ct,"align","center"),l(ut,"align","center"),l(ht,"align","center"),l(gt,"align","center"),l(Ge,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_unidiffuser.py"),l(Ge,"rel","nofollow"),l(_t,"align","center"),l(y,"align","center"),l($e,"href","https://huggingface.co/spaces/thu-ml/unidiffuser"),l($e,"rel","nofollow"),l(bt,"align","center"),Xl(wt.src,Qs="https://colab.research.google.com/assets/colab-badge.svg")||l(wt,"src",Qs),l(wt,"alt","Open In Colab"),l(We,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/unidiffuser.ipynb"),l(We,"rel","nofollow"),l(vt,"align","center"),l(O,"id","usage-examples"),l(O,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(O,"href","#usage-examples"),l(X,"class","relative group"),l(K,"id","unconditional-image-and-text-generation"),l(K,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(K,"href","#unconditional-image-and-text-generation"),l(k,"class","relative group"),l(Ut,"href","/docs/diffusers/v0.18.0/en/api/pipelines/unidiffuser#diffusers.UniDiffuserPipeline"),l(Mt,"href","/docs/diffusers/v0.18.0/en/api/pipelines/unidiffuser#diffusers.UniDiffuserPipeline.set_joint_mode"),l(Tt,"href","/docs/diffusers/v0.18.0/en/api/pipelines/unidiffuser#diffusers.UniDiffuserPipeline.reset_mode"),l(ne,"id","texttoimage-generation"),l(ne,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(ne,"href","#texttoimage-generation"),l(V,"class","relative group"),l(Jt,"href","/docs/diffusers/v0.18.0/en/api/pipelines/unidiffuser#diffusers.UniDiffuserPipeline.set_text_to_image_mode"),l(ae,"id","imagetotext-generation"),l(ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(ae,"href","#imagetotext-generation"),l(B,"class","relative group"),l(jt,"href","/docs/diffusers/v0.18.0/en/api/pipelines/unidiffuser#diffusers.UniDiffuserPipeline.set_image_to_text_mode"),l(oe,"id","image-variation"),l(oe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(oe,"href","#image-variation"),l(C,"class","relative group"),l(se,"id","text-variation"),l(se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(se,"href","#text-variation"),l(N,"class","relative group"),l(re,"id","diffusers.UniDiffuserPipeline"),l(re,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(re,"href","#diffusers.UniDiffuserPipeline"),l(R,"class","relative group"),l(He,"href","https://arxiv.org/pdf/2303.06555.pdf"),l(He,"rel","nofollow"),l(Wt,"href","/docs/diffusers/v0.18.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),l(le,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(de,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(pe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(fe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(me,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ce,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ue,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(he,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ge,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(c,"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,d){t(document.head,W),m(e,Gi,d),m(e,D,d),t(D,S),t(S,Dt),g(we,Dt,null),t(D,An),t(D,Pt),t(Pt,Ln),m(e,$i,d),m(e,Q,d),t(Q,Hn),t(Q,ye),t(ye,qn),t(Q,On),m(e,Wi,d),m(e,Y,d),t(Y,Kn),t(Y,Ue),t(Ue,ea),t(Y,ta),m(e,Di,d),m(e,lt,d),t(lt,Xt),t(Xt,ia),m(e,Pi,d),m(e,dt,d),t(dt,na),m(e,Xi,d),m(e,z,d),t(z,pt),t(pt,xe),t(xe,aa),t(pt,oa),t(z,sa),t(z,ft),t(ft,Me),t(Me,ra),t(ft,la),m(e,ki,d),m(e,mt,d),t(mt,da),m(e,Vi,d),m(e,A,d),t(A,Te),t(Te,kt),t(kt,pa),t(Te,fa),t(Te,Ee),t(Ee,ma),t(A,ca),t(A,Ze),t(Ze,Vt),t(Vt,ua),t(Ze,ha),t(Ze,Je),t(Je,ga),m(e,Bi,d),m(e,L,d),t(L,_a),t(L,Ie),t(Ie,ba),t(L,va),m(e,Ci,d),m(e,P,d),t(P,H),t(H,Bt),g(je,Bt,null),t(P,wa),t(P,Ct),t(Ct,ya),m(e,Ni,d),m(e,q,d),t(q,Nt),t(Nt,Z),t(Z,ct),t(ct,Ua),t(Z,xa),t(Z,ut),t(ut,Ma),t(Z,Ta),t(Z,ht),t(ht,Ea),t(Z,Za),t(Z,gt),t(gt,Ja),t(q,Ia),t(q,Rt),t(Rt,J),t(J,_t),t(_t,Ge),t(Ge,ja),t(J,Ga),t(J,y),t(y,Ft),t(Ft,$a),t(y,Wa),t(y,St),t(St,Da),t(y,Pa),t(y,Qt),t(Qt,Xa),t(y,ka),t(y,Va),t(y,Ba),t(y,Yt),t(Yt,Ca),t(y,Na),t(y,zt),t(zt,Ra),t(y,Fa),t(y,At),t(At,Sa),t(y,Qa),t(y,Lt),t(Lt,Ya),t(J,za),t(J,bt),t(bt,$e),t($e,Aa),t(J,La),t(J,vt),t(vt,We),t(We,wt),m(e,Ri,d),m(e,X,d),t(X,O),t(O,Ht),g(De,Ht,null),t(X,Ha),t(X,qt),t(qt,qa),m(e,Fi,d),m(e,yt,d),t(yt,Oa),m(e,Si,d),m(e,k,d),t(k,K),t(K,Ot),g(Pe,Ot,null),t(k,Ka),t(k,Kt),t(Kt,eo),m(e,Qi,d),m(e,ee,d),t(ee,to),t(ee,Ut),t(Ut,io),t(ee,no),m(e,Yi,d),g(Xe,e,d),m(e,zi,d),m(e,xt,d),t(xt,ao),m(e,Ai,d),m(e,te,d),t(te,oo),t(te,Mt),t(Mt,so),t(te,ro),m(e,Li,d),g(ke,e,d),m(e,Hi,d),m(e,ie,d),t(ie,lo),t(ie,Tt),t(Tt,po),t(ie,fo),m(e,qi,d),m(e,Et,d),t(Et,mo),m(e,Oi,d),g(Ve,e,d),m(e,Ki,d),m(e,V,d),t(V,ne),t(ne,ei),g(Be,ei,null),t(V,co),t(V,ti),t(ti,uo),m(e,en,d),m(e,Zt,d),t(Zt,ho),m(e,tn,d),g(Ce,e,d),m(e,nn,d),m(e,U,d),t(U,go),t(U,ii),t(ii,_o),t(U,bo),t(U,ni),t(ni,vo),t(U,wo),t(U,ai),t(ai,yo),t(U,Uo),t(U,oi),t(oi,xo),t(U,Mo),t(U,Jt),t(Jt,To),t(U,Eo),m(e,an,d),m(e,B,d),t(B,ae),t(ae,si),g(Ne,si,null),t(B,Zo),t(B,ri),t(ri,Jo),m(e,on,d),m(e,It,d),t(It,Io),m(e,sn,d),g(Re,e,d),m(e,rn,d),m(e,M,d),t(M,jo),t(M,li),t(li,Go),t(M,$o),t(M,di),t(di,Wo),t(M,Do),t(M,pi),t(pi,Po),t(M,Xo),t(M,jt),t(jt,ko),t(M,Vo),m(e,ln,d),m(e,C,d),t(C,oe),t(oe,fi),g(Fe,fi,null),t(C,Bo),t(C,mi),t(mi,Co),m(e,dn,d),m(e,Gt,d),t(Gt,No),m(e,pn,d),g(Se,e,d),m(e,fn,d),m(e,N,d),t(N,se),t(se,ci),g(Qe,ci,null),t(N,Ro),t(N,ui),t(ui,Fo),m(e,mn,d),m(e,$t,d),t($t,So),m(e,cn,d),g(Ye,e,d),m(e,un,d),m(e,R,d),t(R,re),t(re,hi),g(ze,hi,null),t(R,Qo),t(R,gi),t(gi,Yo),m(e,hn,d),m(e,c,d),g(Ae,c,null),t(c,zo),t(c,Le),t(Le,Ao),t(Le,He),t(He,Lo),t(Le,Ho),t(c,qo),t(c,qe),t(qe,Oo),t(qe,Wt),t(Wt,Ko),t(qe,es),t(c,ts),t(c,le),g(Oe,le,null),t(le,is),t(le,_i),t(_i,ns),t(c,as),t(c,de),g(Ke,de,null),t(de,os),t(de,T),t(T,ss),t(T,bi),t(bi,rs),t(T,ls),t(T,vi),t(vi,ds),t(T,ps),t(T,wi),t(wi,fs),t(T,ms),t(T,yi),t(yi,cs),t(T,us),t(c,hs),t(c,pe),g(et,pe,null),t(pe,gs),t(pe,I),t(I,_s),t(I,Ui),t(Ui,bs),t(I,vs),t(I,xi),t(xi,ws),t(I,ys),t(I,Mi),t(Mi,Us),t(I,xs),t(c,Ms),t(c,fe),g(tt,fe,null),t(fe,Ts),t(fe,Ti),t(Ti,Es),t(c,Zs),t(c,me),g(it,me,null),t(me,Js),t(me,Ei),t(Ei,Is),t(c,js),t(c,ce),g(nt,ce,null),t(ce,Gs),t(ce,Zi),t(Zi,$s),t(c,Ws),t(c,ue),g(at,ue,null),t(ue,Ds),t(ue,Ji),t(Ji,Ps),t(c,Xs),t(c,he),g(ot,he,null),t(he,ks),t(he,Ii),t(Ii,Vs),t(c,Bs),t(c,ge),g(st,ge,null),t(ge,Cs),t(ge,ji),t(ji,Ns),gn=!0},p:kl,i(e){gn||(_(we.$$.fragment,e),_(je.$$.fragment,e),_(De.$$.fragment,e),_(Pe.$$.fragment,e),_(Xe.$$.fragment,e),_(ke.$$.fragment,e),_(Ve.$$.fragment,e),_(Be.$$.fragment,e),_(Ce.$$.fragment,e),_(Ne.$$.fragment,e),_(Re.$$.fragment,e),_(Fe.$$.fragment,e),_(Se.$$.fragment,e),_(Qe.$$.fragment,e),_(Ye.$$.fragment,e),_(ze.$$.fragment,e),_(Ae.$$.fragment,e),_(Oe.$$.fragment,e),_(Ke.$$.fragment,e),_(et.$$.fragment,e),_(tt.$$.fragment,e),_(it.$$.fragment,e),_(nt.$$.fragment,e),_(at.$$.fragment,e),_(ot.$$.fragment,e),_(st.$$.fragment,e),gn=!0)},o(e){b(we.$$.fragment,e),b(je.$$.fragment,e),b(De.$$.fragment,e),b(Pe.$$.fragment,e),b(Xe.$$.fragment,e),b(ke.$$.fragment,e),b(Ve.$$.fragment,e),b(Be.$$.fragment,e),b(Ce.$$.fragment,e),b(Ne.$$.fragment,e),b(Re.$$.fragment,e),b(Fe.$$.fragment,e),b(Se.$$.fragment,e),b(Qe.$$.fragment,e),b(Ye.$$.fragment,e),b(ze.$$.fragment,e),b(Ae.$$.fragment,e),b(Oe.$$.fragment,e),b(Ke.$$.fragment,e),b(et.$$.fragment,e),b(tt.$$.fragment,e),b(it.$$.fragment,e),b(nt.$$.fragment,e),b(at.$$.fragment,e),b(ot.$$.fragment,e),b(st.$$.fragment,e),gn=!1},d(e){i(W),e&&i(Gi),e&&i(D),v(we),e&&i($i),e&&i(Q),e&&i(Wi),e&&i(Y),e&&i(Di),e&&i(lt),e&&i(Pi),e&&i(dt),e&&i(Xi),e&&i(z),e&&i(ki),e&&i(mt),e&&i(Vi),e&&i(A),e&&i(Bi),e&&i(L),e&&i(Ci),e&&i(P),v(je),e&&i(Ni),e&&i(q),e&&i(Ri),e&&i(X),v(De),e&&i(Fi),e&&i(yt),e&&i(Si),e&&i(k),v(Pe),e&&i(Qi),e&&i(ee),e&&i(Yi),v(Xe,e),e&&i(zi),e&&i(xt),e&&i(Ai),e&&i(te),e&&i(Li),v(ke,e),e&&i(Hi),e&&i(ie),e&&i(qi),e&&i(Et),e&&i(Oi),v(Ve,e),e&&i(Ki),e&&i(V),v(Be),e&&i(en),e&&i(Zt),e&&i(tn),v(Ce,e),e&&i(nn),e&&i(U),e&&i(an),e&&i(B),v(Ne),e&&i(on),e&&i(It),e&&i(sn),v(Re,e),e&&i(rn),e&&i(M),e&&i(ln),e&&i(C),v(Fe),e&&i(dn),e&&i(Gt),e&&i(pn),v(Se,e),e&&i(fn),e&&i(N),v(Qe),e&&i(mn),e&&i($t),e&&i(cn),v(Ye,e),e&&i(un),e&&i(R),v(ze),e&&i(hn),e&&i(c),v(Ae),v(Oe),v(Ke),v(et),v(tt),v(it),v(nt),v(at),v(ot),v(st)}}}const Cl={local:"unidiffuser",sections:[{local:"available-pipelines",title:"Available Pipelines:"},{local:"usage-examples",sections:[{local:"unconditional-image-and-text-generation",title:"Unconditional Image and Text Generation"},{local:"texttoimage-generation",title:"Text-to-Image Generation"},{local:"imagetotext-generation",title:"Image-to-Text Generation"},{local:"image-variation",title:"Image Variation"},{local:"text-variation",title:"Text Variation"}],title:"Usage Examples"},{local:"diffusers.UniDiffuserPipeline",title:"UniDiffuserPipeline"}],title:"UniDiffuser"};function Nl(Ss){return Vl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Yl extends $l{constructor(W){super();Wl(this,W,Nl,Bl,Dl,{})}}export{Yl as default,Cl as metadata};
