import{s as he,n as de,o as ge}from"../chunks/scheduler.e4ff9b64.js";import{S as $e,i as ye,e as p,s as n,c as U,h as We,a,d as l,b as s,f as Me,g as o,j as m,k as pe,l as ve,m as i,n as f,t as T,o as u,p as r}from"../chunks/index.09f1bca0.js";import{C as Ve,H as ae,E as Be}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.dde31fc2.js";import{C as se}from"../chunks/CodeBlock.54e44b16.js";function Ce(me){let J,F,j,E,c,L,w,k,M,Je='🤗 <a href="https://github.com/huggingface/optimum-intel" rel="nofollow">Optimum</a> 提供与 OpenVINO 兼容的 Stable Diffusion 管道，可在各种 Intel 处理器上执行推理（请参阅支持的设备<a href="https://docs.openvino.ai/latest/openvino_docs_OV_UG_supported_plugins_Supported_Devices.html" rel="nofollow">完整列表</a>）。',X,h,Ue='您需要安装 🤗 Optimum Intel，并使用 <code>--upgrade-strategy eager</code> 选项以确保 <a href="https://github.com/huggingface/optimum-intel" rel="nofollow"><code>optimum-intel</code></a> 使用最新版本：',N,d,D,g,oe="本指南将展示如何使用 Stable Diffusion 和 Stable Diffusion XL (SDXL) 管道与 OpenVINO。",O,$,z,y,fe="要加载并运行推理，请使用 <code>OVStableDiffusionPipeline</code>。如果您想加载 PyTorch 模型并即时转换为 OpenVINO 格式，请设置 <code>export=True</code>：",H,W,Q,v,Te="为了进一步加速推理，静态重塑模型。如果您更改任何参数，例如输出高度或宽度，您需要再次静态重塑模型。",R,V,P,b,ue='<img src="https://huggingface.co/datasets/optimum/documentation-images/resolve/main/intel/openvino/stable_diffusion_v1_5_sail_boat_rembrandt.png"/>',Y,B,re='您可以在 🤗 Optimum <a href="https://huggingface.co/docs/optimum/intel/inference#stable-diffusion" rel="nofollow">文档</a> 中找到更多示例，Stable Diffusion 支持文本到图像、图像到图像和修复。',q,C,A,I,be="要加载并运行 SDXL 推理，请使用 <code>OVStableDiffusionXLPipeline</code>：",K,_,ee,Z,ce='为了进一步加速推理，可以如Stable Diffusion部分所示<a href="#stable-diffusion">静态重塑</a>模型。',te,G,we='您可以在🤗 Optimum<a href="https://huggingface.co/docs/optimum/intel/inference#stable-diffusion-xl" rel="nofollow">文档</a>中找到更多示例，并且在OpenVINO中运行SDXL支持文本到图像和图像到图像。',le,x,ie,S,ne;return c=new Ve({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),w=new ae({props:{title:"OpenVINO",local:"openvino",headingTag:"h1"}}),d=new se({props:{code:"cGlwJTIwaW5zdGFsbCUyMC0tdXBncmFkZS1zdHJhdGVneSUyMGVhZ2VyJTIwb3B0aW11bSU1QiUyMm9wZW52aW5vJTIyJTVE",highlighted:'pip install --upgrade-strategy eager optimum[<span class="hljs-string">&quot;openvino&quot;</span>]',wrap:!1}}),$=new ae({props:{title:"Stable Diffusion",local:"stable-diffusion",headingTag:"h2"}}),W=new se({props:{code:"ZnJvbSUyMG9wdGltdW0uaW50ZWwlMjBpbXBvcnQlMjBPVlN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJzdGFibGUtZGlmZnVzaW9uLXYxLTUlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMEFwaXBlbGluZSUyMCUzRCUyME9WU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwZXhwb3J0JTNEVHJ1ZSklMEFwcm9tcHQlMjAlM0QlMjAlMjJzYWlsaW5nJTIwc2hpcCUyMGluJTIwc3Rvcm0lMjBieSUyMFJlbWJyYW5kdCUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0KS5pbWFnZXMlNUIwJTVEJTBBJTBBJTIzJTIwJUU1JTg4JUFCJUU1JUJGJTk4JUU0JUJBJTg2JUU0JUJGJTlEJUU1JUFEJTk4JUU1JUFGJUJDJUU1JTg3JUJBJUU3JTlBJTg0JUU2JUE4JUExJUU1JTlFJThCJTBBcGlwZWxpbmUuc2F2ZV9wcmV0cmFpbmVkKCUyMm9wZW52aW5vLXNkLXYxLTUlMjIp",highlighted:`<span class="hljs-keyword">from</span> optimum.intel <span class="hljs-keyword">import</span> OVStableDiffusionPipeline

model_id = <span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>
pipeline = OVStableDiffusionPipeline.from_pretrained(model_id, export=<span class="hljs-literal">True</span>)
prompt = <span class="hljs-string">&quot;sailing ship in storm by Rembrandt&quot;</span>
image = pipeline(prompt).images[<span class="hljs-number">0</span>]

