import{s as ae,o as oe,n as re}from"../chunks/scheduler.182ea377.js";import{S as pe,i as me,g as r,s as i,r as G,A as ce,h as p,f as s,c as a,j as le,u as j,x as c,k as ne,y as ue,a as l,v as g,d as $,t as I,w as _}from"../chunks/index.abf12888.js";import{T as fe}from"../chunks/Tip.230e2334.js";import{C as A}from"../chunks/CodeBlock.57fe6e13.js";import{H as ie}from"../chunks/Heading.16916d63.js";function he(C){let n,u='Generating multiple prompts in a batch can <a href="https://github.com/huggingface/diffusers/issues/363" rel="nofollow">crash</a> or fail to work reliably. We believe this is related to the <a href="https://github.com/pytorch/pytorch/issues/84039" rel="nofollow"><code>mps</code></a> backend in PyTorch. While this is being investigated, you should iterate instead of batching.';return{c(){n=r("p"),n.innerHTML=u},l(o){n=p(o,"P",{"data-svelte-h":!0}),c(n)!=="svelte-17wj08e"&&(n.innerHTML=u)},m(o,Z){l(o,n,Z)},p:re,d(o){o&&s(n)}}}function de(C){let n,u,o,Z,f,X,h,Q='🤗 Diffusers is compatible with Apple silicon (M1/M2 chips) using the PyTorch <a href="https://pytorch.org/docs/stable/notes/mps.html" rel="nofollow"><code>mps</code></a> device, which uses the Metal framework to leverage the GPU on MacOS devices. You’ll need to have:',P,d,F='<li>macOS computer with Apple silicon (M1/M2) hardware</li> <li>macOS 12.6 or later (13.0 or later recommended)</li> <li>arm64 version of Python</li> <li><a href="https://pytorch.org/get-started/locally/" rel="nofollow">PyTorch 2.0</a> (recommended) or 1.13 (minimum version supported for <code>mps</code>)</li>',S,y,D="The <code>mps</code> backend uses PyTorch’s <code>.to()</code> interface to move the Stable Diffusion pipeline on to your M1 or M2 device:",H,M,R,m,Y,w,K="If you’re using <strong>PyTorch 1.13</strong>, you need to “prime” the pipeline with an additional one-time pass through it. This is a temporary workaround for an issue where the first inference pass produces slightly different results than subsequent ones. You only need to do this pass once, and after just one inference step you can discard the result.",k,T,V,J,E,b,O="M1/M2 performance is very sensitive to memory pressure. When this occurs, the system automatically swaps if it needs to which significantly degrades performance.",L,v,ee='To prevent this from happening, we recommend <em>attention slicing</em> to reduce memory pressure during inference and prevent swapping. This is especially relevant if your computer has less than 64GB of system RAM, or if you generate images at non-standard resolutions larger than 512×512 pixels. Call the <a href="/docs/diffusers/v0.22.1/en/api/pipelines/stable_diffusion/adapter#diffusers.StableDiffusionXLAdapterPipeline.enable_attention_slicing">enable_attention_slicing()</a> function on your pipeline:',z,U,x,B,te="Attention slicing performs the costly attention operation in multiple steps instead of all at once. It usually improves performance by ~20% in computers without universal memory, but we’ve observed <em>better performance</em> in most Apple silicon computers unless you have 64GB of RAM or more.",q,W,N;return f=new ie({props:{title:"Metal Performance Shaders (MPS)",local:"metal-performance-shaders-mps",headingTag:"h1"}}),M=new A({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiklMEFwaXBlJTIwJTNEJTIwcGlwZS50byglMjJtcHMlMjIpJTBBJTBBJTIzJTIwUmVjb21tZW5kZWQlMjBpZiUyMHlvdXIlMjBjb21wdXRlciUyMGhhcyUyMCUzQyUyMDY0JTIwR0IlMjBvZiUyMFJBTSUwQXBpcGUuZW5hYmxlX2F0dGVudGlvbl9zbGljaW5nKCklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJhJTIwcGhvdG8lMjBvZiUyMGFuJTIwYXN0cm9uYXV0JTIwcmlkaW5nJTIwYSUyMGhvcnNlJTIwb24lMjBtYXJzJTIy",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>)
pipe = pipe.to(<span class="hljs-string">&quot;mps&quot;</span>)

<span class="hljs-comment"># Recommended if your computer has &lt; 64 GB of RAM</span>
pipe.enable_attention_slicing()

prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>`,wrap:!1}}),m=new fe({props:{warning:!0,$$slots:{default:[he]},$$scope:{ctx:C}}}),T=new A({props:{code:"JTIwJTIwZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBJTIwJTIwcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMikudG8oJTIybXBzJTIyKSUwQSUyMCUyMHBpcGUuZW5hYmxlX2F0dGVudGlvbl9zbGljaW5nKCklMEElMEElMjAlMjBwcm9tcHQlMjAlM0QlMjAlMjJhJTIwcGhvdG8lMjBvZiUyMGFuJTIwYXN0cm9uYXV0JTIwcmlkaW5nJTIwYSUyMGhvcnNlJTIwb24lMjBtYXJzJTIyJTBBJTIzJTIwRmlyc3QtdGltZSUyMCUyMndhcm11cCUyMiUyMHBhc3MlMjBpZiUyMFB5VG9yY2glMjB2ZXJzaW9uJTIwaXMlMjAxLjEzJTBBJTJCJTIwXyUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDEpJTBBJTBBJTIzJTIwUmVzdWx0cyUyMG1hdGNoJTIwdGhvc2UlMjBmcm9tJTIwdGhlJTIwQ1BVJTIwZGV2aWNlJTIwYWZ0ZXIlMjB0aGUlMjB3YXJtdXAlMjBwYXNzLiUwQSUyMCUyMGltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQpLmltYWdlcyU1QjAlNUQ=",highlighted:`  from diffusers import DiffusionPipeline

  pipe = DiffusionPipeline.from_pretrained(&quot;runwayml/stable-diffusion-v1-5&quot;).to(&quot;mps&quot;)
  pipe.enable_attention_slicing()

  prompt = &quot;a photo of an astronaut riding a horse on mars&quot;
# First-time &quot;warmup&quot; pass if PyTorch version is 1.13
<span class="hljs-addition">+ _ = pipe(prompt, num_inference_steps=1)</span>

# Results match those from the CPU device after the warmup pass.
  image = pipe(prompt).images[0]`,wrap:!1}}),J=new ie({props:{title:"Troubleshoot",local:"troubleshoot",headingTag:"h2"}}),U=new A({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMjB2YXJpYW50JTNEJTIyZnAxNiUyMiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpLnRvKCUyMm1wcyUyMiklMEFwaXBlbGluZS5lbmFibGVfYXR0ZW50aW9uX3NsaWNpbmcoKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>, torch_dtype=torch.float16, variant=<span class="hljs-string">&quot;fp16&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>).to(<span class="hljs-string">&quot;mps&quot;</span>)
pipeline.enable_attention_slicing()`,wrap:!1}}),{c(){n=r("meta"),u=i(),o=r("p"),Z=i(),G(f.$$.fragment),X=i(),h=r("p"),h.innerHTML=Q,P=i(),d=r("ul"),d.innerHTML=F,S=i(),y=r("p"),y.innerHTML=D,H=i(),G(M.$$.fragment),R=i(),G(m.$$.fragment),Y=i(),w=r("p"),w.innerHTML=K,k=i(),G(T.$$.fragment),V=i(),G(J.$$.fragment),E=i(),b=r("p"),b.textContent=O,L=i(),v=r("p"),v.innerHTML=ee,z=i(),G(U.$$.fragment),x=i(),B=r("p"),B.innerHTML=te,q=i(),W=r("p"),this.h()},l(e){const t=ce("svelte-u9bgzb",document.head);n=p(t,"META",{name:!0,content:!0}),t.forEach(s),u=a(e),o=p(e,"P",{}),le(o).forEach(s),Z=a(e),j(f.$$.fragment,e),X=a(e),h=p(e,"P",{"data-svelte-h":!0}),c(h)!=="svelte-j79ol3"&&(h.innerHTML=Q),P=a(e),d=p(e,"UL",{"data-svelte-h":!0}),c(d)!=="svelte-1rb0nsv"&&(d.innerHTML=F),S=a(e),y=p(e,"P",{"data-svelte-h":!0}),c(y)!=="svelte-n7utwp"&&(y.innerHTML=D),H=a(e),j(M.$$.fragment,e),R=a(e),j(m.$$.fragment,e),Y=a(e),w=p(e,"P",{"data-svelte-h":!0}),c(w)!=="svelte-1sliuep"&&(w.innerHTML=K),k=a(e),j(T.$$.fragment,e),V=a(e),j(J.$$.fragment,e),E=a(e),b=p(e,"P",{"data-svelte-h":!0}),c(b)!=="svelte-1oew7wr"&&(b.textContent=O),L=a(e),v=p(e,"P",{"data-svelte-h":!0}),c(v)!=="svelte-1631ywi"&&(v.innerHTML=ee),z=a(e),j(U.$$.fragment,e),x=a(e),B=p(e,"P",{"data-svelte-h":!0}),c(B)!=="svelte-xihi2j"&&(B.innerHTML=te),q=a(e),W=p(e,"P",{}),le(W).forEach(s),this.h()},h(){ne(n,"name","hf:doc:metadata"),ne(n,"content",ye)},m(e,t){ue(document.head,n),l(e,u,t),l(e,o,t),l(e,Z,t),g(f,e,t),l(e,X,t),l(e,h,t),l(e,P,t),l(e,d,t),l(e,S,t),l(e,y,t),l(e,H,t),g(M,e,t),l(e,R,t),g(m,e,t),l(e,Y,t),l(e,w,t),l(e,k,t),g(T,e,t),l(e,V,t),g(J,e,t),l(e,E,t),l(e,b,t),l(e,L,t),l(e,v,t),l(e,z,t),g(U,e,t),l(e,x,t),l(e,B,t),l(e,q,t),l(e,W,t),N=!0},p(e,[t]){const se={};t&2&&(se.$$scope={dirty:t,ctx:e}),m.$set(se)},i(e){N||($(f.$$.fragment,e),$(M.$$.fragment,e),$(m.$$.fragment,e),$(T.$$.fragment,e),$(J.$$.fragment,e),$(U.$$.fragment,e),N=!0)},o(e){I(f.$$.fragment,e),I(M.$$.fragment,e),I(m.$$.fragment,e),I(T.$$.fragment,e),I(J.$$.fragment,e),I(U.$$.fragment,e),N=!1},d(e){e&&(s(u),s(o),s(Z),s(X),s(h),s(P),s(d),s(S),s(y),s(H),s(R),s(Y),s(w),s(k),s(V),s(E),s(b),s(L),s(v),s(z),s(x),s(B),s(q),s(W)),s(n),_(f,e),_(M,e),_(m,e),_(T,e),_(J,e),_(U,e)}}}const ye='{"title":"Metal Performance Shaders (MPS)","local":"metal-performance-shaders-mps","sections":[{"title":"Troubleshoot","local":"troubleshoot","sections":[],"depth":2}],"depth":1}';function Me(C){return oe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ue extends pe{constructor(n){super(),me(this,n,Me,de,ae,{})}}export{Ue as component};
