import{s as R,n as W,o as X}from"../chunks/scheduler.e4ff9b64.js";import{S as Z,i as N,e as m,s as r,c as z,h as V,a as f,d as s,b as o,f as I,g as q,j as g,k as O,l as Y,m as n,n as U,t as B,o as G,p as S}from"../chunks/index.09f1bca0.js";import{C as ee,H as te,E as se}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.11400f6f.js";import{C as ne}from"../chunks/CodeBlock.78f3be90.js";function re(J){let a,T,_,v,p,w,c,L,u,K='我们推荐在推理和训练过程中使用<a href="https://github.com/facebookresearch/xformers" rel="nofollow">xFormers</a>。在我们的测试中，其对注意力模块的优化能同时提升运行速度并降低内存消耗。',M,$,Q="通过<code>pip</code>安装xFormers：",y,h,C,i,j='<p>xFormers的<code>pip</code>安装包需要最新版本的PyTorch。如需使用旧版PyTorch，建议<a href="https://github.com/facebookresearch/xformers#installing-xformers" rel="nofollow">从源码安装xFormers</a>。</p>',H,x,A='安装完成后，您可调用<code>enable_xformers_memory_efficient_attention()</code>来实现更快的推理速度和更低的内存占用，具体用法参见<a href="memory#memory-efficient-attention">此章节</a>。',P,l,D='<p>根据<a href="https://github.com/huggingface/diffusers/issues/2234#issuecomment-1416931212" rel="nofollow">此问题</a>反馈，xFormers <code>v0.0.16</code>版本在某些GPU上无法用于训练（微调或DreamBooth）。如遇此问题，请按照该issue评论区指引安装开发版本。</p>',k,d,E,b,F;return p=new ee({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),c=new te({props:{title:"xFormers",local:"xformers",headingTag:"h1"}}),h=new ne({props:{code:"cGlwJTIwaW5zdGFsbCUyMHhmb3JtZXJz",highlighted:"pip install xformers",wrap:!1}}),d=new se({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/optimization/xformers.md"}}),{c(){a=m("meta"),T=r(),_=m("p"),v=r(),z(p.$$.fragment),w=r(),z(c.$$.fragment),L=r(),u=m("p"),u.innerHTML=K,M=r(),$=m("p"),$.innerHTML=Q,y=r(),z(h.$$.fragment),C=r(),i=m("blockquote"),i.innerHTML=j,H=r(),x=m("p"),x.innerHTML=A,P=r(),l=m("blockquote"),l.innerHTML=D,k=r(),z(d.$$.fragment),E=r(),b=m("p"),this.h()},l(e){const t=V("svelte-u9bgzb",document.head);a=f(t,"META",{name:!0,content:!0}),t.forEach(s),T=o(e),_=f(e,"P",{}),I(_).forEach(s),v=o(e),q(p.$$.fragment,e),w=o(e),q(c.$$.fragment,e),L=o(e),u=f(e,"P",{"data-svelte-h":!0}),g(u)!=="svelte-1k8d7zl"&&(u.innerHTML=K),M=o(e),$=f(e,"P",{"data-svelte-h":!0}),g($)!=="svelte-oxf3ff"&&($.innerHTML=Q),y=o(e),q(h.$$.fragment,e),C=o(e),i=f(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),g(i)!=="svelte-19pllcm"&&(i.innerHTML=j),H=o(e),x=f(e,"P",{"data-svelte-h":!0}),g(x)!=="svelte-1x5mssq"&&(x.innerHTML=A),P=o(e),l=f(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),g(l)!=="svelte-f78ug8"&&(l.innerHTML=D),k=o(e),q(d.$$.fragment,e),E=o(e),b=f(e,"P",{}),I(b).forEach(s),this.h()},h(){O(a,"name","hf:doc:metadata"),O(a,"content",oe),O(i,"class","tip"),O(l,"class","warning")},m(e,t){Y(document.head,a),n(e,T,t),n(e,_,t),n(e,v,t),U(p,e,t),n(e,w,t),U(c,e,t),n(e,L,t),n(e,u,t),n(e,M,t),n(e,$,t),n(e,y,t),U(h,e,t),n(e,C,t),n(e,i,t),n(e,H,t),n(e,x,t),n(e,P,t),n(e,l,t),n(e,k,t),U(d,e,t),n(e,E,t),n(e,b,t),F=!0},p:W,i(e){F||(B(p.$$.fragment,e),B(c.$$.fragment,e),B(h.$$.fragment,e),B(d.$$.fragment,e),F=!0)},o(e){G(p.$$.fragment,e),G(c.$$.fragment,e),G(h.$$.fragment,e),G(d.$$.fragment,e),F=!1},d(e){e&&(s(T),s(_),s(v),s(w),s(L),s(u),s(M),s($),s(y),s(C),s(i),s(H),s(x),s(P),s(l),s(k),s(E),s(b)),s(a),S(p,e),S(c,e),S(h,e),S(d,e)}}}const oe='{"title":"xFormers","local":"xformers","sections":[],"depth":1}';function ae(J){return X(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pe extends Z{constructor(a){super(),N(this,a,ae,re,R,{})}}export{pe as component};
