import{S as qt,i as Xt,s as Ct,e as i,k as m,w as k,t as l,M as Ht,c as a,d as t,m as u,a as s,x as S,h as p,b as f,G as o,g as r,y as T,L as Lt,q as D,o as R,B as I,v as Gt}from"../../chunks/vendor-hf-doc-builder.js";import{I as Ie}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as Ae}from"../../chunks/CodeBlock-hf-doc-builder.js";function Kt(mt){let c,le,d,$,z,A,je,F,qe,pe,b,Xe,j,Ce,He,fe,v,y,Q,q,Le,V,Ge,me,U,Ke,ue,X,he,_,x,Z,C,Me,ee,Be,ce,h,Ue,W,We,Ye,te,Je,ze,oe,Fe,Qe,de,H,ve,N,Ve,L,ne,Ze,et,_e,G,we,Y,tt,$e,K,be,E,ot,ie,nt,it,ye,g,at,M,st,rt,xe,w,O,ae,B,lt,se,pt,Ne,J,re,ft,Ee;return A=new Ie({}),q=new Ie({}),X=new Ae({props:{code:'pip install optimum["onnxruntime"]',highlighted:'pip <span class="hljs-keyword">install</span> optimum[<span class="hljs-string">&quot;onnxruntime&quot;</span>]'}}),C=new Ie({}),H=new Ae({props:{code:`from optimum.onnxruntime import ORTStableDiffusionPipeline

model_id = "runwayml/stable-diffusion-v1-5"
pipe = ORTStableDiffusionPipeline.from_pretrained(model_id, export=True)
prompt = "a photo of an astronaut riding a horse on mars"
images = pipe(prompt).images[0]
pipe.save_pretrained("./onnx-stable-diffusion-v1-5")`,highlighted:`<span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> ORTStableDiffusionPipeline

model_id = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
pipe = ORTStableDiffusionPipeline.from_pretrained(model_id, export=<span class="hljs-literal">True</span>)
prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>
images = pipe(prompt).images[<span class="hljs-number">0</span>]
pipe.save_pretrained(<span class="hljs-string">&quot;./onnx-stable-diffusion-v1-5&quot;</span>)`}}),G=new Ae({props:{code:"optimum-cli export onnx --model runwayml/stable-diffusion-v1-5 sd_v15_onnx/",highlighted:'optimum-cli <span class="hljs-built_in">export</span> onnx --model runwayml/stable-diffusion-v1-5 sd_v15_onnx/'}}),K=new Ae({props:{code:`from optimum.onnxruntime import ORTStableDiffusionPipeline

model_id = "sd_v15_onnx"
pipe = ORTStableDiffusionPipeline.from_pretrained(model_id)
prompt = "a photo of an astronaut riding a horse on mars"
images = pipe(prompt).images[0]`,highlighted:`<span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> ORTStableDiffusionPipeline

model_id = <span class="hljs-string">&quot;sd_v15_onnx&quot;</span>
pipe = ORTStableDiffusionPipeline.from_pretrained(model_id)
prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>
images = pipe(prompt).images[<span class="hljs-number">0</span>]`}}),B=new Ie({}),{c(){c=i("meta"),le=m(),d=i("h1"),$=i("a"),z=i("span"),k(A.$$.fragment),je=m(),F=i("span"),qe=l("How to use the ONNX Runtime for inference"),pe=m(),b=i("p"),Xe=l("\u{1F917} "),j=i("a"),Ce=l("Optimum"),He=l(" provides a Stable Diffusion pipeline compatible with ONNX Runtime."),fe=m(),v=i("h2"),y=i("a"),Q=i("span"),k(q.$$.fragment),Le=m(),V=i("span"),Ge=l("Installation"),me=m(),U=i("p"),Ke=l("Install \u{1F917} Optimum with the following command for ONNX Runtime support:"),ue=m(),k(X.$$.fragment),he=m(),_=i("h2"),x=i("a"),Z=i("span"),k(C.$$.fragment),Me=m(),ee=i("span"),Be=l("Stable Diffusion Inference"),ce=m(),h=i("p"),Ue=l("To load an ONNX model and run inference with the ONNX Runtime, you need to replace "),W=i("a"),We=l("StableDiffusionPipeline"),Ye=l(" with "),te=i("code"),Je=l("ORTStableDiffusionPipeline"),ze=l(`. In case you want to load
a PyTorch model and convert it to the ONNX format on-the-fly, you can set `),oe=i("code"),Fe=l("export=True"),Qe=l("."),de=m(),k(H.$$.fragment),ve=m(),N=i("p"),Ve=l(`If you want to export the pipeline in the ONNX format offline and later use it for inference,
you can use the `),L=i("a"),ne=i("code"),Ze=l("optimum-cli export"),et=l(" command:"),_e=m(),k(G.$$.fragment),we=m(),Y=i("p"),tt=l("Then perform inference:"),$e=m(),k(K.$$.fragment),be=m(),E=i("p"),ot=l("Notice that we didn\u2019t have to specify "),ie=i("code"),nt=l("export=True"),it=l(" above."),ye=m(),g=i("p"),at=l("You can find more examples in "),M=i("a"),st=l("optimum documentation"),rt=l("."),xe=m(),w=i("h2"),O=i("a"),ae=i("span"),k(B.$$.fragment),lt=m(),se=i("span"),pt=l("Known Issues"),Ne=m(),J=i("ul"),re=i("li"),ft=l("Generating multiple prompts in a batch seems to take too much memory. While we look into it, you may need to iterate instead of batching."),this.h()},l(e){const n=Ht('[data-svelte="svelte-1phssyn"]',document.head);c=a(n,"META",{name:!0,content:!0}),n.forEach(t),le=u(e),d=a(e,"H1",{class:!0});var ge=s(d);$=a(ge,"A",{id:!0,class:!0,href:!0});var ut=s($);z=a(ut,"SPAN",{});var ht=s(z);S(A.$$.fragment,ht),ht.forEach(t),ut.forEach(t),je=u(ge),F=a(ge,"SPAN",{});var ct=s(F);qe=p(ct,"How to use the ONNX Runtime for inference"),ct.forEach(t),ge.forEach(t),pe=u(e),b=a(e,"P",{});var Oe=s(b);Xe=p(Oe,"\u{1F917} "),j=a(Oe,"A",{href:!0,rel:!0});var dt=s(j);Ce=p(dt,"Optimum"),dt.forEach(t),He=p(Oe," provides a Stable Diffusion pipeline compatible with ONNX Runtime."),Oe.forEach(t),fe=u(e),v=a(e,"H2",{class:!0});var Pe=s(v);y=a(Pe,"A",{id:!0,class:!0,href:!0});var vt=s(y);Q=a(vt,"SPAN",{});var _t=s(Q);S(q.$$.fragment,_t),_t.forEach(t),vt.forEach(t),Le=u(Pe),V=a(Pe,"SPAN",{});var wt=s(V);Ge=p(wt,"Installation"),wt.forEach(t),Pe.forEach(t),me=u(e),U=a(e,"P",{});var $t=s(U);Ke=p($t,"Install \u{1F917} Optimum with the following command for ONNX Runtime support:"),$t.forEach(t),ue=u(e),S(X.$$.fragment,e),he=u(e),_=a(e,"H2",{class:!0});var ke=s(_);x=a(ke,"A",{id:!0,class:!0,href:!0});var bt=s(x);Z=a(bt,"SPAN",{});var yt=s(Z);S(C.$$.fragment,yt),yt.forEach(t),bt.forEach(t),Me=u(ke),ee=a(ke,"SPAN",{});var xt=s(ee);Be=p(xt,"Stable Diffusion Inference"),xt.forEach(t),ke.forEach(t),ce=u(e),h=a(e,"P",{});var P=s(h);Ue=p(P,"To load an ONNX model and run inference with the ONNX Runtime, you need to replace "),W=a(P,"A",{href:!0});var Nt=s(W);We=p(Nt,"StableDiffusionPipeline"),Nt.forEach(t),Ye=p(P," with "),te=a(P,"CODE",{});var Et=s(te);Je=p(Et,"ORTStableDiffusionPipeline"),Et.forEach(t),ze=p(P,`. In case you want to load
a PyTorch model and convert it to the ONNX format on-the-fly, you can set `),oe=a(P,"CODE",{});var gt=s(oe);Fe=p(gt,"export=True"),gt.forEach(t),Qe=p(P,"."),P.forEach(t),de=u(e),S(H.$$.fragment,e),ve=u(e),N=a(e,"P",{});var Se=s(N);Ve=p(Se,`If you want to export the pipeline in the ONNX format offline and later use it for inference,
you can use the `),L=a(Se,"A",{href:!0,rel:!0});var Ot=s(L);ne=a(Ot,"CODE",{});var Pt=s(ne);Ze=p(Pt,"optimum-cli export"),Pt.forEach(t),Ot.forEach(t),et=p(Se," command:"),Se.forEach(t),_e=u(e),S(G.$$.fragment,e),we=u(e),Y=a(e,"P",{});var kt=s(Y);tt=p(kt,"Then perform inference:"),kt.forEach(t),$e=u(e),S(K.$$.fragment,e),be=u(e),E=a(e,"P",{});var Te=s(E);ot=p(Te,"Notice that we didn\u2019t have to specify "),ie=a(Te,"CODE",{});var St=s(ie);nt=p(St,"export=True"),St.forEach(t),it=p(Te," above."),Te.forEach(t),ye=u(e),g=a(e,"P",{});var De=s(g);at=p(De,"You can find more examples in "),M=a(De,"A",{href:!0,rel:!0});var Tt=s(M);st=p(Tt,"optimum documentation"),Tt.forEach(t),rt=p(De,"."),De.forEach(t),xe=u(e),w=a(e,"H2",{class:!0});var Re=s(w);O=a(Re,"A",{id:!0,class:!0,href:!0});var Dt=s(O);ae=a(Dt,"SPAN",{});var Rt=s(ae);S(B.$$.fragment,Rt),Rt.forEach(t),Dt.forEach(t),lt=u(Re),se=a(Re,"SPAN",{});var It=s(se);pt=p(It,"Known Issues"),It.forEach(t),Re.forEach(t),Ne=u(e),J=a(e,"UL",{});var At=s(J);re=a(At,"LI",{});var jt=s(re);ft=p(jt,"Generating multiple prompts in a batch seems to take too much memory. While we look into it, you may need to iterate instead of batching."),jt.forEach(t),At.forEach(t),this.h()},h(){f(c,"name","hf:doc:metadata"),f(c,"content",JSON.stringify(Mt)),f($,"id","how-to-use-the-onnx-runtime-for-inference"),f($,"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"),f($,"href","#how-to-use-the-onnx-runtime-for-inference"),f(d,"class","relative group"),f(j,"href","https://github.com/huggingface/optimum"),f(j,"rel","nofollow"),f(y,"id","installation"),f(y,"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"),f(y,"href","#installation"),f(v,"class","relative group"),f(x,"id","stable-diffusion-inference"),f(x,"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"),f(x,"href","#stable-diffusion-inference"),f(_,"class","relative group"),f(W,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),f(L,"href","https://huggingface.co/docs/optimum/main/en/exporters/onnx/usage_guides/export_a_model#exporting-a-model-to-onnx-using-the-cli"),f(L,"rel","nofollow"),f(M,"href","https://huggingface.co/docs/optimum/"),f(M,"rel","nofollow"),f(O,"id","known-issues"),f(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"),f(O,"href","#known-issues"),f(w,"class","relative group")},m(e,n){o(document.head,c),r(e,le,n),r(e,d,n),o(d,$),o($,z),T(A,z,null),o(d,je),o(d,F),o(F,qe),r(e,pe,n),r(e,b,n),o(b,Xe),o(b,j),o(j,Ce),o(b,He),r(e,fe,n),r(e,v,n),o(v,y),o(y,Q),T(q,Q,null),o(v,Le),o(v,V),o(V,Ge),r(e,me,n),r(e,U,n),o(U,Ke),r(e,ue,n),T(X,e,n),r(e,he,n),r(e,_,n),o(_,x),o(x,Z),T(C,Z,null),o(_,Me),o(_,ee),o(ee,Be),r(e,ce,n),r(e,h,n),o(h,Ue),o(h,W),o(W,We),o(h,Ye),o(h,te),o(te,Je),o(h,ze),o(h,oe),o(oe,Fe),o(h,Qe),r(e,de,n),T(H,e,n),r(e,ve,n),r(e,N,n),o(N,Ve),o(N,L),o(L,ne),o(ne,Ze),o(N,et),r(e,_e,n),T(G,e,n),r(e,we,n),r(e,Y,n),o(Y,tt),r(e,$e,n),T(K,e,n),r(e,be,n),r(e,E,n),o(E,ot),o(E,ie),o(ie,nt),o(E,it),r(e,ye,n),r(e,g,n),o(g,at),o(g,M),o(M,st),o(g,rt),r(e,xe,n),r(e,w,n),o(w,O),o(O,ae),T(B,ae,null),o(w,lt),o(w,se),o(se,pt),r(e,Ne,n),r(e,J,n),o(J,re),o(re,ft),Ee=!0},p:Lt,i(e){Ee||(D(A.$$.fragment,e),D(q.$$.fragment,e),D(X.$$.fragment,e),D(C.$$.fragment,e),D(H.$$.fragment,e),D(G.$$.fragment,e),D(K.$$.fragment,e),D(B.$$.fragment,e),Ee=!0)},o(e){R(A.$$.fragment,e),R(q.$$.fragment,e),R(X.$$.fragment,e),R(C.$$.fragment,e),R(H.$$.fragment,e),R(G.$$.fragment,e),R(K.$$.fragment,e),R(B.$$.fragment,e),Ee=!1},d(e){t(c),e&&t(le),e&&t(d),I(A),e&&t(pe),e&&t(b),e&&t(fe),e&&t(v),I(q),e&&t(me),e&&t(U),e&&t(ue),I(X,e),e&&t(he),e&&t(_),I(C),e&&t(ce),e&&t(h),e&&t(de),I(H,e),e&&t(ve),e&&t(N),e&&t(_e),I(G,e),e&&t(we),e&&t(Y),e&&t($e),I(K,e),e&&t(be),e&&t(E),e&&t(ye),e&&t(g),e&&t(xe),e&&t(w),I(B),e&&t(Ne),e&&t(J)}}}const Mt={local:"how-to-use-the-onnx-runtime-for-inference",sections:[{local:"installation",title:"Installation"},{local:"stable-diffusion-inference",title:"Stable Diffusion Inference"},{local:"known-issues",title:"Known Issues"}],title:"How to use the ONNX Runtime for inference"};function Bt(mt){return Gt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Jt extends qt{constructor(c){super();Xt(this,c,Bt,Kt,Ct,{})}}export{Jt as default,Mt as metadata};
