import{s as jt,o as Jt,n as Ut}from"../chunks/scheduler.5c93273d.js";import{S as Zt,i as gt,g as p,s as n,r as f,A as St,h as m,f as l,c as s,j as Wt,u,x as $,k as ut,y as Bt,a as i,v as b,d as r,t as d,w as c}from"../chunks/index.e43dd92b.js";import{T as Gt}from"../chunks/Tip.1cbfe904.js";import{C as k}from"../chunks/CodeBlock.6896320e.js";import{H as bt,E as _t}from"../chunks/getInferenceSnippets.bd93e167.js";function Xt(I){let a,T="当前批量生成多个提示可能会占用过高内存。在问题修复前，建议采用迭代方式而非批量处理。";return{c(){a=p("p"),a.textContent=T},l(o){a=m(o,"P",{"data-svelte-h":!0}),$(a)!=="svelte-1fi329i"&&(a.textContent=T)},m(o,Q){i(o,a,Q)},p:Ut,d(o){o&&l(a)}}}function Nt(I){let a,T,o,Q,x,P,h,rt='🤗 <a href="https://github.com/huggingface/optimum" rel="nofollow">Optimum</a> 提供了兼容 ONNX Runtime 的 Stable Diffusion 流水线。您需要运行以下命令安装支持 ONNX Runtime 的 🤗 Optimum：',E,y,F,v,dt="本指南将展示如何使用 ONNX Runtime 运行 Stable Diffusion 和 Stable Diffusion XL (SDXL) 流水线。",V,W,Y,j,ct="要加载并运行推理，请使用 <code>ORTStableDiffusionPipeline</code>。若需加载 PyTorch 模型并实时转换为 ONNX 格式，请设置 <code>export=True</code>：",O,J,q,M,z,U,$t='如需离线导出 ONNX 格式流水线供后续推理使用，请使用 <a href="https://huggingface.co/docs/optimum/main/en/exporters/onnx/usage_guides/export_a_model#exporting-a-model-to-onnx-using-the-cli" rel="nofollow"><code>optimum-cli export</code></a> 命令：',D,Z,A,g,Mt="随后进行推理时（无需再次指定 <code>export=True</code>）：",K,S,tt,w,wt='<img src="https://huggingface.co/datasets/optimum/documentation-images/resolve/main/onnxruntime/stable_diffusion_v1_5_ort_sail_boat.png"/>',et,B,Tt='您可以在 🤗 Optimum <a href="https://huggingface.co/docs/optimum/" rel="nofollow">文档</a> 中找到更多示例，Stable Diffusion 支持文生图、图生图和图像修复任务。',lt,G,it,_,xt="要加载并运行 SDXL 推理，请使用 <code>ORTStableDiffusionXLPipeline</code>：",nt,X,st,N,ht="如需导出 ONNX 格式流水线供后续推理使用，请运行：",at,R,pt,C,yt="SDXL 的 ONNX 格式目前支持文生图和图生图任务。",mt,L,ot,H,ft;return x=new bt({props:{title:"ONNX Runtime",local:"onnx-runtime",headingTag:"h1"}}),y=new k({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwb3B0aW11bSU1QiUyMm9ubnhydW50aW1lJTIyJTVE",highlighted:'pip install -q optimum[<span class="hljs-string">&quot;onnxruntime&quot;</span>]',wrap:!1}}),W=new bt({props:{title:"Stable Diffusion",local:"stable-diffusion",headingTag:"h2"}}),J=new k({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBPUlRTdGFibGVEaWZmdXNpb25QaXBlbGluZSUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS01JTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBcGlwZWxpbmUlMjAlM0QlMjBPUlRTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjBleHBvcnQlM0RUcnVlKSUwQXByb21wdCUyMCUzRCUyMCUyMnNhaWxpbmclMjBzaGlwJTIwaW4lMjBzdG9ybSUyMGJ5JTIwTGVvbmFyZG8lMjBkYSUyMFZpbmNpJTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQpLmltYWdlcyU1QjAlNUQlMEFwaXBlbGluZS5zYXZlX3ByZXRyYWluZWQoJTIyLiUyRm9ubngtc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> ORTStableDiffusionPipeline

model_id = <span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>
pipeline = ORTStableDiffusionPipeline.from_pretrained(model_id, export=<span class="hljs-literal">True</span>)
prompt = <span class="hljs-string">&quot;sailing ship in storm by Leonardo da Vinci&quot;</span>
image = pipeline(prompt).images[<span class="hljs-number">0</span>]
pipeline.save_pretrained(<span class="hljs-string">&quot;./onnx-stable-diffusion-v1-5&quot;</span>)`,wrap:!1}}),M=new Gt({props:{warning:!0,$$slots:{default:[Xt]},$$scope:{ctx:I}}}),Z=new k({props:{code:"b3B0aW11bS1jbGklMjBleHBvcnQlMjBvbm54JTIwLS1tb2RlbCUyMHN0YWJsZS1kaWZmdXNpb24tdjEtNSUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMHNkX3YxNV9vbm54JTJG",highlighted:'optimum-cli <span class="hljs-built_in">export</span> onnx --model stable-diffusion-v1-5/stable-diffusion-v1-5 sd_v15_onnx/',wrap:!1}}),S=new k({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBPUlRTdGFibGVEaWZmdXNpb25QaXBlbGluZSUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyc2RfdjE1X29ubnglMjIlMEFwaXBlbGluZSUyMCUzRCUyME9SVFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEFwcm9tcHQlMjAlM0QlMjAlMjJzYWlsaW5nJTIwc2hpcCUyMGluJTIwc3Rvcm0lMjBieSUyMExlb25hcmRvJTIwZGElMjBWaW5jaSUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0KS5pbWFnZXMlNUIwJTVE",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>
pipeline = ORTStableDiffusionPipeline.from_pretrained(model_id)
prompt = <span class="hljs-string">&quot;sailing ship in storm by Leonardo da Vinci&quot;</span>
image = pipeline(prompt).images[<span class="hljs-number">0</span>]`,wrap:!1}}),G=new bt({props:{title:"Stable Diffusion XL",local:"stable-diffusion-xl",headingTag:"h2"}}),X=new k({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBPUlRTdGFibGVEaWZmdXNpb25YTFBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlMjIlMEFwaXBlbGluZSUyMCUzRCUyME9SVFN0YWJsZURpZmZ1c2lvblhMUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQXByb21wdCUyMCUzRCUyMCUyMnNhaWxpbmclMjBzaGlwJTIwaW4lMjBzdG9ybSUyMGJ5JTIwTGVvbmFyZG8lMjBkYSUyMFZpbmNpJTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQpLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> ORTStableDiffusionXLPipeline

model_id = <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>
pipeline = ORTStableDiffusionXLPipeline.from_pretrained(model_id)
prompt = <span class="hljs-string">&quot;sailing ship in storm by Leonardo da Vinci&quot;</span>
image = pipeline(prompt).images[<span class="hljs-number">0</span>]`,wrap:!1}}),R=new k({props:{code:"b3B0aW11bS1jbGklMjBleHBvcnQlMjBvbm54JTIwLS1tb2RlbCUyMHN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMC0tdGFzayUyMHN0YWJsZS1kaWZmdXNpb24teGwlMjBzZF94bF9vbm54JTJG",highlighted:'optimum-cli <span class="hljs-built_in">export</span> onnx --model stabilityai/stable-diffusion-xl-base-1.0 --task stable-diffusion-xl sd_xl_onnx/',wrap:!1}}),L=new _t({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/optimization/onnx.md"}}),{c(){a=p("meta"),T=n(),o=p("p"),Q=n(),f(x.$$.fragment),P=n(),h=p("p"),h.innerHTML=rt,E=n(),f(y.$$.fragment),F=n(),v=p("p"),v.textContent=dt,V=n(),f(W.$$.fragment),Y=n(),j=p("p"),j.innerHTML=ct,O=n(),f(J.$$.fragment),q=n(),f(M.$$.fragment),z=n(),U=p("p"),U.innerHTML=$t,D=n(),f(Z.$$.fragment),A=n(),g=p("p"),g.innerHTML=Mt,K=n(),f(S.$$.fragment),tt=n(),w=p("div"),w.innerHTML=wt,et=n(),B=p("p"),B.innerHTML=Tt,lt=n(),f(G.$$.fragment),it=n(),_=p("p"),_.innerHTML=xt,nt=n(),f(X.$$.fragment),st=n(),N=p("p"),N.textContent=ht,at=n(),f(R.$$.fragment),pt=n(),C=p("p"),C.textContent=yt,mt=n(),f(L.$$.fragment),ot=n(),H=p("p"),this.h()},l(t){const e=St("svelte-u9bgzb",document.head);a=m(e,"META",{name:!0,content:!0}),e.forEach(l),T=s(t),o=m(t,"P",{}),Wt(o).forEach(l),Q=s(t),u(x.$$.fragment,t),P=s(t),h=m(t,"P",{"data-svelte-h":!0}),$(h)!=="svelte-bf49fb"&&(h.innerHTML=rt),E=s(t),u(y.$$.fragment,t),F=s(t),v=m(t,"P",{"data-svelte-h":!0}),$(v)!=="svelte-1bhmzfy"&&(v.textContent=dt),V=s(t),u(W.$$.fragment,t),Y=s(t),j=m(t,"P",{"data-svelte-h":!0}),$(j)!=="svelte-1moz7qk"&&(j.innerHTML=ct),O=s(t),u(J.$$.fragment,t),q=s(t),u(M.$$.fragment,t),z=s(t),U=m(t,"P",{"data-svelte-h":!0}),$(U)!=="svelte-1hhbws2"&&(U.innerHTML=$t),D=s(t),u(Z.$$.fragment,t),A=s(t),g=m(t,"P",{"data-svelte-h":!0}),$(g)!=="svelte-9myidw"&&(g.innerHTML=Mt),K=s(t),u(S.$$.fragment,t),tt=s(t),w=m(t,"DIV",{class:!0,"data-svelte-h":!0}),$(w)!=="svelte-1pusq1s"&&(w.innerHTML=wt),et=s(t),B=m(t,"P",{"data-svelte-h":!0}),$(B)!=="svelte-xb1f3"&&(B.innerHTML=Tt),lt=s(t),u(G.$$.fragment,t),it=s(t),_=m(t,"P",{"data-svelte-h":!0}),$(_)!=="svelte-6saohp"&&(_.innerHTML=xt),nt=s(t),u(X.$$.fragment,t),st=s(t),N=m(t,"P",{"data-svelte-h":!0}),$(N)!=="svelte-1gse514"&&(N.textContent=ht),at=s(t),u(R.$$.fragment,t),pt=s(t),C=m(t,"P",{"data-svelte-h":!0}),$(C)!=="svelte-xx2wlb"&&(C.textContent=yt),mt=s(t),u(L.$$.fragment,t),ot=s(t),H=m(t,"P",{}),Wt(H).forEach(l),this.h()},h(){ut(a,"name","hf:doc:metadata"),ut(a,"content",Rt),ut(w,"class","flex justify-center")},m(t,e){Bt(document.head,a),i(t,T,e),i(t,o,e),i(t,Q,e),b(x,t,e),i(t,P,e),i(t,h,e),i(t,E,e),b(y,t,e),i(t,F,e),i(t,v,e),i(t,V,e),b(W,t,e),i(t,Y,e),i(t,j,e),i(t,O,e),b(J,t,e),i(t,q,e),b(M,t,e),i(t,z,e),i(t,U,e),i(t,D,e),b(Z,t,e),i(t,A,e),i(t,g,e),i(t,K,e),b(S,t,e),i(t,tt,e),i(t,w,e),i(t,et,e),i(t,B,e),i(t,lt,e),b(G,t,e),i(t,it,e),i(t,_,e),i(t,nt,e),b(X,t,e),i(t,st,e),i(t,N,e),i(t,at,e),b(R,t,e),i(t,pt,e),i(t,C,e),i(t,mt,e),b(L,t,e),i(t,ot,e),i(t,H,e),ft=!0},p(t,[e]){const vt={};e&2&&(vt.$$scope={dirty:e,ctx:t}),M.$set(vt)},i(t){ft||(r(x.$$.fragment,t),r(y.$$.fragment,t),r(W.$$.fragment,t),r(J.$$.fragment,t),r(M.$$.fragment,t),r(Z.$$.fragment,t),r(S.$$.fragment,t),r(G.$$.fragment,t),r(X.$$.fragment,t),r(R.$$.fragment,t),r(L.$$.fragment,t),ft=!0)},o(t){d(x.$$.fragment,t),d(y.$$.fragment,t),d(W.$$.fragment,t),d(J.$$.fragment,t),d(M.$$.fragment,t),d(Z.$$.fragment,t),d(S.$$.fragment,t),d(G.$$.fragment,t),d(X.$$.fragment,t),d(R.$$.fragment,t),d(L.$$.fragment,t),ft=!1},d(t){t&&(l(T),l(o),l(Q),l(P),l(h),l(E),l(F),l(v),l(V),l(Y),l(j),l(O),l(q),l(z),l(U),l(D),l(A),l(g),l(K),l(tt),l(w),l(et),l(B),l(lt),l(it),l(_),l(nt),l(st),l(N),l(at),l(pt),l(C),l(mt),l(ot),l(H)),l(a),c(x,t),c(y,t),c(W,t),c(J,t),c(M,t),c(Z,t),c(S,t),c(G,t),c(X,t),c(R,t),c(L,t)}}}const Rt='{"title":"ONNX Runtime","local":"onnx-runtime","sections":[{"title":"Stable Diffusion","local":"stable-diffusion","sections":[],"depth":2},{"title":"Stable Diffusion XL","local":"stable-diffusion-xl","sections":[],"depth":2}],"depth":1}';function Ct(I){return Jt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pt extends Zt{constructor(a){super(),gt(this,a,Ct,Nt,jt,{})}}export{Pt as component};
