import{S as Dp,i as Mp,s as Lp,e as r,k as h,w as m,t as a,M as Op,c as s,d as o,m as d,a as i,x as v,h as l,b as f,G as t,g as p,y as w,q as _,o as y,B as b,v as Np}from"../../chunks/vendor-hf-doc-builder.js";import{T as Tp}from"../../chunks/Tip-hf-doc-builder.js";import{I}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as Le}from"../../chunks/CodeBlock-hf-doc-builder.js";function qp(Qo){let c,ie,$,L,W,S,Oe,V,j,ne,q;return{c(){c=r("p"),ie=a("You can also run the "),$=r("code"),L=a("diffusers"),W=a(" Python codebase on Apple Silicon Macs using the "),S=r("code"),Oe=a("mps"),V=a(" accelerator built into PyTorch. This approach is explained in depth in "),j=r("a"),ne=a("the mps guide"),q=a(", but it is not compatible with native apps."),this.h()},l(D){c=s(D,"P",{});var k=i(c);ie=l(k,"You can also run the "),$=s(k,"CODE",{});var gt=i($);L=l(gt,"diffusers"),gt.forEach(o),W=l(k," Python codebase on Apple Silicon Macs using the "),S=s(k,"CODE",{});var Ne=i(S);Oe=l(Ne,"mps"),Ne.forEach(o),V=l(k," accelerator built into PyTorch. This approach is explained in depth in "),j=s(k,"A",{href:!0});var X=i(j);ne=l(X,"the mps guide"),X.forEach(o),q=l(k,", but it is not compatible with native apps."),k.forEach(o),this.h()},h(){f(j,"href","mps")},m(D,k){p(D,c,k),t(c,ie),t(c,$),t($,L),t(c,W),t(c,S),t(S,Oe),t(c,V),t(c,j),t(j,ne),t(c,q)},d(D){D&&o(c)}}}function xp(Qo){let c,ie,$,L,W,S,Oe,V,j,ne,q,D,k,gt,Ne,X,ml,Zo,pe,ea,J,fe,Ht,Te,vl,Ft,wl,ta,$t,_l,oa,U,yl,qe,bl,El,Gt,gl,$l,aa,Pt,Pl,la,H,xe,kl,Ie,Cl,Al,Sl,kt,je,Dl,Ml,Ll,Ue,Ol,He,Nl,Tl,ra,he,ql,Fe,xl,Il,sa,K,de,Yt,Ge,jl,zt,Ul,ia,Ct,Hl,na,ce,Ye,Rt,Fl,Gl,ze,ue,Bt,Yl,zl,Re,Rl,Bl,Wl,P,Vl,Wt,Xl,Jl,Vt,Kl,Ql,Xt,Zl,er,Be,tr,or,We,ar,lr,rr,Ve,Jt,sr,ir,Xe,At,Kt,nr,pr,fr,O,Qt,hr,dr,Zt,cr,ur,me,eo,mr,vr,wr,to,_r,yr,pa,ve,br,Je,Er,gr,fa,Ke,ha,St,$r,da,Q,we,oo,Qe,Pr,ao,kr,ca,Dt,Cr,ua,Ze,ma,Z,_e,lo,et,Ar,ro,Sr,va,C,Dr,so,Mr,Lr,io,Or,Nr,no,Tr,qr,po,xr,Ir,wa,F,jr,fo,Ur,Hr,ho,Fr,Gr,_a,tt,ya,ee,ye,co,ot,Yr,uo,zr,ba,Mt,Rr,Ea,at,ga,E,mo,Br,Wr,vo,Vr,Xr,wo,Jr,Kr,_o,Qr,Zr,yo,es,ts,bo,os,as,$a,N,ls,Eo,rs,ss,go,is,ns,$o,ps,fs,Pa,be,hs,lt,Po,ds,cs,ka,rt,Ca,te,Ee,ko,st,us,Co,ms,Aa,ge,vs,Ao,ws,_s,Sa,oe,$e,So,it,ys,Do,bs,Da,G,Es,Mo,gs,$s,Lo,Ps,ks,Ma,nt,La,ae,Pe,Oo,pt,Cs,No,As,Oa,Lt,Ss,Na,ft,Ta,ke,Ds,ht,Ms,Ls,qa,dt,xa,u,Os,To,Ns,Ts,qo,qs,xs,xo,Is,js,Io,Us,Hs,jo,Fs,Gs,Uo,Ys,zs,Ho,Rs,Bs,Ia,Ce,Ws,ct,Vs,Xs,ja,le,Ae,Fo,ut,Js,Go,Ks,Ua,Ot,Qs,Ha,Y,Yo,Zs,ei,x,ti,zo,oi,ai,Ro,li,ri,Bo,si,ii,ni,Wo,pi,Fa,z,fi,mt,hi,di,vt,ci,ui,Ga,Nt,mi,Ya,re,Se,Vo,wt,vi,Xo,wi,za,A,_i,_t,yi,bi,Jo,Ei,gi,yt,$i,Pi,bt,ki,Ci,Ra;return S=new I({}),pe=new Tp({props:{$$slots:{default:[qp]},$$scope:{ctx:Qo}}}),Te=new I({}),Ge=new I({}),Ke=new Le({props:{code:`coreml-stable-diffusion-v1-4
\u251C\u2500\u2500 README.md
\u251C\u2500\u2500 original
\u2502   \u251C\u2500\u2500 compiled
\u2502   \u2514\u2500\u2500 packages
\u2514\u2500\u2500 split_einsum
    \u251C\u2500\u2500 compiled
    \u2514\u2500\u2500 packages`,highlighted:`coreml-stable-<span class="hljs-keyword">diffusion-v1-4
</span>\u251C\u2500\u2500 README.md
\u251C\u2500\u2500 <span class="hljs-keyword">original
</span>\u2502   \u251C\u2500\u2500 compiled
\u2502   \u2514\u2500\u2500 packages
\u2514\u2500\u2500 split_einsum
    \u251C\u2500\u2500 compiled
    \u2514\u2500\u2500 packages`}}),Qe=new I({}),Ze=new Le({props:{code:`pip install huggingface_hub
pip install git+https://github.com/apple/ml-stable-diffusion`,highlighted:`pip install huggingface_hub
pip install git+https://github.com/apple/ml-stable-diffusion`}}),et=new I({}),tt=new Le({props:{code:`from huggingface_hub import snapshot_download
from pathlib import Path

repo_id = "apple/coreml-stable-diffusion-v1-4"
variant = "original/packages"

model_path = Path("./models") / (repo_id.split("/")[-1] + "_" + variant.replace("/", "_"))
snapshot_download(repo_id, allow_patterns=f"{variant}/*", local_dir=model_path, local_dir_use_symlinks=False)
print(f"Model downloaded at {model_path}")`,highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> snapshot_download
<span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path

repo_id = <span class="hljs-string">&quot;apple/coreml-stable-diffusion-v1-4&quot;</span>
variant = <span class="hljs-string">&quot;original/packages&quot;</span>

model_path = Path(<span class="hljs-string">&quot;./models&quot;</span>) / (repo_id.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>] + <span class="hljs-string">&quot;_&quot;</span> + variant.replace(<span class="hljs-string">&quot;/&quot;</span>, <span class="hljs-string">&quot;_&quot;</span>))
snapshot_download(repo_id, allow_patterns=<span class="hljs-string">f&quot;<span class="hljs-subst">{variant}</span>/*&quot;</span>, local_dir=model_path, local_dir_use_symlinks=<span class="hljs-literal">False</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Model downloaded at <span class="hljs-subst">{model_path}</span>&quot;</span>)`}}),ot=new I({}),at=new Le({props:{code:'python -m python_coreml_stable_diffusion.pipeline --prompt "a photo of an astronaut riding a horse on mars" -i models/coreml-stable-diffusion-v1-4_original_packages -o </path/to/output/image> --compute-unit CPU_AND_GPU --seed 93',highlighted:"python -m python_coreml_stable_diffusion.pipeline --prompt &quot;a photo of an astronaut riding a horse on mars&quot; -i models/coreml-stable-diffusion-v1-4_original_packages -o &lt;/path/to/output/image&gt; --compute-unit CPU_AND_GPU --seed 93"}}),rt=new Le({props:{code:'python -m python_coreml_stable_diffusion.pipeline --prompt "a photo of an astronaut riding a horse on mars" --compute-unit ALL -o output --seed 93 -i models/coreml-stable-diffusion-v1-5_original_packages --model-version runwayml/stable-diffusion-v1-5',highlighted:"python -m python_coreml_stable_diffusion.pipeline --prompt &quot;a photo of an astronaut riding a horse on mars&quot; --compute-unit ALL -o output --seed 93 -i models/coreml-stable-diffusion-v1-5_original_packages --model-version runwayml/stable-diffusion-v1-5"}}),st=new I({}),it=new I({}),nt=new Le({props:{code:`from huggingface_hub import snapshot_download
from pathlib import Path

repo_id = "apple/coreml-stable-diffusion-v1-4"
variant = "original/compiled"

model_path = Path("./models") / (repo_id.split("/")[-1] + "_" + variant.replace("/", "_"))
snapshot_download(repo_id, allow_patterns=f"{variant}/*", local_dir=model_path, local_dir_use_symlinks=False)
print(f"Model downloaded at {model_path}")`,highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> snapshot_download
<span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path

repo_id = <span class="hljs-string">&quot;apple/coreml-stable-diffusion-v1-4&quot;</span>
variant = <span class="hljs-string">&quot;original/compiled&quot;</span>

model_path = Path(<span class="hljs-string">&quot;./models&quot;</span>) / (repo_id.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>] + <span class="hljs-string">&quot;_&quot;</span> + variant.replace(<span class="hljs-string">&quot;/&quot;</span>, <span class="hljs-string">&quot;_&quot;</span>))
snapshot_download(repo_id, allow_patterns=<span class="hljs-string">f&quot;<span class="hljs-subst">{variant}</span>/*&quot;</span>, local_dir=model_path, local_dir_use_symlinks=<span class="hljs-literal">False</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Model downloaded at <span class="hljs-subst">{model_path}</span>&quot;</span>)`}}),pt=new I({}),ft=new Le({props:{code:`git clone https://github.com/apple/ml-stable-diffusion
cd ml-stable-diffusion`,highlighted:`git <span class="hljs-built_in">clone</span> https://github.com/apple/ml-stable-diffusion
<span class="hljs-built_in">cd</span> ml-stable-diffusion`}}),dt=new Le({props:{code:'swift run StableDiffusionSample --resource-path models/coreml-stable-diffusion-v1-4_original_compiled --compute-units all "a photo of an astronaut riding a horse on mars"',highlighted:'swift run StableDiffusionSample --resource-path models/coreml-stable-diffusion-v1-4_original_compiled --compute-units all <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>'}}),ut=new I({}),wt=new I({}),{c(){c=r("meta"),ie=h(),$=r("h1"),L=r("a"),W=r("span"),m(S.$$.fragment),Oe=h(),V=r("span"),j=a("How to run Stable Diffusion with Core ML"),ne=h(),q=r("p"),D=r("a"),k=a("Core ML"),gt=a(" is the model format and machine learning library supported by Apple frameworks. If you are interested in running Stable Diffusion models inside your macOS or iOS/iPadOS apps, this guide will show you how to convert existing PyTorch checkpoints into the Core ML format and use them for inference with Python or Swift."),Ne=h(),X=r("p"),ml=a("Core ML models can leverage all the compute engines available in Apple devices: the CPU, the GPU, and the Apple Neural Engine (or ANE, a tensor-optimized accelerator available in Apple Silicon Macs and modern iPhones/iPads). Depending on the model and the device it\u2019s running on, Core ML can mix and match compute engines too, so some portions of the model may run on the CPU while others run on GPU, for example."),Zo=h(),m(pe.$$.fragment),ea=h(),J=r("h2"),fe=r("a"),Ht=r("span"),m(Te.$$.fragment),vl=h(),Ft=r("span"),wl=a("Stable Diffusion Core ML Checkpoints"),ta=h(),$t=r("p"),_l=a("Stable Diffusion weights (or checkpoints) are stored in the PyTorch format, so you need to convert them to the Core ML format before we can use them inside native apps."),oa=h(),U=r("p"),yl=a("Thankfully, Apple engineers developed "),qe=r("a"),bl=a("a conversion tool"),El=a(" based on "),Gt=r("code"),gl=a("diffusers"),$l=a(" to convert the PyTorch checkpoints to Core ML."),aa=h(),Pt=r("p"),Pl=a("Before you convert a model, though, take a moment to explore the Hugging Face Hub \u2013 chances are the model you\u2019re interested in is already available in Core ML format:"),la=h(),H=r("ul"),xe=r("li"),kl=a("the "),Ie=r("a"),Cl=a("Apple"),Al=a(" organization includes Stable Diffusion versions 1.4, 1.5, 2.0 base, and 2.1 base"),Sl=h(),kt=r("li"),je=r("a"),Dl=a("coreml"),Ml=a(" organization includes custom DreamBoothed and finetuned models"),Ll=h(),Ue=r("li"),Ol=a("use this "),He=r("a"),Nl=a("filter"),Tl=a(" to return all available Core ML checkpoints"),ra=h(),he=r("p"),ql=a("If you can\u2019t find the model you\u2019re interested in, we recommend you follow the instructions for "),Fe=r("a"),xl=a("Converting Models to Core ML"),Il=a(" by Apple."),sa=h(),K=r("h2"),de=r("a"),Yt=r("span"),m(Ge.$$.fragment),jl=h(),zt=r("span"),Ul=a("Selecting the Core ML Variant to Use"),ia=h(),Ct=r("p"),Hl=a("Stable Diffusion models can be converted to different Core ML variants intended for different purposes:"),na=h(),ce=r("ul"),Ye=r("li"),Rt=r("p"),Fl=a("The type of attention blocks used. The attention operation is used to \u201Cpay attention\u201D to the relationship between different areas in the image representations and to understand how the image and text representations are related. Attention is compute- and memory-intensive, so different implementations exist that consider the hardware characteristics of different devices. For Core ML Stable Diffusion models, there are two attention variants:"),Gl=h(),ze=r("ul"),ue=r("li"),Bt=r("code"),Yl=a("split_einsum"),zl=a(" ("),Re=r("a"),Rl=a("introduced by Apple"),Bl=a(") is optimized for ANE devices, which is available in modern iPhones, iPads and M-series computers."),Wl=h(),P=r("li"),Vl=a("The \u201Coriginal\u201D attention (the base implementation used in "),Wt=r("code"),Xl=a("diffusers"),Jl=a(") is only compatible with CPU/GPU and not ANE. It can be "),Vt=r("em"),Kl=a("faster"),Ql=a(" to run your model on CPU + GPU using "),Xt=r("code"),Zl=a("original"),er=a(" attention than ANE. See "),Be=r("a"),tr=a("this performance benchmark"),or=a(" as well as some "),We=r("a"),ar=a("additional measures provided by the community"),lr=a(" for additional details."),rr=h(),Ve=r("li"),Jt=r("p"),sr=a("The supported inference framework."),ir=h(),Xe=r("ul"),At=r("li"),Kt=r("code"),nr=a("packages"),pr=a(" are suitable for Python inference. This can be used to test converted Core ML models before attempting to integrate them inside native apps, or if you want to explore Core ML performance but don\u2019t need to support native apps. For example, an application with a web UI could perfectly use a Python Core ML backend."),fr=h(),O=r("li"),Qt=r("code"),hr=a("compiled"),dr=a(" models are required for Swift code. The "),Zt=r("code"),cr=a("compiled"),ur=a(" models in the Hub split the large UNet model weights into several files for compatibility with iOS and iPadOS devices. This corresponds to the "),me=r("a"),eo=r("code"),mr=a("--chunk-unet"),vr=a(" conversion option"),wr=a(". If you want to support native apps, then you need to select the "),to=r("code"),_r=a("compiled"),yr=a(" variant."),pa=h(),ve=r("p"),br=a("The official Core ML Stable Diffusion "),Je=r("a"),Er=a("models"),gr=a(" include these variants, but the community ones may vary:"),fa=h(),m(Ke.$$.fragment),ha=h(),St=r("p"),$r=a("You can download and use the variant you need as shown below."),da=h(),Q=r("h2"),we=r("a"),oo=r("span"),m(Qe.$$.fragment),Pr=h(),ao=r("span"),kr=a("Core ML Inference in Python"),ca=h(),Dt=r("p"),Cr=a("Install the following libraries to run Core ML inference in Python:"),ua=h(),m(Ze.$$.fragment),ma=h(),Z=r("h3"),_e=r("a"),lo=r("span"),m(et.$$.fragment),Ar=h(),ro=r("span"),Sr=a("Download the Model Checkpoints"),va=h(),C=r("p"),Dr=a("To run inference in Python, use one of the versions stored in the "),so=r("code"),Mr=a("packages"),Lr=a(" folders because the "),io=r("code"),Or=a("compiled"),Nr=a(" ones are only compatible with Swift. You may choose whether you want to use "),no=r("code"),Tr=a("original"),qr=a(" or "),po=r("code"),xr=a("split_einsum"),Ir=a(" attention."),wa=h(),F=r("p"),jr=a("This is how you\u2019d download the "),fo=r("code"),Ur=a("original"),Hr=a(" attention variant from the Hub to a directory called "),ho=r("code"),Fr=a("models"),Gr=a(":"),_a=h(),m(tt.$$.fragment),ya=h(),ee=r("h3"),ye=r("a"),co=r("span"),m(ot.$$.fragment),Yr=h(),uo=r("span"),zr=a("Inference"),ba=h(),Mt=r("p"),Rr=a("Once you have downloaded a snapshot of the model, you can test it using Apple\u2019s Python script."),Ea=h(),m(at.$$.fragment),ga=h(),E=r("p"),mo=r("code"),Br=a("<output-mlpackages-directory>"),Wr=a(" should point to the checkpoint you downloaded in the step above, and "),vo=r("code"),Vr=a("--compute-unit"),Xr=a(" indicates the hardware you want to allow for inference. It must be one of the following options: "),wo=r("code"),Jr=a("ALL"),Kr=a(", "),_o=r("code"),Qr=a("CPU_AND_GPU"),Zr=a(", "),yo=r("code"),es=a("CPU_ONLY"),ts=a(", "),bo=r("code"),os=a("CPU_AND_NE"),as=a(". You may also provide an optional output path, and a seed for reproducibility."),$a=h(),N=r("p"),ls=a("The inference script assumes you\u2019re using the original version of the Stable Diffusion model, "),Eo=r("code"),rs=a("CompVis/stable-diffusion-v1-4"),ss=a(". If you use another model, you "),go=r("em"),is=a("have"),ns=a(" to specify its Hub id in the inference command line, using the "),$o=r("code"),ps=a("--model-version"),fs=a(" option. This works for models already supported and custom models you trained or fine-tuned yourself."),Pa=h(),be=r("p"),hs=a("For example, if you want to use "),lt=r("a"),Po=r("code"),ds=a("runwayml/stable-diffusion-v1-5"),cs=a(":"),ka=h(),m(rt.$$.fragment),Ca=h(),te=r("h2"),Ee=r("a"),ko=r("span"),m(st.$$.fragment),us=h(),Co=r("span"),ms=a("Core ML inference in Swift"),Aa=h(),ge=r("p"),vs=a("Running inference in Swift is slightly faster than in Python because the models are already compiled in the "),Ao=r("code"),ws=a("mlmodelc"),_s=a(" format. This is noticeable on app startup when the model is loaded but shouldn\u2019t be noticeable if you run several generations afterward."),Sa=h(),oe=r("h3"),$e=r("a"),So=r("span"),m(it.$$.fragment),ys=h(),Do=r("span"),bs=a("Download"),Da=h(),G=r("p"),Es=a("To run inference in Swift on your Mac, you need one of the "),Mo=r("code"),gs=a("compiled"),$s=a(" checkpoint versions. We recommend you download them locally using Python code similar to the previous example, but with one of the "),Lo=r("code"),Ps=a("compiled"),ks=a(" variants:"),Ma=h(),m(nt.$$.fragment),La=h(),ae=r("h3"),Pe=r("a"),Oo=r("span"),m(pt.$$.fragment),Cs=h(),No=r("span"),As=a("Inference"),Oa=h(),Lt=r("p"),Ss=a("To run inference, please clone Apple\u2019s repo:"),Na=h(),m(ft.$$.fragment),Ta=h(),ke=r("p"),Ds=a("And then use Apple\u2019s command line tool, "),ht=r("a"),Ms=a("Swift Package Manager"),Ls=a(":"),qa=h(),m(dt.$$.fragment),xa=h(),u=r("p"),Os=a("You have to specify in "),To=r("code"),Ns=a("--resource-path"),Ts=a(" one of the checkpoints downloaded in the previous step, so please make sure it contains compiled Core ML bundles with the extension "),qo=r("code"),qs=a(".mlmodelc"),xs=a(". The "),xo=r("code"),Is=a("--compute-units"),js=a(" has to be one of these values: "),Io=r("code"),Us=a("all"),Hs=a(", "),jo=r("code"),Fs=a("cpuOnly"),Gs=a(", "),Uo=r("code"),Ys=a("cpuAndGPU"),zs=a(", "),Ho=r("code"),Rs=a("cpuAndNeuralEngine"),Bs=a("."),Ia=h(),Ce=r("p"),Ws=a("For more details, please refer to the "),ct=r("a"),Vs=a("instructions in Apple\u2019s repo"),Xs=a("."),ja=h(),le=r("h2"),Ae=r("a"),Fo=r("span"),m(ut.$$.fragment),Js=h(),Go=r("span"),Ks=a("Supported Diffusers Features"),Ua=h(),Ot=r("p"),Qs=a("The Core ML models and inference code don\u2019t support many of the features, options, and flexibility of \u{1F9E8} Diffusers. These are some of the limitations to keep in mind:"),Ha=h(),Y=r("ul"),Yo=r("li"),Zs=a("Core ML models are only suitable for inference. They can\u2019t be used for training or fine-tuning."),ei=h(),x=r("li"),ti=a("Only two schedulers have been ported to Swift, the default one used by Stable Diffusion and "),zo=r("code"),oi=a("DPMSolverMultistepScheduler"),ai=a(", which we ported to Swift from our "),Ro=r("code"),li=a("diffusers"),ri=a(" implementation. We recommend you use "),Bo=r("code"),si=a("DPMSolverMultistepScheduler"),ii=a(", since it produces the same quality in about half the steps."),ni=h(),Wo=r("li"),pi=a("Negative prompts, classifier-free guidance scale, and image-to-image tasks are available in the inference code. Advanced features such as depth guidance, ControlNet, and latent upscalers are not available yet."),Fa=h(),z=r("p"),fi=a("Apple\u2019s "),mt=r("a"),hi=a("conversion and inference repo"),di=a(" and our own "),vt=r("a"),ci=a("swift-coreml-diffusers"),ui=a(" repos are intended as technology demonstrators to enable other developers to build upon."),Ga=h(),Nt=r("p"),mi=a("If you feel strongly about any missing features, please feel free to open a feature request or, better yet, a contribution PR :)"),Ya=h(),re=r("h2"),Se=r("a"),Vo=r("span"),m(wt.$$.fragment),vi=h(),Xo=r("span"),wi=a("Native Diffusers Swift app"),za=h(),A=r("p"),_i=a("One easy way to run Stable Diffusion on your own Apple hardware is to use "),_t=r("a"),yi=a("our open-source Swift repo"),bi=a(", based on "),Jo=r("code"),Ei=a("diffusers"),gi=a(" and Apple\u2019s conversion and inference repo. You can study the code, compile it with "),yt=r("a"),$i=a("Xcode"),Pi=a(" and adapt it for your own needs. For your convenience, there\u2019s also a "),bt=r("a"),ki=a("standalone Mac app in the App Store"),Ci=a(", so you can play with it without having to deal with the code or IDE. If you are a developer and have determined that Core ML is the best solution to build your Stable Diffusion app, then you can use the rest of this guide to get started with your project. We can\u2019t wait to see what you\u2019ll build :)"),this.h()},l(e){const n=Op('[data-svelte="svelte-1phssyn"]',document.head);c=s(n,"META",{name:!0,content:!0}),n.forEach(o),ie=d(e),$=s(e,"H1",{class:!0});var Et=i($);L=s(Et,"A",{id:!0,class:!0,href:!0});var Li=i(L);W=s(Li,"SPAN",{});var Oi=i(W);v(S.$$.fragment,Oi),Oi.forEach(o),Li.forEach(o),Oe=d(Et),V=s(Et,"SPAN",{});var Ni=i(V);j=l(Ni,"How to run Stable Diffusion with Core ML"),Ni.forEach(o),Et.forEach(o),ne=d(e),q=s(e,"P",{});var Ai=i(q);D=s(Ai,"A",{href:!0,rel:!0});var Ti=i(D);k=l(Ti,"Core ML"),Ti.forEach(o),gt=l(Ai," is the model format and machine learning library supported by Apple frameworks. If you are interested in running Stable Diffusion models inside your macOS or iOS/iPadOS apps, this guide will show you how to convert existing PyTorch checkpoints into the Core ML format and use them for inference with Python or Swift."),Ai.forEach(o),Ne=d(e),X=s(e,"P",{});var qi=i(X);ml=l(qi,"Core ML models can leverage all the compute engines available in Apple devices: the CPU, the GPU, and the Apple Neural Engine (or ANE, a tensor-optimized accelerator available in Apple Silicon Macs and modern iPhones/iPads). Depending on the model and the device it\u2019s running on, Core ML can mix and match compute engines too, so some portions of the model may run on the CPU while others run on GPU, for example."),qi.forEach(o),Zo=d(e),v(pe.$$.fragment,e),ea=d(e),J=s(e,"H2",{class:!0});var Ba=i(J);fe=s(Ba,"A",{id:!0,class:!0,href:!0});var xi=i(fe);Ht=s(xi,"SPAN",{});var Ii=i(Ht);v(Te.$$.fragment,Ii),Ii.forEach(o),xi.forEach(o),vl=d(Ba),Ft=s(Ba,"SPAN",{});var ji=i(Ft);wl=l(ji,"Stable Diffusion Core ML Checkpoints"),ji.forEach(o),Ba.forEach(o),ta=d(e),$t=s(e,"P",{});var Ui=i($t);_l=l(Ui,"Stable Diffusion weights (or checkpoints) are stored in the PyTorch format, so you need to convert them to the Core ML format before we can use them inside native apps."),Ui.forEach(o),oa=d(e),U=s(e,"P",{});var Tt=i(U);yl=l(Tt,"Thankfully, Apple engineers developed "),qe=s(Tt,"A",{href:!0,rel:!0});var Hi=i(qe);bl=l(Hi,"a conversion tool"),Hi.forEach(o),El=l(Tt," based on "),Gt=s(Tt,"CODE",{});var Fi=i(Gt);gl=l(Fi,"diffusers"),Fi.forEach(o),$l=l(Tt," to convert the PyTorch checkpoints to Core ML."),Tt.forEach(o),aa=d(e),Pt=s(e,"P",{});var Gi=i(Pt);Pl=l(Gi,"Before you convert a model, though, take a moment to explore the Hugging Face Hub \u2013 chances are the model you\u2019re interested in is already available in Core ML format:"),Gi.forEach(o),la=d(e),H=s(e,"UL",{});var qt=i(H);xe=s(qt,"LI",{});var Wa=i(xe);kl=l(Wa,"the "),Ie=s(Wa,"A",{href:!0,rel:!0});var Yi=i(Ie);Cl=l(Yi,"Apple"),Yi.forEach(o),Al=l(Wa," organization includes Stable Diffusion versions 1.4, 1.5, 2.0 base, and 2.1 base"),Wa.forEach(o),Sl=d(qt),kt=s(qt,"LI",{});var Si=i(kt);je=s(Si,"A",{href:!0,rel:!0});var zi=i(je);Dl=l(zi,"coreml"),zi.forEach(o),Ml=l(Si," organization includes custom DreamBoothed and finetuned models"),Si.forEach(o),Ll=d(qt),Ue=s(qt,"LI",{});var Va=i(Ue);Ol=l(Va,"use this "),He=s(Va,"A",{href:!0,rel:!0});var Ri=i(He);Nl=l(Ri,"filter"),Ri.forEach(o),Tl=l(Va," to return all available Core ML checkpoints"),Va.forEach(o),qt.forEach(o),ra=d(e),he=s(e,"P",{});var Xa=i(he);ql=l(Xa,"If you can\u2019t find the model you\u2019re interested in, we recommend you follow the instructions for "),Fe=s(Xa,"A",{href:!0,rel:!0});var Bi=i(Fe);xl=l(Bi,"Converting Models to Core ML"),Bi.forEach(o),Il=l(Xa," by Apple."),Xa.forEach(o),sa=d(e),K=s(e,"H2",{class:!0});var Ja=i(K);de=s(Ja,"A",{id:!0,class:!0,href:!0});var Wi=i(de);Yt=s(Wi,"SPAN",{});var Vi=i(Yt);v(Ge.$$.fragment,Vi),Vi.forEach(o),Wi.forEach(o),jl=d(Ja),zt=s(Ja,"SPAN",{});var Xi=i(zt);Ul=l(Xi,"Selecting the Core ML Variant to Use"),Xi.forEach(o),Ja.forEach(o),ia=d(e),Ct=s(e,"P",{});var Ji=i(Ct);Hl=l(Ji,"Stable Diffusion models can be converted to different Core ML variants intended for different purposes:"),Ji.forEach(o),na=d(e),ce=s(e,"UL",{});var Ka=i(ce);Ye=s(Ka,"LI",{});var Qa=i(Ye);Rt=s(Qa,"P",{});var Ki=i(Rt);Fl=l(Ki,"The type of attention blocks used. The attention operation is used to \u201Cpay attention\u201D to the relationship between different areas in the image representations and to understand how the image and text representations are related. Attention is compute- and memory-intensive, so different implementations exist that consider the hardware characteristics of different devices. For Core ML Stable Diffusion models, there are two attention variants:"),Ki.forEach(o),Gl=d(Qa),ze=s(Qa,"UL",{});var Za=i(ze);ue=s(Za,"LI",{});var Ko=i(ue);Bt=s(Ko,"CODE",{});var Qi=i(Bt);Yl=l(Qi,"split_einsum"),Qi.forEach(o),zl=l(Ko," ("),Re=s(Ko,"A",{href:!0,rel:!0});var Zi=i(Re);Rl=l(Zi,"introduced by Apple"),Zi.forEach(o),Bl=l(Ko,") is optimized for ANE devices, which is available in modern iPhones, iPads and M-series computers."),Ko.forEach(o),Wl=d(Za),P=s(Za,"LI",{});var T=i(P);Vl=l(T,"The \u201Coriginal\u201D attention (the base implementation used in "),Wt=s(T,"CODE",{});var en=i(Wt);Xl=l(en,"diffusers"),en.forEach(o),Jl=l(T,") is only compatible with CPU/GPU and not ANE. It can be "),Vt=s(T,"EM",{});var tn=i(Vt);Kl=l(tn,"faster"),tn.forEach(o),Ql=l(T," to run your model on CPU + GPU using "),Xt=s(T,"CODE",{});var on=i(Xt);Zl=l(on,"original"),on.forEach(o),er=l(T," attention than ANE. See "),Be=s(T,"A",{href:!0,rel:!0});var an=i(Be);tr=l(an,"this performance benchmark"),an.forEach(o),or=l(T," as well as some "),We=s(T,"A",{href:!0,rel:!0});var ln=i(We);ar=l(ln,"additional measures provided by the community"),ln.forEach(o),lr=l(T," for additional details."),T.forEach(o),Za.forEach(o),Qa.forEach(o),rr=d(Ka),Ve=s(Ka,"LI",{});var el=i(Ve);Jt=s(el,"P",{});var rn=i(Jt);sr=l(rn,"The supported inference framework."),rn.forEach(o),ir=d(el),Xe=s(el,"UL",{});var tl=i(Xe);At=s(tl,"LI",{});var Di=i(At);Kt=s(Di,"CODE",{});var sn=i(Kt);nr=l(sn,"packages"),sn.forEach(o),pr=l(Di," are suitable for Python inference. This can be used to test converted Core ML models before attempting to integrate them inside native apps, or if you want to explore Core ML performance but don\u2019t need to support native apps. For example, an application with a web UI could perfectly use a Python Core ML backend."),Di.forEach(o),fr=d(tl),O=s(tl,"LI",{});var se=i(O);Qt=s(se,"CODE",{});var nn=i(Qt);hr=l(nn,"compiled"),nn.forEach(o),dr=l(se," models are required for Swift code. The "),Zt=s(se,"CODE",{});var pn=i(Zt);cr=l(pn,"compiled"),pn.forEach(o),ur=l(se," models in the Hub split the large UNet model weights into several files for compatibility with iOS and iPadOS devices. This corresponds to the "),me=s(se,"A",{href:!0,rel:!0});var Mi=i(me);eo=s(Mi,"CODE",{});var fn=i(eo);mr=l(fn,"--chunk-unet"),fn.forEach(o),vr=l(Mi," conversion option"),Mi.forEach(o),wr=l(se,". If you want to support native apps, then you need to select the "),to=s(se,"CODE",{});var hn=i(to);_r=l(hn,"compiled"),hn.forEach(o),yr=l(se," variant."),se.forEach(o),tl.forEach(o),el.forEach(o),Ka.forEach(o),pa=d(e),ve=s(e,"P",{});var ol=i(ve);br=l(ol,"The official Core ML Stable Diffusion "),Je=s(ol,"A",{href:!0,rel:!0});var dn=i(Je);Er=l(dn,"models"),dn.forEach(o),gr=l(ol," include these variants, but the community ones may vary:"),ol.forEach(o),fa=d(e),v(Ke.$$.fragment,e),ha=d(e),St=s(e,"P",{});var cn=i(St);$r=l(cn,"You can download and use the variant you need as shown below."),cn.forEach(o),da=d(e),Q=s(e,"H2",{class:!0});var al=i(Q);we=s(al,"A",{id:!0,class:!0,href:!0});var un=i(we);oo=s(un,"SPAN",{});var mn=i(oo);v(Qe.$$.fragment,mn),mn.forEach(o),un.forEach(o),Pr=d(al),ao=s(al,"SPAN",{});var vn=i(ao);kr=l(vn,"Core ML Inference in Python"),vn.forEach(o),al.forEach(o),ca=d(e),Dt=s(e,"P",{});var wn=i(Dt);Cr=l(wn,"Install the following libraries to run Core ML inference in Python:"),wn.forEach(o),ua=d(e),v(Ze.$$.fragment,e),ma=d(e),Z=s(e,"H3",{class:!0});var ll=i(Z);_e=s(ll,"A",{id:!0,class:!0,href:!0});var _n=i(_e);lo=s(_n,"SPAN",{});var yn=i(lo);v(et.$$.fragment,yn),yn.forEach(o),_n.forEach(o),Ar=d(ll),ro=s(ll,"SPAN",{});var bn=i(ro);Sr=l(bn,"Download the Model Checkpoints"),bn.forEach(o),ll.forEach(o),va=d(e),C=s(e,"P",{});var R=i(C);Dr=l(R,"To run inference in Python, use one of the versions stored in the "),so=s(R,"CODE",{});var En=i(so);Mr=l(En,"packages"),En.forEach(o),Lr=l(R," folders because the "),io=s(R,"CODE",{});var gn=i(io);Or=l(gn,"compiled"),gn.forEach(o),Nr=l(R," ones are only compatible with Swift. You may choose whether you want to use "),no=s(R,"CODE",{});var $n=i(no);Tr=l($n,"original"),$n.forEach(o),qr=l(R," or "),po=s(R,"CODE",{});var Pn=i(po);xr=l(Pn,"split_einsum"),Pn.forEach(o),Ir=l(R," attention."),R.forEach(o),wa=d(e),F=s(e,"P",{});var xt=i(F);jr=l(xt,"This is how you\u2019d download the "),fo=s(xt,"CODE",{});var kn=i(fo);Ur=l(kn,"original"),kn.forEach(o),Hr=l(xt," attention variant from the Hub to a directory called "),ho=s(xt,"CODE",{});var Cn=i(ho);Fr=l(Cn,"models"),Cn.forEach(o),Gr=l(xt,":"),xt.forEach(o),_a=d(e),v(tt.$$.fragment,e),ya=d(e),ee=s(e,"H3",{class:!0});var rl=i(ee);ye=s(rl,"A",{id:!0,class:!0,href:!0});var An=i(ye);co=s(An,"SPAN",{});var Sn=i(co);v(ot.$$.fragment,Sn),Sn.forEach(o),An.forEach(o),Yr=d(rl),uo=s(rl,"SPAN",{});var Dn=i(uo);zr=l(Dn,"Inference"),Dn.forEach(o),rl.forEach(o),ba=d(e),Mt=s(e,"P",{});var Mn=i(Mt);Rr=l(Mn,"Once you have downloaded a snapshot of the model, you can test it using Apple\u2019s Python script."),Mn.forEach(o),Ea=d(e),v(at.$$.fragment,e),ga=d(e),E=s(e,"P",{});var M=i(E);mo=s(M,"CODE",{});var Ln=i(mo);Br=l(Ln,"<output-mlpackages-directory>"),Ln.forEach(o),Wr=l(M," should point to the checkpoint you downloaded in the step above, and "),vo=s(M,"CODE",{});var On=i(vo);Vr=l(On,"--compute-unit"),On.forEach(o),Xr=l(M," indicates the hardware you want to allow for inference. It must be one of the following options: "),wo=s(M,"CODE",{});var Nn=i(wo);Jr=l(Nn,"ALL"),Nn.forEach(o),Kr=l(M,", "),_o=s(M,"CODE",{});var Tn=i(_o);Qr=l(Tn,"CPU_AND_GPU"),Tn.forEach(o),Zr=l(M,", "),yo=s(M,"CODE",{});var qn=i(yo);es=l(qn,"CPU_ONLY"),qn.forEach(o),ts=l(M,", "),bo=s(M,"CODE",{});var xn=i(bo);os=l(xn,"CPU_AND_NE"),xn.forEach(o),as=l(M,". You may also provide an optional output path, and a seed for reproducibility."),M.forEach(o),$a=d(e),N=s(e,"P",{});var De=i(N);ls=l(De,"The inference script assumes you\u2019re using the original version of the Stable Diffusion model, "),Eo=s(De,"CODE",{});var In=i(Eo);rs=l(In,"CompVis/stable-diffusion-v1-4"),In.forEach(o),ss=l(De,". If you use another model, you "),go=s(De,"EM",{});var jn=i(go);is=l(jn,"have"),jn.forEach(o),ns=l(De," to specify its Hub id in the inference command line, using the "),$o=s(De,"CODE",{});var Un=i($o);ps=l(Un,"--model-version"),Un.forEach(o),fs=l(De," option. This works for models already supported and custom models you trained or fine-tuned yourself."),De.forEach(o),Pa=d(e),be=s(e,"P",{});var sl=i(be);hs=l(sl,"For example, if you want to use "),lt=s(sl,"A",{href:!0,rel:!0});var Hn=i(lt);Po=s(Hn,"CODE",{});var Fn=i(Po);ds=l(Fn,"runwayml/stable-diffusion-v1-5"),Fn.forEach(o),Hn.forEach(o),cs=l(sl,":"),sl.forEach(o),ka=d(e),v(rt.$$.fragment,e),Ca=d(e),te=s(e,"H2",{class:!0});var il=i(te);Ee=s(il,"A",{id:!0,class:!0,href:!0});var Gn=i(Ee);ko=s(Gn,"SPAN",{});var Yn=i(ko);v(st.$$.fragment,Yn),Yn.forEach(o),Gn.forEach(o),us=d(il),Co=s(il,"SPAN",{});var zn=i(Co);ms=l(zn,"Core ML inference in Swift"),zn.forEach(o),il.forEach(o),Aa=d(e),ge=s(e,"P",{});var nl=i(ge);vs=l(nl,"Running inference in Swift is slightly faster than in Python because the models are already compiled in the "),Ao=s(nl,"CODE",{});var Rn=i(Ao);ws=l(Rn,"mlmodelc"),Rn.forEach(o),_s=l(nl," format. This is noticeable on app startup when the model is loaded but shouldn\u2019t be noticeable if you run several generations afterward."),nl.forEach(o),Sa=d(e),oe=s(e,"H3",{class:!0});var pl=i(oe);$e=s(pl,"A",{id:!0,class:!0,href:!0});var Bn=i($e);So=s(Bn,"SPAN",{});var Wn=i(So);v(it.$$.fragment,Wn),Wn.forEach(o),Bn.forEach(o),ys=d(pl),Do=s(pl,"SPAN",{});var Vn=i(Do);bs=l(Vn,"Download"),Vn.forEach(o),pl.forEach(o),Da=d(e),G=s(e,"P",{});var It=i(G);Es=l(It,"To run inference in Swift on your Mac, you need one of the "),Mo=s(It,"CODE",{});var Xn=i(Mo);gs=l(Xn,"compiled"),Xn.forEach(o),$s=l(It," checkpoint versions. We recommend you download them locally using Python code similar to the previous example, but with one of the "),Lo=s(It,"CODE",{});var Jn=i(Lo);Ps=l(Jn,"compiled"),Jn.forEach(o),ks=l(It," variants:"),It.forEach(o),Ma=d(e),v(nt.$$.fragment,e),La=d(e),ae=s(e,"H3",{class:!0});var fl=i(ae);Pe=s(fl,"A",{id:!0,class:!0,href:!0});var Kn=i(Pe);Oo=s(Kn,"SPAN",{});var Qn=i(Oo);v(pt.$$.fragment,Qn),Qn.forEach(o),Kn.forEach(o),Cs=d(fl),No=s(fl,"SPAN",{});var Zn=i(No);As=l(Zn,"Inference"),Zn.forEach(o),fl.forEach(o),Oa=d(e),Lt=s(e,"P",{});var ep=i(Lt);Ss=l(ep,"To run inference, please clone Apple\u2019s repo:"),ep.forEach(o),Na=d(e),v(ft.$$.fragment,e),Ta=d(e),ke=s(e,"P",{});var hl=i(ke);Ds=l(hl,"And then use Apple\u2019s command line tool, "),ht=s(hl,"A",{href:!0,rel:!0});var tp=i(ht);Ms=l(tp,"Swift Package Manager"),tp.forEach(o),Ls=l(hl,":"),hl.forEach(o),qa=d(e),v(dt.$$.fragment,e),xa=d(e),u=s(e,"P",{});var g=i(u);Os=l(g,"You have to specify in "),To=s(g,"CODE",{});var op=i(To);Ns=l(op,"--resource-path"),op.forEach(o),Ts=l(g," one of the checkpoints downloaded in the previous step, so please make sure it contains compiled Core ML bundles with the extension "),qo=s(g,"CODE",{});var ap=i(qo);qs=l(ap,".mlmodelc"),ap.forEach(o),xs=l(g,". The "),xo=s(g,"CODE",{});var lp=i(xo);Is=l(lp,"--compute-units"),lp.forEach(o),js=l(g," has to be one of these values: "),Io=s(g,"CODE",{});var rp=i(Io);Us=l(rp,"all"),rp.forEach(o),Hs=l(g,", "),jo=s(g,"CODE",{});var sp=i(jo);Fs=l(sp,"cpuOnly"),sp.forEach(o),Gs=l(g,", "),Uo=s(g,"CODE",{});var ip=i(Uo);Ys=l(ip,"cpuAndGPU"),ip.forEach(o),zs=l(g,", "),Ho=s(g,"CODE",{});var np=i(Ho);Rs=l(np,"cpuAndNeuralEngine"),np.forEach(o),Bs=l(g,"."),g.forEach(o),Ia=d(e),Ce=s(e,"P",{});var dl=i(Ce);Ws=l(dl,"For more details, please refer to the "),ct=s(dl,"A",{href:!0,rel:!0});var pp=i(ct);Vs=l(pp,"instructions in Apple\u2019s repo"),pp.forEach(o),Xs=l(dl,"."),dl.forEach(o),ja=d(e),le=s(e,"H2",{class:!0});var cl=i(le);Ae=s(cl,"A",{id:!0,class:!0,href:!0});var fp=i(Ae);Fo=s(fp,"SPAN",{});var hp=i(Fo);v(ut.$$.fragment,hp),hp.forEach(o),fp.forEach(o),Js=d(cl),Go=s(cl,"SPAN",{});var dp=i(Go);Ks=l(dp,"Supported Diffusers Features"),dp.forEach(o),cl.forEach(o),Ua=d(e),Ot=s(e,"P",{});var cp=i(Ot);Qs=l(cp,"The Core ML models and inference code don\u2019t support many of the features, options, and flexibility of \u{1F9E8} Diffusers. These are some of the limitations to keep in mind:"),cp.forEach(o),Ha=d(e),Y=s(e,"UL",{});var jt=i(Y);Yo=s(jt,"LI",{});var up=i(Yo);Zs=l(up,"Core ML models are only suitable for inference. They can\u2019t be used for training or fine-tuning."),up.forEach(o),ei=d(jt),x=s(jt,"LI",{});var Me=i(x);ti=l(Me,"Only two schedulers have been ported to Swift, the default one used by Stable Diffusion and "),zo=s(Me,"CODE",{});var mp=i(zo);oi=l(mp,"DPMSolverMultistepScheduler"),mp.forEach(o),ai=l(Me,", which we ported to Swift from our "),Ro=s(Me,"CODE",{});var vp=i(Ro);li=l(vp,"diffusers"),vp.forEach(o),ri=l(Me," implementation. We recommend you use "),Bo=s(Me,"CODE",{});var wp=i(Bo);si=l(wp,"DPMSolverMultistepScheduler"),wp.forEach(o),ii=l(Me,", since it produces the same quality in about half the steps."),Me.forEach(o),ni=d(jt),Wo=s(jt,"LI",{});var _p=i(Wo);pi=l(_p,"Negative prompts, classifier-free guidance scale, and image-to-image tasks are available in the inference code. Advanced features such as depth guidance, ControlNet, and latent upscalers are not available yet."),_p.forEach(o),jt.forEach(o),Fa=d(e),z=s(e,"P",{});var Ut=i(z);fi=l(Ut,"Apple\u2019s "),mt=s(Ut,"A",{href:!0,rel:!0});var yp=i(mt);hi=l(yp,"conversion and inference repo"),yp.forEach(o),di=l(Ut," and our own "),vt=s(Ut,"A",{href:!0,rel:!0});var bp=i(vt);ci=l(bp,"swift-coreml-diffusers"),bp.forEach(o),ui=l(Ut," repos are intended as technology demonstrators to enable other developers to build upon."),Ut.forEach(o),Ga=d(e),Nt=s(e,"P",{});var Ep=i(Nt);mi=l(Ep,"If you feel strongly about any missing features, please feel free to open a feature request or, better yet, a contribution PR :)"),Ep.forEach(o),Ya=d(e),re=s(e,"H2",{class:!0});var ul=i(re);Se=s(ul,"A",{id:!0,class:!0,href:!0});var gp=i(Se);Vo=s(gp,"SPAN",{});var $p=i(Vo);v(wt.$$.fragment,$p),$p.forEach(o),gp.forEach(o),vi=d(ul),Xo=s(ul,"SPAN",{});var Pp=i(Xo);wi=l(Pp,"Native Diffusers Swift app"),Pp.forEach(o),ul.forEach(o),za=d(e),A=s(e,"P",{});var B=i(A);_i=l(B,"One easy way to run Stable Diffusion on your own Apple hardware is to use "),_t=s(B,"A",{href:!0,rel:!0});var kp=i(_t);yi=l(kp,"our open-source Swift repo"),kp.forEach(o),bi=l(B,", based on "),Jo=s(B,"CODE",{});var Cp=i(Jo);Ei=l(Cp,"diffusers"),Cp.forEach(o),gi=l(B," and Apple\u2019s conversion and inference repo. You can study the code, compile it with "),yt=s(B,"A",{href:!0,rel:!0});var Ap=i(yt);$i=l(Ap,"Xcode"),Ap.forEach(o),Pi=l(B," and adapt it for your own needs. For your convenience, there\u2019s also a "),bt=s(B,"A",{href:!0,rel:!0});var Sp=i(bt);ki=l(Sp,"standalone Mac app in the App Store"),Sp.forEach(o),Ci=l(B,", so you can play with it without having to deal with the code or IDE. If you are a developer and have determined that Core ML is the best solution to build your Stable Diffusion app, then you can use the rest of this guide to get started with your project. We can\u2019t wait to see what you\u2019ll build :)"),B.forEach(o),this.h()},h(){f(c,"name","hf:doc:metadata"),f(c,"content",JSON.stringify(Ip)),f(L,"id","how-to-run-stable-diffusion-with-core-ml"),f(L,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(L,"href","#how-to-run-stable-diffusion-with-core-ml"),f($,"class","relative group"),f(D,"href","https://developer.apple.com/documentation/coreml"),f(D,"rel","nofollow"),f(fe,"id","stable-diffusion-core-ml-checkpoints"),f(fe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(fe,"href","#stable-diffusion-core-ml-checkpoints"),f(J,"class","relative group"),f(qe,"href","https://github.com/apple/ml-stable-diffusion#-converting-models-to-core-ml"),f(qe,"rel","nofollow"),f(Ie,"href","https://huggingface.co/apple"),f(Ie,"rel","nofollow"),f(je,"href","https://huggingface.co/coreml"),f(je,"rel","nofollow"),f(He,"href","https://huggingface.co/models?pipeline_tag=text-to-image&library=coreml&p=2&sort=likes"),f(He,"rel","nofollow"),f(Fe,"href","https://github.com/apple/ml-stable-diffusion#-converting-models-to-core-ml"),f(Fe,"rel","nofollow"),f(de,"id","selecting-the-core-ml-variant-to-use"),f(de,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(de,"href","#selecting-the-core-ml-variant-to-use"),f(K,"class","relative group"),f(Re,"href","https://machinelearning.apple.com/research/neural-engine-transformers"),f(Re,"rel","nofollow"),f(Be,"href","https://huggingface.co/blog/fast-mac-diffusers#performance-benchmarks"),f(Be,"rel","nofollow"),f(We,"href","https://github.com/huggingface/swift-coreml-diffusers/issues/31"),f(We,"rel","nofollow"),f(me,"href","https://github.com/apple/ml-stable-diffusion#-converting-models-to-core-ml"),f(me,"rel","nofollow"),f(Je,"href","https://huggingface.co/apple/coreml-stable-diffusion-v1-4/tree/main"),f(Je,"rel","nofollow"),f(we,"id","core-ml-inference-in-python"),f(we,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(we,"href","#core-ml-inference-in-python"),f(Q,"class","relative group"),f(_e,"id","download-the-model-checkpoints"),f(_e,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(_e,"href","#download-the-model-checkpoints"),f(Z,"class","relative group"),f(ye,"id","python-inference"),f(ye,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(ye,"href","#python-inference"),f(ee,"class","relative group"),f(lt,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),f(lt,"rel","nofollow"),f(Ee,"id","core-ml-inference-in-swift"),f(Ee,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Ee,"href","#core-ml-inference-in-swift"),f(te,"class","relative group"),f($e,"id","download"),f($e,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f($e,"href","#download"),f(oe,"class","relative group"),f(Pe,"id","swift-inference"),f(Pe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Pe,"href","#swift-inference"),f(ae,"class","relative group"),f(ht,"href","https://www.swift.org/package-manager/#"),f(ht,"rel","nofollow"),f(ct,"href","https://github.com/apple/ml-stable-diffusion"),f(ct,"rel","nofollow"),f(Ae,"id","supported-diffusers-features"),f(Ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Ae,"href","#supported-diffusers-features"),f(le,"class","relative group"),f(mt,"href","https://github.com/apple/ml-stable-diffusion"),f(mt,"rel","nofollow"),f(vt,"href","https://github.com/huggingface/swift-coreml-diffusers"),f(vt,"rel","nofollow"),f(Se,"id","native-diffusers-swift-app"),f(Se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Se,"href","#native-diffusers-swift-app"),f(re,"class","relative group"),f(_t,"href","https://github.com/huggingface/swift-coreml-diffusers"),f(_t,"rel","nofollow"),f(yt,"href","https://developer.apple.com/xcode/"),f(yt,"rel","nofollow"),f(bt,"href","https://apps.apple.com/app/diffusers/id1666309574"),f(bt,"rel","nofollow")},m(e,n){t(document.head,c),p(e,ie,n),p(e,$,n),t($,L),t(L,W),w(S,W,null),t($,Oe),t($,V),t(V,j),p(e,ne,n),p(e,q,n),t(q,D),t(D,k),t(q,gt),p(e,Ne,n),p(e,X,n),t(X,ml),p(e,Zo,n),w(pe,e,n),p(e,ea,n),p(e,J,n),t(J,fe),t(fe,Ht),w(Te,Ht,null),t(J,vl),t(J,Ft),t(Ft,wl),p(e,ta,n),p(e,$t,n),t($t,_l),p(e,oa,n),p(e,U,n),t(U,yl),t(U,qe),t(qe,bl),t(U,El),t(U,Gt),t(Gt,gl),t(U,$l),p(e,aa,n),p(e,Pt,n),t(Pt,Pl),p(e,la,n),p(e,H,n),t(H,xe),t(xe,kl),t(xe,Ie),t(Ie,Cl),t(xe,Al),t(H,Sl),t(H,kt),t(kt,je),t(je,Dl),t(kt,Ml),t(H,Ll),t(H,Ue),t(Ue,Ol),t(Ue,He),t(He,Nl),t(Ue,Tl),p(e,ra,n),p(e,he,n),t(he,ql),t(he,Fe),t(Fe,xl),t(he,Il),p(e,sa,n),p(e,K,n),t(K,de),t(de,Yt),w(Ge,Yt,null),t(K,jl),t(K,zt),t(zt,Ul),p(e,ia,n),p(e,Ct,n),t(Ct,Hl),p(e,na,n),p(e,ce,n),t(ce,Ye),t(Ye,Rt),t(Rt,Fl),t(Ye,Gl),t(Ye,ze),t(ze,ue),t(ue,Bt),t(Bt,Yl),t(ue,zl),t(ue,Re),t(Re,Rl),t(ue,Bl),t(ze,Wl),t(ze,P),t(P,Vl),t(P,Wt),t(Wt,Xl),t(P,Jl),t(P,Vt),t(Vt,Kl),t(P,Ql),t(P,Xt),t(Xt,Zl),t(P,er),t(P,Be),t(Be,tr),t(P,or),t(P,We),t(We,ar),t(P,lr),t(ce,rr),t(ce,Ve),t(Ve,Jt),t(Jt,sr),t(Ve,ir),t(Ve,Xe),t(Xe,At),t(At,Kt),t(Kt,nr),t(At,pr),t(Xe,fr),t(Xe,O),t(O,Qt),t(Qt,hr),t(O,dr),t(O,Zt),t(Zt,cr),t(O,ur),t(O,me),t(me,eo),t(eo,mr),t(me,vr),t(O,wr),t(O,to),t(to,_r),t(O,yr),p(e,pa,n),p(e,ve,n),t(ve,br),t(ve,Je),t(Je,Er),t(ve,gr),p(e,fa,n),w(Ke,e,n),p(e,ha,n),p(e,St,n),t(St,$r),p(e,da,n),p(e,Q,n),t(Q,we),t(we,oo),w(Qe,oo,null),t(Q,Pr),t(Q,ao),t(ao,kr),p(e,ca,n),p(e,Dt,n),t(Dt,Cr),p(e,ua,n),w(Ze,e,n),p(e,ma,n),p(e,Z,n),t(Z,_e),t(_e,lo),w(et,lo,null),t(Z,Ar),t(Z,ro),t(ro,Sr),p(e,va,n),p(e,C,n),t(C,Dr),t(C,so),t(so,Mr),t(C,Lr),t(C,io),t(io,Or),t(C,Nr),t(C,no),t(no,Tr),t(C,qr),t(C,po),t(po,xr),t(C,Ir),p(e,wa,n),p(e,F,n),t(F,jr),t(F,fo),t(fo,Ur),t(F,Hr),t(F,ho),t(ho,Fr),t(F,Gr),p(e,_a,n),w(tt,e,n),p(e,ya,n),p(e,ee,n),t(ee,ye),t(ye,co),w(ot,co,null),t(ee,Yr),t(ee,uo),t(uo,zr),p(e,ba,n),p(e,Mt,n),t(Mt,Rr),p(e,Ea,n),w(at,e,n),p(e,ga,n),p(e,E,n),t(E,mo),t(mo,Br),t(E,Wr),t(E,vo),t(vo,Vr),t(E,Xr),t(E,wo),t(wo,Jr),t(E,Kr),t(E,_o),t(_o,Qr),t(E,Zr),t(E,yo),t(yo,es),t(E,ts),t(E,bo),t(bo,os),t(E,as),p(e,$a,n),p(e,N,n),t(N,ls),t(N,Eo),t(Eo,rs),t(N,ss),t(N,go),t(go,is),t(N,ns),t(N,$o),t($o,ps),t(N,fs),p(e,Pa,n),p(e,be,n),t(be,hs),t(be,lt),t(lt,Po),t(Po,ds),t(be,cs),p(e,ka,n),w(rt,e,n),p(e,Ca,n),p(e,te,n),t(te,Ee),t(Ee,ko),w(st,ko,null),t(te,us),t(te,Co),t(Co,ms),p(e,Aa,n),p(e,ge,n),t(ge,vs),t(ge,Ao),t(Ao,ws),t(ge,_s),p(e,Sa,n),p(e,oe,n),t(oe,$e),t($e,So),w(it,So,null),t(oe,ys),t(oe,Do),t(Do,bs),p(e,Da,n),p(e,G,n),t(G,Es),t(G,Mo),t(Mo,gs),t(G,$s),t(G,Lo),t(Lo,Ps),t(G,ks),p(e,Ma,n),w(nt,e,n),p(e,La,n),p(e,ae,n),t(ae,Pe),t(Pe,Oo),w(pt,Oo,null),t(ae,Cs),t(ae,No),t(No,As),p(e,Oa,n),p(e,Lt,n),t(Lt,Ss),p(e,Na,n),w(ft,e,n),p(e,Ta,n),p(e,ke,n),t(ke,Ds),t(ke,ht),t(ht,Ms),t(ke,Ls),p(e,qa,n),w(dt,e,n),p(e,xa,n),p(e,u,n),t(u,Os),t(u,To),t(To,Ns),t(u,Ts),t(u,qo),t(qo,qs),t(u,xs),t(u,xo),t(xo,Is),t(u,js),t(u,Io),t(Io,Us),t(u,Hs),t(u,jo),t(jo,Fs),t(u,Gs),t(u,Uo),t(Uo,Ys),t(u,zs),t(u,Ho),t(Ho,Rs),t(u,Bs),p(e,Ia,n),p(e,Ce,n),t(Ce,Ws),t(Ce,ct),t(ct,Vs),t(Ce,Xs),p(e,ja,n),p(e,le,n),t(le,Ae),t(Ae,Fo),w(ut,Fo,null),t(le,Js),t(le,Go),t(Go,Ks),p(e,Ua,n),p(e,Ot,n),t(Ot,Qs),p(e,Ha,n),p(e,Y,n),t(Y,Yo),t(Yo,Zs),t(Y,ei),t(Y,x),t(x,ti),t(x,zo),t(zo,oi),t(x,ai),t(x,Ro),t(Ro,li),t(x,ri),t(x,Bo),t(Bo,si),t(x,ii),t(Y,ni),t(Y,Wo),t(Wo,pi),p(e,Fa,n),p(e,z,n),t(z,fi),t(z,mt),t(mt,hi),t(z,di),t(z,vt),t(vt,ci),t(z,ui),p(e,Ga,n),p(e,Nt,n),t(Nt,mi),p(e,Ya,n),p(e,re,n),t(re,Se),t(Se,Vo),w(wt,Vo,null),t(re,vi),t(re,Xo),t(Xo,wi),p(e,za,n),p(e,A,n),t(A,_i),t(A,_t),t(_t,yi),t(A,bi),t(A,Jo),t(Jo,Ei),t(A,gi),t(A,yt),t(yt,$i),t(A,Pi),t(A,bt),t(bt,ki),t(A,Ci),Ra=!0},p(e,[n]){const Et={};n&2&&(Et.$$scope={dirty:n,ctx:e}),pe.$set(Et)},i(e){Ra||(_(S.$$.fragment,e),_(pe.$$.fragment,e),_(Te.$$.fragment,e),_(Ge.$$.fragment,e),_(Ke.$$.fragment,e),_(Qe.$$.fragment,e),_(Ze.$$.fragment,e),_(et.$$.fragment,e),_(tt.$$.fragment,e),_(ot.$$.fragment,e),_(at.$$.fragment,e),_(rt.$$.fragment,e),_(st.$$.fragment,e),_(it.$$.fragment,e),_(nt.$$.fragment,e),_(pt.$$.fragment,e),_(ft.$$.fragment,e),_(dt.$$.fragment,e),_(ut.$$.fragment,e),_(wt.$$.fragment,e),Ra=!0)},o(e){y(S.$$.fragment,e),y(pe.$$.fragment,e),y(Te.$$.fragment,e),y(Ge.$$.fragment,e),y(Ke.$$.fragment,e),y(Qe.$$.fragment,e),y(Ze.$$.fragment,e),y(et.$$.fragment,e),y(tt.$$.fragment,e),y(ot.$$.fragment,e),y(at.$$.fragment,e),y(rt.$$.fragment,e),y(st.$$.fragment,e),y(it.$$.fragment,e),y(nt.$$.fragment,e),y(pt.$$.fragment,e),y(ft.$$.fragment,e),y(dt.$$.fragment,e),y(ut.$$.fragment,e),y(wt.$$.fragment,e),Ra=!1},d(e){o(c),e&&o(ie),e&&o($),b(S),e&&o(ne),e&&o(q),e&&o(Ne),e&&o(X),e&&o(Zo),b(pe,e),e&&o(ea),e&&o(J),b(Te),e&&o(ta),e&&o($t),e&&o(oa),e&&o(U),e&&o(aa),e&&o(Pt),e&&o(la),e&&o(H),e&&o(ra),e&&o(he),e&&o(sa),e&&o(K),b(Ge),e&&o(ia),e&&o(Ct),e&&o(na),e&&o(ce),e&&o(pa),e&&o(ve),e&&o(fa),b(Ke,e),e&&o(ha),e&&o(St),e&&o(da),e&&o(Q),b(Qe),e&&o(ca),e&&o(Dt),e&&o(ua),b(Ze,e),e&&o(ma),e&&o(Z),b(et),e&&o(va),e&&o(C),e&&o(wa),e&&o(F),e&&o(_a),b(tt,e),e&&o(ya),e&&o(ee),b(ot),e&&o(ba),e&&o(Mt),e&&o(Ea),b(at,e),e&&o(ga),e&&o(E),e&&o($a),e&&o(N),e&&o(Pa),e&&o(be),e&&o(ka),b(rt,e),e&&o(Ca),e&&o(te),b(st),e&&o(Aa),e&&o(ge),e&&o(Sa),e&&o(oe),b(it),e&&o(Da),e&&o(G),e&&o(Ma),b(nt,e),e&&o(La),e&&o(ae),b(pt),e&&o(Oa),e&&o(Lt),e&&o(Na),b(ft,e),e&&o(Ta),e&&o(ke),e&&o(qa),b(dt,e),e&&o(xa),e&&o(u),e&&o(Ia),e&&o(Ce),e&&o(ja),e&&o(le),b(ut),e&&o(Ua),e&&o(Ot),e&&o(Ha),e&&o(Y),e&&o(Fa),e&&o(z),e&&o(Ga),e&&o(Nt),e&&o(Ya),e&&o(re),b(wt),e&&o(za),e&&o(A)}}}const Ip={local:"how-to-run-stable-diffusion-with-core-ml",sections:[{local:"stable-diffusion-core-ml-checkpoints",title:"Stable Diffusion Core ML Checkpoints"},{local:"selecting-the-core-ml-variant-to-use",title:"Selecting the Core ML Variant to Use"},{local:"core-ml-inference-in-python",sections:[{local:"download-the-model-checkpoints",title:"Download the Model Checkpoints"},{local:"python-inference",title:"Inference"}],title:"Core ML Inference in Python"},{local:"core-ml-inference-in-swift",sections:[{local:"download",title:"Download"},{local:"swift-inference",title:"Inference"}],title:"Core ML inference in Swift"},{local:"supported-diffusers-features",title:"Supported Diffusers Features"},{local:"native-diffusers-swift-app",title:"Native Diffusers Swift app"}],title:"How to run Stable Diffusion with Core ML"};function jp(Qo){return Np(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Yp extends Dp{constructor(c){super();Mp(this,c,jp,xp,Lp,{})}}export{Yp as default,Ip as metadata};