<span class="hljs-comment"># 别忘了保存导出的模型</span>
pipeline.save_pretrained(<span class="hljs-string">&quot;openvino-sd-v1-5&quot;</span>)`,wrap:!1}}),V=new se({props:{code:"JTIzJTIwJUU1JUFFJTlBJUU0JUI5JTg5JUU0JUI4JThFJUU4JUJFJTkzJUU1JTg1JUE1JUU1JTkyJThDJUU2JTlDJTlGJUU2JTlDJTlCJUU4JUJFJTkzJUU1JTg3JUJBJUU3JTlCJUI4JUU1JTg1JUIzJUU3JTlBJTg0JUU1JUJEJUEyJUU3JThBJUI2JTBBYmF0Y2hfc2l6ZSUyQyUyMG51bV9pbWFnZXMlMkMlMjBoZWlnaHQlMkMlMjB3aWR0aCUyMCUzRCUyMDElMkMlMjAxJTJDJTIwNTEyJTJDJTIwNTEyJTBBJTBBJTIzJTIwJUU5JTlEJTk5JUU2JTgwJTgxJUU5JTg3JThEJUU1JUExJTkxJUU2JUE4JUExJUU1JTlFJThCJTBBcGlwZWxpbmUucmVzaGFwZShiYXRjaF9zaXplJTJDJTIwaGVpZ2h0JTJDJTIwd2lkdGglMkMlMjBudW1faW1hZ2VzKSUwQSUyMyUyMCVFNSU5QyVBOCVFNiU4RSVBOCVFNyU5MCU4NiVFNSU4OSU4RCVFNyVCQyU5NiVFOCVBRiU5MSVFNiVBOCVBMSVFNSU5RSU4QiUwQXBpcGVsaW5lLmNvbXBpbGUoKSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTJDJTBBJTIwJTIwJTIwJTIwaGVpZ2h0JTNEaGVpZ2h0JTJDJTBBJTIwJTIwJTIwJTIwd2lkdGglM0R3aWR0aCUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbWFnZXNfcGVyX3Byb21wdCUzRG51bV9pbWFnZXMlMkMlMEEpLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-comment"># 定义与输入和期望输出相关的形状</span>
batch_size, num_images, height, width = <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">512</span>, <span class="hljs-number">512</span>

<span class="hljs-comment"># 静态重塑模型</span>
pipeline.reshape(batch_size, height, width, num_images)
<span class="hljs-comment"># 在推理前编译模型</span>
pipeline.<span class="hljs-built_in">compile</span>()

image = pipeline(
    prompt,
    height=height,
    width=width,
    num_images_per_prompt=num_images,
).images[<span class="hljs-number">0</span>]`,wrap:!1}}),C=new ae({props:{title:"Stable Diffusion XL",local:"stable-diffusion-xl",headingTag:"h2"}}),_=new se({props:{code:"ZnJvbSUyMG9wdGltdW0uaW50ZWwlMjBpbXBvcnQlMjBPVlN0YWJsZURpZmZ1c2lvblhMUGlwZWxpbmUlMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUwQXBpcGVsaW5lJTIwJTNEJTIwT1ZTdGFibGVEaWZmdXNpb25YTFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEFwcm9tcHQlMjAlM0QlMjAlMjJzYWlsaW5nJTIwc2hpcCUyMGluJTIwc3Rvcm0lMjBieSUyMFJlbWJyYW5kdCUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0KS5pbWFnZXMlNUIwJTVE",highlighted:`<span class="hljs-keyword">from</span> optimum.intel <span class="hljs-keyword">import</span> OVStableDiffusionXLPipeline

model_id = <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>
pipeline = OVStableDiffusionXLPipeline.from_pretrained(model_id)
prompt = <span class="hljs-string">&quot;sailing ship in storm by Rembrandt&quot;</span>
image = pipeline(prompt).images[<span class="hljs-number">0</span>]`,wrap:!1}}),x=new Be({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/optimization/open_vino.md"}}),{c(){J=p("meta"),F=n(),j=p("p"),E=n(),U(c.$$.fragment),L=n(),U(w.$$.fragment),k=n(),M=p("p"),M.innerHTML=Je,X=n(),h=p("p"),h.innerHTML=Ue,N=n(),U(d.$$.fragment),D=n(),g=p("p"),g.textContent=oe,O=n(),U($.$$.fragment),z=n(),y=p("p"),y.innerHTML=fe,H=n(),U(W.$$.fragment),Q=n(),v=p("p"),v.textContent=Te,R=n(),U(V.$$.fragment),P=n(),b=p("div"),b.innerHTML=ue,Y=n(),B=p("p"),B.innerHTML=re,q=n(),U(C.$$.fragment),A=n(),I=p("p"),I.innerHTML=be,K=n(),U(_.$$.fragment),ee=n(),Z=p("p"),Z.innerHTML=ce,te=n(),G=p("p"),G.innerHTML=we,le=n(),U(x.$$.fragment),ie=n(),S=p("p"),this.h()},l(e){const t=We("svelte-u9bgzb",document.head);J=a(t,"META",{name:!0,content:!0}),t.forEach(l),F=s(e),j=a(e,"P",{}),Me(j).forEach(l),E=s(e),o(c.$$.fragment,e),L=s(e),o(w.$$.fragment,e),k=s(e),M=a(e,"P",{"data-svelte-h":!0}),m(M)!=="svelte-1mlnscv"&&(M.innerHTML=Je),X=s(e),h=a(e,"P",{"data-svelte-h":!0}),m(h)!=="svelte-1n4m4a7"&&(h.innerHTML=Ue),N=s(e),o(d.$$.fragment,e),D=s(e),g=a(e,"P",{"data-svelte-h":!0}),m(g)!=="svelte-j7ofnn"&&(g.textContent=oe),O=s(e),o($.$$.fragment,e),z=s(e),y=a(e,"P",{"data-svelte-h":!0}),m(y)!=="svelte-1yy7m16"&&(y.innerHTML=fe),H=s(e),o(W.$$.fragment,e),Q=s(e),v=a(e,"P",{"data-svelte-h":!0}),m(v)!=="svelte-1pv8wg6"&&(v.textContent=Te),R=s(e),o(V.$$.fragment,e),P=s(e),b=a(e,"DIV",{class:!0,"data-svelte-h":!0}),m(b)!=="svelte-1bbei4i"&&(b.innerHTML=ue),Y=s(e),B=a(e,"P",{"data-svelte-h":!0}),m(B)!=="svelte-180xwbj"&&(B.innerHTML=re),q=s(e),o(C.$$.fragment,e),A=s(e),I=a(e,"P",{"data-svelte-h":!0}),m(I)!=="svelte-1xia1vt"&&(I.innerHTML=be),K=s(e),o(_.$$.fragment,e),ee=s(e),Z=a(e,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-2ooruq"&&(Z.innerHTML=ce),te=s(e),G=a(e,"P",{"data-svelte-h":!0}),m(G)!=="svelte-1psuxlw"&&(G.innerHTML=we),le=s(e),o(x.$$.fragment,e),ie=s(e),S=a(e,"P",{}),Me(S).forEach(l),this.h()},h(){pe(J,"name","hf:doc:metadata"),pe(J,"content",Ie),pe(b,"class","flex justify-center")},m(e,t){ve(document.head,J),i(e,F,t),i(e,j,t),i(e,E,t),f(c,e,t),i(e,L,t),f(w,e,t),i(e,k,t),i(e,M,t),i(e,X,t),i(e,h,t),i(e,N,t),f(d,e,t),i(e,D,t),i(e,g,t),i(e,O,t),f($,e,t),i(e,z,t),i(e,y,t),i(e,H,t),f(W,e,t),i(e,Q,t),i(e,v,t),i(e,R,t),f(V,e,t),i(e,P,t),i(e,b,t),i(e,Y,t),i(e,B,t),i(e,q,t),f(C,e,t),i(e,A,t),i(e,I,t),i(e,K,t),f(_,e,t),i(e,ee,t),i(e,Z,t),i(e,te,t),i(e,G,t),i(e,le,t),f(x,e,t),i(e,ie,t),i(e,S,t),ne=!0},p:de,i(e){ne||(T(c.$$.fragment,e),T(w.$$.fragment,e),T(d.$$.fragment,e),T($.$$.fragment,e),T(W.$$.fragment,e),T(V.$$.fragment,e),T(C.$$.fragment,e),T(_.$$.fragment,e),T(x.$$.fragment,e),ne=!0)},o(e){u(c.$$.fragment,e),u(w.$$.fragment,e),u(d.$$.fragment,e),u($.$$.fragment,e),u(W.$$.fragment,e),u(V.$$.fragment,e),u(C.$$.fragment,e),u(_.$$.fragment,e),u(x.$$.fragment,e),ne=!1},d(e){e&&(l(F),l(j),l(E),l(L),l(k),l(M),l(X),l(h),l(N),l(D),l(g),l(O),l(z),l(y),l(H),l(Q),l(v),l(R),l(P),l(b),l(Y),l(B),l(q),l(A),l(I),l(K),l(ee),l(Z),l(te),l(G),l(le),l(ie),l(S)),l(J),r(c,e),r(w,e),r(d,e),r($,e),r(W,e),r(V,e),r(C,e),r(_,e),r(x,e)}}}const Ie='{"title":"OpenVINO","local":"openvino","sections":[{"title":"Stable Diffusion","local":"stable-diffusion","sections":[],"depth":2},{"title":"Stable Diffusion XL","local":"stable-diffusion-xl","sections":[],"depth":2}],"depth":1}';function _e(me){return ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends $e{constructor(J){super(),ye(this,J,_e,Ce,he,{})}}export{Se as component};
