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