import{S as li,i as ni,s as si,e as i,k as h,w as fe,t as l,M as ui,c as o,d as a,m as f,a as r,x as pe,h as n,b as s,G as e,g as p,y as ce,L as hi,q as de,o as me,B as be,v as fi}from"../../chunks/vendor-hf-doc-builder.js";import{I as ht}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as ri}from"../../chunks/CodeBlock-hf-doc-builder.js";function pi(va){let b,je,_,G,_e,x,ft,ge,pt,Oe,D,ct,j,dt,mt,Le,g,k,ve,O,bt,we,_t,Me,S,L,gt,M,vt,wt,Et,Ee,yt,Ce,v,T,ye,C,$t,$e,Ht,Fe,X,Gt,Ne,A,w,Dt,F,He,kt,St,Ge,Tt,At,Pt,N,qt,B,De,It,xt,Be,c,jt,ke,Ot,Lt,Se,Mt,Ct,Te,Ft,Nt,z,Bt,zt,R,Rt,Ut,ze,U,Re,Z,Yt,Ue,Y,Ye,m,Wt,W,Jt,Kt,J,Qt,Vt,We,E,P,Ae,K,Xt,Pe,Zt,Je,q,ea,Q,ta,aa,Ke,I,qe,y,Qe,ia,ee,oa,ra,te,la,na,V,$,Ie,sa,ua,ae,ha,fa,ie,pa,ca,H,xe,da,ma,oe,ba,_a,re,ga,Ve;return x=new ht({}),O=new ht({}),C=new ht({}),U=new ri({props:{code:`from optimum.habana import GaudiConfig
from optimum.habana.diffusers import GaudiDDIMScheduler, GaudiStableDiffusionPipeline

model_name = "stabilityai/stable-diffusion-2-base"
scheduler = GaudiDDIMScheduler.from_pretrained(model_name, subfolder="scheduler")
pipeline = GaudiStableDiffusionPipeline.from_pretrained(
    model_name,
    scheduler=scheduler,
    use_habana=True,
    use_hpu_graphs=True,
    gaudi_config="Habana/stable-diffusion",
)`,highlighted:`<span class="hljs-keyword">from</span> optimum.habana <span class="hljs-keyword">import</span> GaudiConfig
<span class="hljs-keyword">from</span> optimum.habana.diffusers <span class="hljs-keyword">import</span> GaudiDDIMScheduler, GaudiStableDiffusionPipeline

model_name = <span class="hljs-string">&quot;stabilityai/stable-diffusion-2-base&quot;</span>
scheduler = GaudiDDIMScheduler.from_pretrained(model_name, subfolder=<span class="hljs-string">&quot;scheduler&quot;</span>)
pipeline = GaudiStableDiffusionPipeline.from_pretrained(
    model_name,
    scheduler=scheduler,
    use_habana=<span class="hljs-literal">True</span>,
    use_hpu_graphs=<span class="hljs-literal">True</span>,
    gaudi_config=<span class="hljs-string">&quot;Habana/stable-diffusion&quot;</span>,
)`}}),Y=new ri({props:{code:`outputs = pipeline(
    prompt=[
        "High quality photo of an astronaut riding a horse in space",
        "Face of a yellow cat, high resolution, sitting on a park bench",
    ],
    num_images_per_prompt=10,
    batch_size=4,
)`,highlighted:`outputs = pipeline(
    prompt=[
        <span class="hljs-string">&quot;High quality photo of an astronaut riding a horse in space&quot;</span>,
        <span class="hljs-string">&quot;Face of a yellow cat, high resolution, sitting on a park bench&quot;</span>,
    ],
    num_images_per_prompt=<span class="hljs-number">10</span>,
    batch_size=<span class="hljs-number">4</span>,
)`}}),K=new ht({}),{c(){b=i("meta"),je=h(),_=i("h1"),G=i("a"),_e=i("span"),fe(x.$$.fragment),ft=h(),ge=i("span"),pt=l("How to use Stable Diffusion on Habana Gaudi"),Oe=h(),D=i("p"),ct=l("\u{1F917} Diffusers is compatible with Habana Gaudi through \u{1F917} "),j=i("a"),dt=l("Optimum Habana"),mt=l("."),Le=h(),g=i("h2"),k=i("a"),ve=i("span"),fe(O.$$.fragment),bt=h(),we=i("span"),_t=l("Requirements"),Me=h(),S=i("ul"),L=i("li"),gt=l("Optimum Habana 1.3 or later, "),M=i("a"),vt=l("here"),wt=l(" is how to install it."),Et=h(),Ee=i("li"),yt=l("SynapseAI 1.7."),Ce=h(),v=i("h2"),T=i("a"),ye=i("span"),fe(C.$$.fragment),$t=h(),$e=i("span"),Ht=l("Inference Pipeline"),Fe=h(),X=i("p"),Gt=l("To generate images with Stable Diffusion 1 and 2 on Gaudi, you need to instantiate two instances:"),Ne=h(),A=i("ul"),w=i("li"),Dt=l("A pipeline with "),F=i("a"),He=i("code"),kt=l("GaudiStableDiffusionPipeline"),St=l(". This pipeline supports "),Ge=i("em"),Tt=l("text-to-image generation"),At=l("."),Pt=h(),N=i("li"),qt=l("A scheduler with "),B=i("a"),De=i("code"),It=l("GaudiDDIMScheduler"),xt=l(". This scheduler has been optimized for Habana Gaudi."),Be=h(),c=i("p"),jt=l("When initializing the pipeline, you have to specify "),ke=i("code"),Ot=l("use_habana=True"),Lt=l(` to deploy it on HPUs.
Furthermore, in order to get the fastest possible generations you should enable `),Se=i("strong"),Mt=l("HPU graphs"),Ct=l(" with "),Te=i("code"),Ft=l("use_hpu_graphs=True"),Nt=l(`.
Finally, you will need to specify a `),z=i("a"),Bt=l("Gaudi configuration"),zt=l(" which can be downloaded from the "),R=i("a"),Rt=l("Hugging Face Hub"),Ut=l("."),ze=h(),fe(U.$$.fragment),Re=h(),Z=i("p"),Yt=l("You can then call the pipeline to generate images by batches from one or several prompts:"),Ue=h(),fe(Y.$$.fragment),Ye=h(),m=i("p"),Wt=l("For more information, check out Optimum Habana\u2019s "),W=i("a"),Jt=l("documentation"),Kt=l(" and the "),J=i("a"),Qt=l("example"),Vt=l(" provided in the official Github repository."),We=h(),E=i("h2"),P=i("a"),Ae=i("span"),fe(K.$$.fragment),Xt=h(),Pe=i("span"),Zt=l("Benchmark"),Je=h(),q=i("p"),ea=l("Here are the latencies for Habana Gaudi 1 and Gaudi 2 with the "),Q=i("a"),ta=l("Habana/stable-diffusion"),aa=l(" Gaudi configuration (mixed precision bf16/fp32):"),Ke=h(),I=i("table"),qe=i("thead"),y=i("tr"),Qe=i("th"),ia=h(),ee=i("th"),oa=l("Latency"),ra=h(),te=i("th"),la=l("Batch size"),na=h(),V=i("tbody"),$=i("tr"),Ie=i("td"),sa=l("Gaudi 1"),ua=h(),ae=i("td"),ha=l("4.37s"),fa=h(),ie=i("td"),pa=l("4/8"),ca=h(),H=i("tr"),xe=i("td"),da=l("Gaudi 2"),ma=h(),oe=i("td"),ba=l("1.19s"),_a=h(),re=i("td"),ga=l("4/8"),this.h()},l(t){const u=ui('[data-svelte="svelte-1phssyn"]',document.head);b=o(u,"META",{name:!0,content:!0}),u.forEach(a),je=f(t),_=o(t,"H1",{class:!0});var Xe=r(_);G=o(Xe,"A",{id:!0,class:!0,href:!0});var wa=r(G);_e=o(wa,"SPAN",{});var Ea=r(_e);pe(x.$$.fragment,Ea),Ea.forEach(a),wa.forEach(a),ft=f(Xe),ge=o(Xe,"SPAN",{});var ya=r(ge);pt=n(ya,"How to use Stable Diffusion on Habana Gaudi"),ya.forEach(a),Xe.forEach(a),Oe=f(t),D=o(t,"P",{});var Ze=r(D);ct=n(Ze,"\u{1F917} Diffusers is compatible with Habana Gaudi through \u{1F917} "),j=o(Ze,"A",{href:!0,rel:!0});var $a=r(j);dt=n($a,"Optimum Habana"),$a.forEach(a),mt=n(Ze,"."),Ze.forEach(a),Le=f(t),g=o(t,"H2",{class:!0});var et=r(g);k=o(et,"A",{id:!0,class:!0,href:!0});var Ha=r(k);ve=o(Ha,"SPAN",{});var Ga=r(ve);pe(O.$$.fragment,Ga),Ga.forEach(a),Ha.forEach(a),bt=f(et),we=o(et,"SPAN",{});var Da=r(we);_t=n(Da,"Requirements"),Da.forEach(a),et.forEach(a),Me=f(t),S=o(t,"UL",{});var tt=r(S);L=o(tt,"LI",{});var at=r(L);gt=n(at,"Optimum Habana 1.3 or later, "),M=o(at,"A",{href:!0,rel:!0});var ka=r(M);vt=n(ka,"here"),ka.forEach(a),wt=n(at," is how to install it."),at.forEach(a),Et=f(tt),Ee=o(tt,"LI",{});var Sa=r(Ee);yt=n(Sa,"SynapseAI 1.7."),Sa.forEach(a),tt.forEach(a),Ce=f(t),v=o(t,"H2",{class:!0});var it=r(v);T=o(it,"A",{id:!0,class:!0,href:!0});var Ta=r(T);ye=o(Ta,"SPAN",{});var Aa=r(ye);pe(C.$$.fragment,Aa),Aa.forEach(a),Ta.forEach(a),$t=f(it),$e=o(it,"SPAN",{});var Pa=r($e);Ht=n(Pa,"Inference Pipeline"),Pa.forEach(a),it.forEach(a),Fe=f(t),X=o(t,"P",{});var qa=r(X);Gt=n(qa,"To generate images with Stable Diffusion 1 and 2 on Gaudi, you need to instantiate two instances:"),qa.forEach(a),Ne=f(t),A=o(t,"UL",{});var ot=r(A);w=o(ot,"LI",{});var le=r(w);Dt=n(le,"A pipeline with "),F=o(le,"A",{href:!0,rel:!0});var Ia=r(F);He=o(Ia,"CODE",{});var xa=r(He);kt=n(xa,"GaudiStableDiffusionPipeline"),xa.forEach(a),Ia.forEach(a),St=n(le,". This pipeline supports "),Ge=o(le,"EM",{});var ja=r(Ge);Tt=n(ja,"text-to-image generation"),ja.forEach(a),At=n(le,"."),le.forEach(a),Pt=f(ot),N=o(ot,"LI",{});var rt=r(N);qt=n(rt,"A scheduler with "),B=o(rt,"A",{href:!0,rel:!0});var Oa=r(B);De=o(Oa,"CODE",{});var La=r(De);It=n(La,"GaudiDDIMScheduler"),La.forEach(a),Oa.forEach(a),xt=n(rt,". This scheduler has been optimized for Habana Gaudi."),rt.forEach(a),ot.forEach(a),Be=f(t),c=o(t,"P",{});var d=r(c);jt=n(d,"When initializing the pipeline, you have to specify "),ke=o(d,"CODE",{});var Ma=r(ke);Ot=n(Ma,"use_habana=True"),Ma.forEach(a),Lt=n(d,` to deploy it on HPUs.
Furthermore, in order to get the fastest possible generations you should enable `),Se=o(d,"STRONG",{});var Ca=r(Se);Mt=n(Ca,"HPU graphs"),Ca.forEach(a),Ct=n(d," with "),Te=o(d,"CODE",{});var Fa=r(Te);Ft=n(Fa,"use_hpu_graphs=True"),Fa.forEach(a),Nt=n(d,`.
Finally, you will need to specify a `),z=o(d,"A",{href:!0,rel:!0});var Na=r(z);Bt=n(Na,"Gaudi configuration"),Na.forEach(a),zt=n(d," which can be downloaded from the "),R=o(d,"A",{href:!0,rel:!0});var Ba=r(R);Rt=n(Ba,"Hugging Face Hub"),Ba.forEach(a),Ut=n(d,"."),d.forEach(a),ze=f(t),pe(U.$$.fragment,t),Re=f(t),Z=o(t,"P",{});var za=r(Z);Yt=n(za,"You can then call the pipeline to generate images by batches from one or several prompts:"),za.forEach(a),Ue=f(t),pe(Y.$$.fragment,t),Ye=f(t),m=o(t,"P",{});var ne=r(m);Wt=n(ne,"For more information, check out Optimum Habana\u2019s "),W=o(ne,"A",{href:!0,rel:!0});var Ra=r(W);Jt=n(Ra,"documentation"),Ra.forEach(a),Kt=n(ne," and the "),J=o(ne,"A",{href:!0,rel:!0});var Ua=r(J);Qt=n(Ua,"example"),Ua.forEach(a),Vt=n(ne," provided in the official Github repository."),ne.forEach(a),We=f(t),E=o(t,"H2",{class:!0});var lt=r(E);P=o(lt,"A",{id:!0,class:!0,href:!0});var Ya=r(P);Ae=o(Ya,"SPAN",{});var Wa=r(Ae);pe(K.$$.fragment,Wa),Wa.forEach(a),Ya.forEach(a),Xt=f(lt),Pe=o(lt,"SPAN",{});var Ja=r(Pe);Zt=n(Ja,"Benchmark"),Ja.forEach(a),lt.forEach(a),Je=f(t),q=o(t,"P",{});var nt=r(q);ea=n(nt,"Here are the latencies for Habana Gaudi 1 and Gaudi 2 with the "),Q=o(nt,"A",{href:!0,rel:!0});var Ka=r(Q);ta=n(Ka,"Habana/stable-diffusion"),Ka.forEach(a),aa=n(nt," Gaudi configuration (mixed precision bf16/fp32):"),nt.forEach(a),Ke=f(t),I=o(t,"TABLE",{});var st=r(I);qe=o(st,"THEAD",{});var Qa=r(qe);y=o(Qa,"TR",{});var se=r(y);Qe=o(se,"TH",{}),r(Qe).forEach(a),ia=f(se),ee=o(se,"TH",{align:!0});var Va=r(ee);oa=n(Va,"Latency"),Va.forEach(a),ra=f(se),te=o(se,"TH",{align:!0});var Xa=r(te);la=n(Xa,"Batch size"),Xa.forEach(a),se.forEach(a),Qa.forEach(a),na=f(st),V=o(st,"TBODY",{});var ut=r(V);$=o(ut,"TR",{});var ue=r($);Ie=o(ue,"TD",{});var Za=r(Ie);sa=n(Za,"Gaudi 1"),Za.forEach(a),ua=f(ue),ae=o(ue,"TD",{align:!0});var ei=r(ae);ha=n(ei,"4.37s"),ei.forEach(a),fa=f(ue),ie=o(ue,"TD",{align:!0});var ti=r(ie);pa=n(ti,"4/8"),ti.forEach(a),ue.forEach(a),ca=f(ut),H=o(ut,"TR",{});var he=r(H);xe=o(he,"TD",{});var ai=r(xe);da=n(ai,"Gaudi 2"),ai.forEach(a),ma=f(he),oe=o(he,"TD",{align:!0});var ii=r(oe);ba=n(ii,"1.19s"),ii.forEach(a),_a=f(he),re=o(he,"TD",{align:!0});var oi=r(re);ga=n(oi,"4/8"),oi.forEach(a),he.forEach(a),ut.forEach(a),st.forEach(a),this.h()},h(){s(b,"name","hf:doc:metadata"),s(b,"content",JSON.stringify(ci)),s(G,"id","how-to-use-stable-diffusion-on-habana-gaudi"),s(G,"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"),s(G,"href","#how-to-use-stable-diffusion-on-habana-gaudi"),s(_,"class","relative group"),s(j,"href","https://huggingface.co/docs/optimum/habana/usage_guides/stable_diffusion"),s(j,"rel","nofollow"),s(k,"id","requirements"),s(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"),s(k,"href","#requirements"),s(g,"class","relative group"),s(M,"href","https://huggingface.co/docs/optimum/habana/installation"),s(M,"rel","nofollow"),s(T,"id","inference-pipeline"),s(T,"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"),s(T,"href","#inference-pipeline"),s(v,"class","relative group"),s(F,"href","https://huggingface.co/docs/optimum/habana/package_reference/stable_diffusion_pipeline"),s(F,"rel","nofollow"),s(B,"href","https://huggingface.co/docs/optimum/habana/package_reference/stable_diffusion_pipeline#optimum.habana.diffusers.GaudiDDIMScheduler"),s(B,"rel","nofollow"),s(z,"href","https://huggingface.co/docs/optimum/habana/package_reference/gaudi_config"),s(z,"rel","nofollow"),s(R,"href","https://huggingface.co/Habana"),s(R,"rel","nofollow"),s(W,"href","https://huggingface.co/docs/optimum/habana/usage_guides/stable_diffusion"),s(W,"rel","nofollow"),s(J,"href","https://github.com/huggingface/optimum-habana/tree/main/examples/stable-diffusion"),s(J,"rel","nofollow"),s(P,"id","benchmark"),s(P,"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"),s(P,"href","#benchmark"),s(E,"class","relative group"),s(Q,"href","https://huggingface.co/Habana/stable-diffusion"),s(Q,"rel","nofollow"),s(ee,"align","center"),s(te,"align","center"),s(ae,"align","center"),s(ie,"align","center"),s(oe,"align","center"),s(re,"align","center")},m(t,u){e(document.head,b),p(t,je,u),p(t,_,u),e(_,G),e(G,_e),ce(x,_e,null),e(_,ft),e(_,ge),e(ge,pt),p(t,Oe,u),p(t,D,u),e(D,ct),e(D,j),e(j,dt),e(D,mt),p(t,Le,u),p(t,g,u),e(g,k),e(k,ve),ce(O,ve,null),e(g,bt),e(g,we),e(we,_t),p(t,Me,u),p(t,S,u),e(S,L),e(L,gt),e(L,M),e(M,vt),e(L,wt),e(S,Et),e(S,Ee),e(Ee,yt),p(t,Ce,u),p(t,v,u),e(v,T),e(T,ye),ce(C,ye,null),e(v,$t),e(v,$e),e($e,Ht),p(t,Fe,u),p(t,X,u),e(X,Gt),p(t,Ne,u),p(t,A,u),e(A,w),e(w,Dt),e(w,F),e(F,He),e(He,kt),e(w,St),e(w,Ge),e(Ge,Tt),e(w,At),e(A,Pt),e(A,N),e(N,qt),e(N,B),e(B,De),e(De,It),e(N,xt),p(t,Be,u),p(t,c,u),e(c,jt),e(c,ke),e(ke,Ot),e(c,Lt),e(c,Se),e(Se,Mt),e(c,Ct),e(c,Te),e(Te,Ft),e(c,Nt),e(c,z),e(z,Bt),e(c,zt),e(c,R),e(R,Rt),e(c,Ut),p(t,ze,u),ce(U,t,u),p(t,Re,u),p(t,Z,u),e(Z,Yt),p(t,Ue,u),ce(Y,t,u),p(t,Ye,u),p(t,m,u),e(m,Wt),e(m,W),e(W,Jt),e(m,Kt),e(m,J),e(J,Qt),e(m,Vt),p(t,We,u),p(t,E,u),e(E,P),e(P,Ae),ce(K,Ae,null),e(E,Xt),e(E,Pe),e(Pe,Zt),p(t,Je,u),p(t,q,u),e(q,ea),e(q,Q),e(Q,ta),e(q,aa),p(t,Ke,u),p(t,I,u),e(I,qe),e(qe,y),e(y,Qe),e(y,ia),e(y,ee),e(ee,oa),e(y,ra),e(y,te),e(te,la),e(I,na),e(I,V),e(V,$),e($,Ie),e(Ie,sa),e($,ua),e($,ae),e(ae,ha),e($,fa),e($,ie),e(ie,pa),e(V,ca),e(V,H),e(H,xe),e(xe,da),e(H,ma),e(H,oe),e(oe,ba),e(H,_a),e(H,re),e(re,ga),Ve=!0},p:hi,i(t){Ve||(de(x.$$.fragment,t),de(O.$$.fragment,t),de(C.$$.fragment,t),de(U.$$.fragment,t),de(Y.$$.fragment,t),de(K.$$.fragment,t),Ve=!0)},o(t){me(x.$$.fragment,t),me(O.$$.fragment,t),me(C.$$.fragment,t),me(U.$$.fragment,t),me(Y.$$.fragment,t),me(K.$$.fragment,t),Ve=!1},d(t){a(b),t&&a(je),t&&a(_),be(x),t&&a(Oe),t&&a(D),t&&a(Le),t&&a(g),be(O),t&&a(Me),t&&a(S),t&&a(Ce),t&&a(v),be(C),t&&a(Fe),t&&a(X),t&&a(Ne),t&&a(A),t&&a(Be),t&&a(c),t&&a(ze),be(U,t),t&&a(Re),t&&a(Z),t&&a(Ue),be(Y,t),t&&a(Ye),t&&a(m),t&&a(We),t&&a(E),be(K),t&&a(Je),t&&a(q),t&&a(Ke),t&&a(I)}}}const ci={local:"how-to-use-stable-diffusion-on-habana-gaudi",sections:[{local:"requirements",title:"Requirements"},{local:"inference-pipeline",title:"Inference Pipeline"},{local:"benchmark",title:"Benchmark"}],title:"How to use Stable Diffusion on Habana Gaudi"};function di(va){return fi(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gi extends li{constructor(b){super();ni(this,b,di,pi,si,{})}}export{gi as default,ci as metadata};
