import{s as Je,n as Ze,o as Se}from"../chunks/scheduler.e4ff9b64.js";import{S as ge,i as Be,e as a,s as n,c as m,h as Ge,a as p,d as l,b as s,f as Ue,g as o,j as f,k as be,l as _e,m as i,n as u,t as b,o as r,p as d}from"../chunks/index.09f1bca0.js";import{C as Xe,H as re,E as Ne}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.dde31fc2.js";import{C as L}from"../chunks/CodeBlock.54e44b16.js";function Re(de){let M,Q,k,I,w,E,T,P,x,Me='🤗 <a href="https://github.com/huggingface/optimum" rel="nofollow">Optimum</a> 提供了兼容 ONNX Runtime 的 Stable Diffusion 流水线。您需要运行以下命令安装支持 ONNX Runtime 的 🤗 Optimum：',F,y,V,h,ce="本指南将展示如何使用 ONNX Runtime 运行 Stable Diffusion 和 Stable Diffusion XL (SDXL) 流水线。",Y,v,O,W,$e="要加载并运行推理，请使用 <code>ORTStableDiffusionPipeline</code>。若需加载 PyTorch 模型并实时转换为 ONNX 格式，请设置 <code>export=True</code>：",q,j,z,c,we="<p>当前批量生成多个提示可能会占用过高内存。在问题修复前，建议采用迭代方式而非批量处理。</p>",D,U,Te='如需离线导出 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> 命令：',A,J,K,Z,xe="随后进行推理时（无需再次指定 <code>export=True</code>）：",ee,S,te,$,ye='<img src="https://huggingface.co/datasets/optimum/documentation-images/resolve/main/onnxruntime/stable_diffusion_v1_5_ort_sail_boat.png"/>',le,g,he='您可以在 🤗 Optimum <a href="https://huggingface.co/docs/optimum/" rel="nofollow">文档</a> 中找到更多示例，Stable Diffusion 支持文生图、图生图和图像修复任务。',ie,B,ne,G,ve="要加载并运行 SDXL 推理，请使用 <code>ORTStableDiffusionXLPipeline</code>：",se,_,ae,X,We="如需导出 ONNX 格式流水线供后续推理使用，请运行：",pe,N,me,R,je="SDXL 的 ONNX 格式目前支持文生图和图生图任务。",oe,C,fe,H,ue;return w=new Xe({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),T=new re({props:{title:"ONNX Runtime",local:"onnx-runtime",headingTag:"h1"}}),y=new L({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwb3B0aW11bSU1QiUyMm9ubnhydW50aW1lJTIyJTVE",highlighted:'pip install -q optimum[<span class="hljs-string">&quot;onnxruntime&quot;</span>]',wrap:!1}}),v=new re({props:{title:"Stable Diffusion",local:"stable-diffusion",headingTag:"h2"}}),j=new L({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}}),J=new L({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 L({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}}),B=new re({props:{title:"Stable Diffusion XL",local:"stable-diffusion-xl",headingTag:"h2"}}),_=new L({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}}),N=new L({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}}),C=new Ne({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/optimization/onnx.md"}}),{c(){M=a("meta"),Q=n(),k=a("p"),I=n(),m(w.$$.fragment),E=n(),m(T.$$.fragment),P=n(),x=a("p"),x.innerHTML=Me,F=n(),m(y.$$.fragment),V=n(),h=a("p"),h.textContent=ce,Y=n(),m(v.$$.fragment),O=n(),W=a("p"),W.innerHTML=$e,q=n(),m(j.$$.fragment),z=n(),c=a("blockquote"),c.innerHTML=we,D=n(),U=a("p"),U.innerHTML=Te,A=n(),m(J.$$.fragment),K=n(),Z=a("p"),Z.innerHTML=xe,ee=n(),m(S.$$.fragment),te=n(),$=a("div"),$.innerHTML=ye,le=n(),g=a("p"),g.innerHTML=he,ie=n(),m(B.$$.fragment),ne=n(),G=a("p"),G.innerHTML=ve,se=n(),m(_.$$.fragment),ae=n(),X=a("p"),X.textContent=We,pe=n(),m(N.$$.fragment),me=n(),R=a("p"),R.textContent=je,oe=n(),m(C.$$.fragment),fe=n(),H=a("p"),this.h()},l(e){const t=Ge("svelte-u9bgzb",document.head);M=p(t,"META",{name:!0,content:!0}),t.forEach(l),Q=s(e),k=p(e,"P",{}),Ue(k).forEach(l),I=s(e),o(w.$$.fragment,e),E=s(e),o(T.$$.fragment,e),P=s(e),x=p(e,"P",{"data-svelte-h":!0}),f(x)!=="svelte-bf49fb"&&(x.innerHTML=Me),F=s(e),o(y.$$.fragment,e),V=s(e),h=p(e,"P",{"data-svelte-h":!0}),f(h)!=="svelte-1bhmzfy"&&(h.textContent=ce),Y=s(e),o(v.$$.fragment,e),O=s(e),W=p(e,"P",{"data-svelte-h":!0}),f(W)!=="svelte-1moz7qk"&&(W.innerHTML=$e),q=s(e),o(j.$$.fragment,e),z=s(e),c=p(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),f(c)!=="svelte-1olsroa"&&(c.innerHTML=we),D=s(e),U=p(e,"P",{"data-svelte-h":!0}),f(U)!=="svelte-1hhbws2"&&(U.innerHTML=Te),A=s(e),o(J.$$.fragment,e),K=s(e),Z=p(e,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-9myidw"&&(Z.innerHTML=xe),ee=s(e),o(S.$$.fragment,e),te=s(e),$=p(e,"DIV",{class:!0,"data-svelte-h":!0}),f($)!=="svelte-1pusq1s"&&($.innerHTML=ye),le=s(e),g=p(e,"P",{"data-svelte-h":!0}),f(g)!=="svelte-xb1f3"&&(g.innerHTML=he),ie=s(e),o(B.$$.fragment,e),ne=s(e),G=p(e,"P",{"data-svelte-h":!0}),f(G)!=="svelte-6saohp"&&(G.innerHTML=ve),se=s(e),o(_.$$.fragment,e),ae=s(e),X=p(e,"P",{"data-svelte-h":!0}),f(X)!=="svelte-1gse514"&&(X.textContent=We),pe=s(e),o(N.$$.fragment,e),me=s(e),R=p(e,"P",{"data-svelte-h":!0}),f(R)!=="svelte-xx2wlb"&&(R.textContent=je),oe=s(e),o(C.$$.fragment,e),fe=s(e),H=p(e,"P",{}),Ue(H).forEach(l),this.h()},h(){be(M,"name","hf:doc:metadata"),be(M,"content",Ce),be(c,"class","warning"),be($,"class","flex justify-center")},m(e,t){_e(document.head,M),i(e,Q,t),i(e,k,t),i(e,I,t),u(w,e,t),i(e,E,t),u(T,e,t),i(e,P,t),i(e,x,t),i(e,F,t),u(y,e,t),i(e,V,t),i(e,h,t),i(e,Y,t),u(v,e,t),i(e,O,t),i(e,W,t),i(e,q,t),u(j,e,t),i(e,z,t),i(e,c,t),i(e,D,t),i(e,U,t),i(e,A,t),u(J,e,t),i(e,K,t),i(e,Z,t),i(e,ee,t),u(S,e,t),i(e,te,t),i(e,$,t),i(e,le,t),i(e,g,t),i(e,ie,t),u(B,e,t),i(e,ne,t),i(e,G,t),i(e,se,t),u(_,e,t),i(e,ae,t),i(e,X,t),i(e,pe,t),u(N,e,t),i(e,me,t),i(e,R,t),i(e,oe,t),u(C,e,t),i(e,fe,t),i(e,H,t),ue=!0},p:Ze,i(e){ue||(b(w.$$.fragment,e),b(T.$$.fragment,e),b(y.$$.fragment,e),b(v.$$.fragment,e),b(j.$$.fragment,e),b(J.$$.fragment,e),b(S.$$.fragment,e),b(B.$$.fragment,e),b(_.$$.fragment,e),b(N.$$.fragment,e),b(C.$$.fragment,e),ue=!0)},o(e){r(w.$$.fragment,e),r(T.$$.fragment,e),r(y.$$.fragment,e),r(v.$$.fragment,e),r(j.$$.fragment,e),r(J.$$.fragment,e),r(S.$$.fragment,e),r(B.$$.fragment,e),r(_.$$.fragment,e),r(N.$$.fragment,e),r(C.$$.fragment,e),ue=!1},d(e){e&&(l(Q),l(k),l(I),l(E),l(P),l(x),l(F),l(V),l(h),l(Y),l(O),l(W),l(q),l(z),l(c),l(D),l(U),l(A),l(K),l(Z),l(ee),l(te),l($),l(le),l(g),l(ie),l(ne),l(G),l(se),l(ae),l(X),l(pe),l(me),l(R),l(oe),l(fe),l(H)),l(M),d(w,e),d(T,e),d(y,e),d(v,e),d(j,e),d(J,e),d(S,e),d(B,e),d(_,e),d(N,e),d(C,e)}}}const Ce='{"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 Le(de){return Se(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ee extends ge{constructor(M){super(),Be(this,M,Le,Re,Je,{})}}export{Ee as component};
