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 Z,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 C}from"../chunks/index.abf12888.js";import{T as fe}from"../chunks/Tip.230e2334.js";import{C as Q}from"../chunks/CodeBlock.57fe6e13.js";import{H as ie}from"../chunks/Heading.16916d63.js";function he(_){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,B){l(o,n,B)},p:re,d(o){o&&s(n)}}}function de(_){let n,u,o,B,f,X,h,A='🤗 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:',H,d,D='<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,F="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:",P,M,E,m,R,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.",Y,T,V,J,k,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.",N,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/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_attention_slicing">enable_attention_slicing()</a> function on your pipeline:',z,U,x,g,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.",L,W,q;return f=new ie({props:{title:"Metal Performance Shaders (MPS)",local:"metal-performance-shaders-mps",headingTag:"h1"}}),M=new Q({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiklMEFwaXBlJTIwJTNEJTIwcGlwZS50byglMjJtcHMlMjIpJTBBJTBBJTIzJTIwUmVjb21tZW5kZWQlMjBpZiUyMHlvdXIlMjBjb21wdXRlciUyMGhhcyUyMCUzQyUyMDY0JTIwR0IlMjBvZiUyMFJBTSUwQXBpcGUuZW5hYmxlX2F0dGVudGlvbl9zbGljaW5nKCklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJhJTIwcGhvdG8lMjBvZiUyMGFuJTIwYXN0cm9uYXV0JTIwcmlkaW5nJTIwYSUyMGhvcnNlJTIwb24lMjBtYXJzJTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKHByb21wdCkuaW1hZ2VzJTVCMCU1RCUwQWltYWdl",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>
image = pipe(prompt).images[<span class="hljs-number">0</span>]
image`,wrap:!1}}),m=new fe({props:{warning:!0,$$slots:{default:[he]},$$scope:{ctx:_}}}),T=new Q({props:{code:"JTIwJTIwZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBJTIwJTIwcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMikudG8oJTIybXBzJTIyKSUwQSUyMCUyMHBpcGUuZW5hYmxlX2F0dGVudGlvbl9zbGljaW5nKCklMEElMEElMjAlMjBwcm9tcHQlMjAlM0QlMjAlMjJhJTIwcGhvdG8lMjBvZiUyMGFuJTIwYXN0cm9uYXV0JTIwcmlkaW5nJTIwYSUyMGhvcnNlJTIwb24lMjBtYXJzJTIyJTBBJTIwJTIwJTIzJTIwRmlyc3QtdGltZSUyMCUyMndhcm11cCUyMiUyMHBhc3MlMjBpZiUyMFB5VG9yY2glMjB2ZXJzaW9uJTIwaXMlMjAxLjEzJTBBJTJCJTIwXyUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDEpJTBBJTBBJTIwJTIwJTIzJTIwUmVzdWx0cyUyMG1hdGNoJTIwdGhvc2UlMjBmcm9tJTIwdGhlJTIwQ1BVJTIwZGV2aWNlJTIwYWZ0ZXIlMjB0aGUlMjB3YXJtdXAlMjBwYXNzLiUwQSUyMCUyMGltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQpLmltYWdlcyU1QjAlNUQ=",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 Q({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMHZhcmlhbnQlM0QlMjJmcDE2JTIyJTJDJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSkudG8oJTIybXBzJTIyKSUwQXBpcGVsaW5lLmVuYWJsZV9hdHRlbnRpb25fc2xpY2luZygp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-keyword">import</span> torch

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"),B=i(),Z(f.$$.fragment),X=i(),h=r("p"),h.innerHTML=A,H=i(),d=r("ul"),d.innerHTML=D,S=i(),y=r("p"),y.innerHTML=F,P=i(),Z(M.$$.fragment),E=i(),Z(m.$$.fragment),R=i(),w=r("p"),w.innerHTML=K,Y=i(),Z(T.$$.fragment),V=i(),Z(J.$$.fragment),k=i(),b=r("p"),b.textContent=O,N=i(),v=r("p"),v.innerHTML=ee,z=i(),Z(U.$$.fragment),x=i(),g=r("p"),g.innerHTML=te,L=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),B=a(e),j(f.$$.fragment,e),X=a(e),h=p(e,"P",{"data-svelte-h":!0}),c(h)!=="svelte-j79ol3"&&(h.innerHTML=A),H=a(e),d=p(e,"UL",{"data-svelte-h":!0}),c(d)!=="svelte-1rb0nsv"&&(d.innerHTML=D),S=a(e),y=p(e,"P",{"data-svelte-h":!0}),c(y)!=="svelte-n7utwp"&&(y.innerHTML=F),P=a(e),j(M.$$.fragment,e),E=a(e),j(m.$$.fragment,e),R=a(e),w=p(e,"P",{"data-svelte-h":!0}),c(w)!=="svelte-1sliuep"&&(w.innerHTML=K),Y=a(e),j(T.$$.fragment,e),V=a(e),j(J.$$.fragment,e),k=a(e),b=p(e,"P",{"data-svelte-h":!0}),c(b)!=="svelte-1oew7wr"&&(b.textContent=O),N=a(e),v=p(e,"P",{"data-svelte-h":!0}),c(v)!=="svelte-wm64dk"&&(v.innerHTML=ee),z=a(e),j(U.$$.fragment,e),x=a(e),g=p(e,"P",{"data-svelte-h":!0}),c(g)!=="svelte-xihi2j"&&(g.innerHTML=te),L=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,B,t),G(f,e,t),l(e,X,t),l(e,h,t),l(e,H,t),l(e,d,t),l(e,S,t),l(e,y,t),l(e,P,t),G(M,e,t),l(e,E,t),G(m,e,t),l(e,R,t),l(e,w,t),l(e,Y,t),G(T,e,t),l(e,V,t),G(J,e,t),l(e,k,t),l(e,b,t),l(e,N,t),l(e,v,t),l(e,z,t),G(U,e,t),l(e,x,t),l(e,g,t),l(e,L,t),l(e,W,t),q=!0},p(e,[t]){const se={};t&2&&(se.$$scope={dirty:t,ctx:e}),m.$set(se)},i(e){q||($(f.$$.fragment,e),$(M.$$.fragment,e),$(m.$$.fragment,e),$(T.$$.fragment,e),$(J.$$.fragment,e),$(U.$$.fragment,e),q=!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),q=!1},d(e){e&&(s(u),s(o),s(B),s(X),s(h),s(H),s(d),s(S),s(y),s(P),s(E),s(R),s(w),s(Y),s(V),s(k),s(b),s(N),s(v),s(z),s(x),s(g),s(L),s(W)),s(n),C(f,e),C(M,e),C(m,e),C(T,e),C(J,e),C(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(_){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};
