import{S as Ml,i as El,s as vl,e as a,k as u,w as $,t as l,M as jl,c as o,d as s,m as d,a as i,x as k,h as r,b as p,G as t,g as c,y as P,q as Z,o as A,B as G,v as Jl}from"../../chunks/vendor-hf-doc-builder.js";import{T as Ul}from"../../chunks/Tip-hf-doc-builder.js";import{I as Gs}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as _e}from"../../chunks/CodeBlock-hf-doc-builder.js";function Tl(Be){let f,z,h,_,I;return{c(){f=a("p"),z=l("To learn more, take a look at the "),h=a("a"),_=l("Distributed Inference with \u{1F917} Accelerate"),I=l(" guide."),this.h()},l(w){f=o(w,"P",{});var j=i(f);z=r(j,"To learn more, take a look at the "),h=o(j,"A",{href:!0,rel:!0});var X=i(h);_=r(X,"Distributed Inference with \u{1F917} Accelerate"),X.forEach(s),I=r(j," guide."),j.forEach(s),this.h()},h(){p(h,"href","https://huggingface.co/docs/accelerate/en/usage_guides/distributed_inference#distributed-inference-with-accelerate"),p(h,"rel","nofollow")},m(w,j){c(w,f,j),t(f,z),t(f,h),t(h,_),t(f,I)},d(w){w&&s(f)}}}function gl(Be){let f,z,h,_,I,w,j,X,yt,Se,J,wt,x,_t,bt,F,Mt,Et,Ye,ue,vt,Qe,C,N,be,q,jt,Me,Jt,Ve,R,Ut,O,Tt,gt,He,m,$t,L,kt,Pt,Ee,Zt,At,ve,Gt,It,de,Ct,Dt,je,zt,Xt,xe,W,Nt,K,Rt,Wt,Fe,ee,qe,U,Bt,Je,St,Yt,Ue,Qt,Vt,Oe,te,Le,B,Ke,D,S,Te,se,Ht,ge,xt,et,Y,Ft,le,$e,qt,Ot,tt,b,Lt,ke,Kt,es,Pe,ts,ss,fe,ls,rs,st,re,lt,y,as,ae,Ze,os,is,Ae,ns,cs,Ge,ps,us,Ie,ds,fs,rt,M,hs,he,ms,ys,Ce,ws,_s,De,bs,Ms,at,oe,ot,E,Es,ie,ze,vs,js,Xe,Js,Us,Ne,Ts,gs,it,ne,nt,T,$s,Re,ks,Ps,We,Zs,As,ct,ce,pt;return w=new Gs({}),q=new Gs({}),ee=new _e({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBQYXJ0aWFsU3RhdGUlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUlMEEpJTBBZGlzdHJpYnV0ZWRfc3RhdGUlMjAlM0QlMjBQYXJ0aWFsU3RhdGUoKSUwQXBpcGVsaW5lLnRvKGRpc3RyaWJ1dGVkX3N0YXRlLmRldmljZSklMEElMEF3aXRoJTIwZGlzdHJpYnV0ZWRfc3RhdGUuc3BsaXRfYmV0d2Vlbl9wcm9jZXNzZXMoJTVCJTIyYSUyMGRvZyUyMiUyQyUyMCUyMmElMjBjYXQlMjIlNUQpJTIwYXMlMjBwcm9tcHQlM0ElMEElMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQpLmltYWdlcyU1QjAlNUQlMEElMjAlMjAlMjAlMjByZXN1bHQuc2F2ZShmJTIycmVzdWx0XyU3QmRpc3RyaWJ1dGVkX3N0YXRlLnByb2Nlc3NfaW5kZXglN0QucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> PartialState
<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, use_safetensors=<span class="hljs-literal">True</span>
)
distributed_state = PartialState()
pipeline.to(distributed_state.device)

<span class="hljs-keyword">with</span> distributed_state.split_between_processes([<span class="hljs-string">&quot;a dog&quot;</span>, <span class="hljs-string">&quot;a cat&quot;</span>]) <span class="hljs-keyword">as</span> prompt:
    result = pipeline(prompt).images[<span class="hljs-number">0</span>]
    result.save(<span class="hljs-string">f&quot;result_<span class="hljs-subst">{distributed_state.process_index}</span>.png&quot;</span>)`}}),te=new _e({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHJ1bl9kaXN0cmlidXRlZC5weSUyMC0tbnVtX3Byb2Nlc3NlcyUzRDI=",highlighted:"accelerate launch run_distributed.py --num_processes=2"}}),B=new Ul({props:{$$slots:{default:[Tl]},$$scope:{ctx:Be}}}),se=new Gs({}),re=new _e({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjB0b3JjaC5kaXN0cmlidXRlZCUyMGFzJTIwZGlzdCUwQWltcG9ydCUyMHRvcmNoLm11bHRpcHJvY2Vzc2luZyUyMGFzJTIwbXAlMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFzZCUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUlMEEp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> torch.distributed <span class="hljs-keyword">as</span> dist
<span class="hljs-keyword">import</span> torch.multiprocessing <span class="hljs-keyword">as</span> mp

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

sd = DiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>, torch_dtype=torch.float16, use_safetensors=<span class="hljs-literal">True</span>
)`}}),oe=new _e({props:{code:"ZGVmJTIwcnVuX2luZmVyZW5jZShyYW5rJTJDJTIwd29ybGRfc2l6ZSklM0ElMEElMjAlMjAlMjAlMjBkaXN0LmluaXRfcHJvY2Vzc19ncm91cCglMjJuY2NsJTIyJTJDJTIwcmFuayUzRHJhbmslMkMlMjB3b3JsZF9zaXplJTNEd29ybGRfc2l6ZSklMEElMEElMjAlMjAlMjAlMjBzZC50byhyYW5rKSUwQSUwQSUyMCUyMCUyMCUyMGlmJTIwdG9yY2guZGlzdHJpYnV0ZWQuZ2V0X3JhbmsoKSUyMCUzRCUzRCUyMDAlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcm9tcHQlMjAlM0QlMjAlMjJhJTIwZG9nJTIyJTBBJTIwJTIwJTIwJTIwZWxpZiUyMHRvcmNoLmRpc3RyaWJ1dGVkLmdldF9yYW5rKCklMjAlM0QlM0QlMjAxJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJvbXB0JTIwJTNEJTIwJTIyYSUyMGNhdCUyMiUwQSUwQSUyMCUyMCUyMCUyMGltYWdlJTIwJTNEJTIwc2QocHJvbXB0KS5pbWFnZXMlNUIwJTVEJTBBJTIwJTIwJTIwJTIwaW1hZ2Uuc2F2ZShmJTIyLiUyRiU3QidfJy5qb2luKHByb21wdCklN0QucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">run_inference</span>(<span class="hljs-params">rank, world_size</span>):
    dist.init_process_group(<span class="hljs-string">&quot;nccl&quot;</span>, rank=rank, world_size=world_size)

    sd.to(rank)

    <span class="hljs-keyword">if</span> torch.distributed.get_rank() == <span class="hljs-number">0</span>:
        prompt = <span class="hljs-string">&quot;a dog&quot;</span>
    <span class="hljs-keyword">elif</span> torch.distributed.get_rank() == <span class="hljs-number">1</span>:
        prompt = <span class="hljs-string">&quot;a cat&quot;</span>

    image = sd(prompt).images[<span class="hljs-number">0</span>]
    image.save(<span class="hljs-string">f&quot;./<span class="hljs-subst">{<span class="hljs-string">&#x27;_&#x27;</span>.join(prompt)}</span>.png&quot;</span>)`}}),ne=new _e({props:{code:"ZGVmJTIwbWFpbigpJTNBJTBBJTIwJTIwJTIwJTIwd29ybGRfc2l6ZSUyMCUzRCUyMDIlMEElMjAlMjAlMjAlMjBtcC5zcGF3bihydW5faW5mZXJlbmNlJTJDJTIwYXJncyUzRCh3b3JsZF9zaXplJTJDKSUyQyUyMG5wcm9jcyUzRHdvcmxkX3NpemUlMkMlMjBqb2luJTNEVHJ1ZSklMEElMEElMEFpZiUyMF9fbmFtZV9fJTIwJTNEJTNEJTIwJTIyX19tYWluX18lMjIlM0ElMEElMjAlMjAlMjAlMjBtYWluKCk=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">main</span>():
    world_size = <span class="hljs-number">2</span>
    mp.spawn(run_inference, args=(world_size,), nprocs=world_size, join=<span class="hljs-literal">True</span>)


<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&quot;__main__&quot;</span>:
    main()`}}),ce=new _e({props:{code:"dG9yY2hydW4lMjBydW5fZGlzdHJpYnV0ZWQucHklMjAtLW5wcm9jX3Blcl9ub2RlJTNEMg==",highlighted:"torchrun run_distributed.py --nproc_per_node=2"}}),{c(){f=a("meta"),z=u(),h=a("h1"),_=a("a"),I=a("span"),$(w.$$.fragment),j=u(),X=a("span"),yt=l("Distributed inference with multiple GPUs"),Se=u(),J=a("p"),wt=l("On distributed setups, you can run inference across multiple GPUs with \u{1F917} "),x=a("a"),_t=l("Accelerate"),bt=l(" or "),F=a("a"),Mt=l("PyTorch Distributed"),Et=l(", which is useful for generating with multiple prompts in parallel."),Ye=u(),ue=a("p"),vt=l("This guide will show you how to use \u{1F917} Accelerate and PyTorch Distributed for distributed inference."),Qe=u(),C=a("h2"),N=a("a"),be=a("span"),$(q.$$.fragment),jt=u(),Me=a("span"),Jt=l("\u{1F917} Accelerate"),Ve=u(),R=a("p"),Ut=l("\u{1F917} "),O=a("a"),Tt=l("Accelerate"),gt=l(" is a library designed to make it easy to train or run inference across distributed setups. It simplifies the process of setting up the distributed environment, allowing you to focus on your PyTorch code."),He=u(),m=a("p"),$t=l("To begin, create a Python file and initialize an "),L=a("a"),kt=l("accelerate.PartialState"),Pt=l(" to create a distributed environment; your setup is automatically detected so you don\u2019t need to explicitly define the "),Ee=a("code"),Zt=l("rank"),At=l(" or "),ve=a("code"),Gt=l("world_size"),It=l(". Move the "),de=a("a"),Ct=l("DiffusionPipeline"),Dt=l(" to "),je=a("code"),zt=l("distributed_state.device"),Xt=l(" to assign a GPU to each process."),xe=u(),W=a("p"),Nt=l("Now use the "),K=a("a"),Rt=l("split_between_processes"),Wt=l(" utility as a context manager to automatically distribute the prompts between the number of processes."),Fe=u(),$(ee.$$.fragment),qe=u(),U=a("p"),Bt=l("Use the "),Je=a("code"),St=l("--num_processes"),Yt=l(" argument to specify the number of GPUs to use, and call "),Ue=a("code"),Qt=l("accelerate launch"),Vt=l(" to run the script:"),Oe=u(),$(te.$$.fragment),Le=u(),$(B.$$.fragment),Ke=u(),D=a("h2"),S=a("a"),Te=a("span"),$(se.$$.fragment),Ht=u(),ge=a("span"),xt=l("PyTorch Distributed"),et=u(),Y=a("p"),Ft=l("PyTorch supports "),le=a("a"),$e=a("code"),qt=l("DistributedDataParallel"),Ot=l(" which enables data parallelism."),tt=u(),b=a("p"),Lt=l("To start, create a Python file and import "),ke=a("code"),Kt=l("torch.distributed"),es=l(" and "),Pe=a("code"),ts=l("torch.multiprocessing"),ss=l(" to set up the distributed process group and to spawn the processes for inference on each GPU. You should also initialize a "),fe=a("a"),ls=l("DiffusionPipeline"),rs=l(":"),st=u(),$(re.$$.fragment),lt=u(),y=a("p"),as=l("You\u2019ll want to create a function to run inference; "),ae=a("a"),Ze=a("code"),os=l("init_process_group"),is=l(" handles creating a distributed environment with the type of backend to use, the "),Ae=a("code"),ns=l("rank"),cs=l(" of the current process, and the "),Ge=a("code"),ps=l("world_size"),us=l(" or the number of processes participating. If you\u2019re running inference in parallel over 2 GPUs, then the "),Ie=a("code"),ds=l("world_size"),fs=l(" is 2."),rt=u(),M=a("p"),hs=l("Move the "),he=a("a"),ms=l("DiffusionPipeline"),ys=l(" to "),Ce=a("code"),ws=l("rank"),_s=l(" and use "),De=a("code"),bs=l("get_rank"),Ms=l(" to assign a GPU to each process, where each process handles a different prompt:"),at=u(),$(oe.$$.fragment),ot=u(),E=a("p"),Es=l("To run the distributed inference, call "),ie=a("a"),ze=a("code"),vs=l("mp.spawn"),js=l(" to run the "),Xe=a("code"),Js=l("run_inference"),Us=l(" function on the number of GPUs defined in "),Ne=a("code"),Ts=l("world_size"),gs=l(":"),it=u(),$(ne.$$.fragment),nt=u(),T=a("p"),$s=l("Once you\u2019ve completed the inference script, use the "),Re=a("code"),ks=l("--nproc_per_node"),Ps=l(" argument to specify the number of GPUs to use and call "),We=a("code"),Zs=l("torchrun"),As=l(" to run the script:"),ct=u(),$(ce.$$.fragment),this.h()},l(e){const n=jl('[data-svelte="svelte-1phssyn"]',document.head);f=o(n,"META",{name:!0,content:!0}),n.forEach(s),z=d(e),h=o(e,"H1",{class:!0});var pe=i(h);_=o(pe,"A",{id:!0,class:!0,href:!0});var Is=i(_);I=o(Is,"SPAN",{});var Cs=i(I);k(w.$$.fragment,Cs),Cs.forEach(s),Is.forEach(s),j=d(pe),X=o(pe,"SPAN",{});var Ds=i(X);yt=r(Ds,"Distributed inference with multiple GPUs"),Ds.forEach(s),pe.forEach(s),Se=d(e),J=o(e,"P",{});var me=i(J);wt=r(me,"On distributed setups, you can run inference across multiple GPUs with \u{1F917} "),x=o(me,"A",{href:!0,rel:!0});var zs=i(x);_t=r(zs,"Accelerate"),zs.forEach(s),bt=r(me," or "),F=o(me,"A",{href:!0,rel:!0});var Xs=i(F);Mt=r(Xs,"PyTorch Distributed"),Xs.forEach(s),Et=r(me,", which is useful for generating with multiple prompts in parallel."),me.forEach(s),Ye=d(e),ue=o(e,"P",{});var Ns=i(ue);vt=r(Ns,"This guide will show you how to use \u{1F917} Accelerate and PyTorch Distributed for distributed inference."),Ns.forEach(s),Qe=d(e),C=o(e,"H2",{class:!0});var ut=i(C);N=o(ut,"A",{id:!0,class:!0,href:!0});var Rs=i(N);be=o(Rs,"SPAN",{});var Ws=i(be);k(q.$$.fragment,Ws),Ws.forEach(s),Rs.forEach(s),jt=d(ut),Me=o(ut,"SPAN",{});var Bs=i(Me);Jt=r(Bs,"\u{1F917} Accelerate"),Bs.forEach(s),ut.forEach(s),Ve=d(e),R=o(e,"P",{});var dt=i(R);Ut=r(dt,"\u{1F917} "),O=o(dt,"A",{href:!0,rel:!0});var Ss=i(O);Tt=r(Ss,"Accelerate"),Ss.forEach(s),gt=r(dt," is a library designed to make it easy to train or run inference across distributed setups. It simplifies the process of setting up the distributed environment, allowing you to focus on your PyTorch code."),dt.forEach(s),He=d(e),m=o(e,"P",{});var v=i(m);$t=r(v,"To begin, create a Python file and initialize an "),L=o(v,"A",{href:!0,rel:!0});var Ys=i(L);kt=r(Ys,"accelerate.PartialState"),Ys.forEach(s),Pt=r(v," to create a distributed environment; your setup is automatically detected so you don\u2019t need to explicitly define the "),Ee=o(v,"CODE",{});var Qs=i(Ee);Zt=r(Qs,"rank"),Qs.forEach(s),At=r(v," or "),ve=o(v,"CODE",{});var Vs=i(ve);Gt=r(Vs,"world_size"),Vs.forEach(s),It=r(v,". Move the "),de=o(v,"A",{href:!0});var Hs=i(de);Ct=r(Hs,"DiffusionPipeline"),Hs.forEach(s),Dt=r(v," to "),je=o(v,"CODE",{});var xs=i(je);zt=r(xs,"distributed_state.device"),xs.forEach(s),Xt=r(v," to assign a GPU to each process."),v.forEach(s),xe=d(e),W=o(e,"P",{});var ft=i(W);Nt=r(ft,"Now use the "),K=o(ft,"A",{href:!0,rel:!0});var Fs=i(K);Rt=r(Fs,"split_between_processes"),Fs.forEach(s),Wt=r(ft," utility as a context manager to automatically distribute the prompts between the number of processes."),ft.forEach(s),Fe=d(e),k(ee.$$.fragment,e),qe=d(e),U=o(e,"P",{});var ye=i(U);Bt=r(ye,"Use the "),Je=o(ye,"CODE",{});var qs=i(Je);St=r(qs,"--num_processes"),qs.forEach(s),Yt=r(ye," argument to specify the number of GPUs to use, and call "),Ue=o(ye,"CODE",{});var Os=i(Ue);Qt=r(Os,"accelerate launch"),Os.forEach(s),Vt=r(ye," to run the script:"),ye.forEach(s),Oe=d(e),k(te.$$.fragment,e),Le=d(e),k(B.$$.fragment,e),Ke=d(e),D=o(e,"H2",{class:!0});var ht=i(D);S=o(ht,"A",{id:!0,class:!0,href:!0});var Ls=i(S);Te=o(Ls,"SPAN",{});var Ks=i(Te);k(se.$$.fragment,Ks),Ks.forEach(s),Ls.forEach(s),Ht=d(ht),ge=o(ht,"SPAN",{});var el=i(ge);xt=r(el,"PyTorch Distributed"),el.forEach(s),ht.forEach(s),et=d(e),Y=o(e,"P",{});var mt=i(Y);Ft=r(mt,"PyTorch supports "),le=o(mt,"A",{href:!0,rel:!0});var tl=i(le);$e=o(tl,"CODE",{});var sl=i($e);qt=r(sl,"DistributedDataParallel"),sl.forEach(s),tl.forEach(s),Ot=r(mt," which enables data parallelism."),mt.forEach(s),tt=d(e),b=o(e,"P",{});var Q=i(b);Lt=r(Q,"To start, create a Python file and import "),ke=o(Q,"CODE",{});var ll=i(ke);Kt=r(ll,"torch.distributed"),ll.forEach(s),es=r(Q," and "),Pe=o(Q,"CODE",{});var rl=i(Pe);ts=r(rl,"torch.multiprocessing"),rl.forEach(s),ss=r(Q," to set up the distributed process group and to spawn the processes for inference on each GPU. You should also initialize a "),fe=o(Q,"A",{href:!0});var al=i(fe);ls=r(al,"DiffusionPipeline"),al.forEach(s),rs=r(Q,":"),Q.forEach(s),st=d(e),k(re.$$.fragment,e),lt=d(e),y=o(e,"P",{});var g=i(y);as=r(g,"You\u2019ll want to create a function to run inference; "),ae=o(g,"A",{href:!0,rel:!0});var ol=i(ae);Ze=o(ol,"CODE",{});var il=i(Ze);os=r(il,"init_process_group"),il.forEach(s),ol.forEach(s),is=r(g," handles creating a distributed environment with the type of backend to use, the "),Ae=o(g,"CODE",{});var nl=i(Ae);ns=r(nl,"rank"),nl.forEach(s),cs=r(g," of the current process, and the "),Ge=o(g,"CODE",{});var cl=i(Ge);ps=r(cl,"world_size"),cl.forEach(s),us=r(g," or the number of processes participating. If you\u2019re running inference in parallel over 2 GPUs, then the "),Ie=o(g,"CODE",{});var pl=i(Ie);ds=r(pl,"world_size"),pl.forEach(s),fs=r(g," is 2."),g.forEach(s),rt=d(e),M=o(e,"P",{});var V=i(M);hs=r(V,"Move the "),he=o(V,"A",{href:!0});var ul=i(he);ms=r(ul,"DiffusionPipeline"),ul.forEach(s),ys=r(V," to "),Ce=o(V,"CODE",{});var dl=i(Ce);ws=r(dl,"rank"),dl.forEach(s),_s=r(V," and use "),De=o(V,"CODE",{});var fl=i(De);bs=r(fl,"get_rank"),fl.forEach(s),Ms=r(V," to assign a GPU to each process, where each process handles a different prompt:"),V.forEach(s),at=d(e),k(oe.$$.fragment,e),ot=d(e),E=o(e,"P",{});var H=i(E);Es=r(H,"To run the distributed inference, call "),ie=o(H,"A",{href:!0,rel:!0});var hl=i(ie);ze=o(hl,"CODE",{});var ml=i(ze);vs=r(ml,"mp.spawn"),ml.forEach(s),hl.forEach(s),js=r(H," to run the "),Xe=o(H,"CODE",{});var yl=i(Xe);Js=r(yl,"run_inference"),yl.forEach(s),Us=r(H," function on the number of GPUs defined in "),Ne=o(H,"CODE",{});var wl=i(Ne);Ts=r(wl,"world_size"),wl.forEach(s),gs=r(H,":"),H.forEach(s),it=d(e),k(ne.$$.fragment,e),nt=d(e),T=o(e,"P",{});var we=i(T);$s=r(we,"Once you\u2019ve completed the inference script, use the "),Re=o(we,"CODE",{});var _l=i(Re);ks=r(_l,"--nproc_per_node"),_l.forEach(s),Ps=r(we," argument to specify the number of GPUs to use and call "),We=o(we,"CODE",{});var bl=i(We);Zs=r(bl,"torchrun"),bl.forEach(s),As=r(we," to run the script:"),we.forEach(s),ct=d(e),k(ce.$$.fragment,e),this.h()},h(){p(f,"name","hf:doc:metadata"),p(f,"content",JSON.stringify($l)),p(_,"id","distributed-inference-with-multiple-gpus"),p(_,"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"),p(_,"href","#distributed-inference-with-multiple-gpus"),p(h,"class","relative group"),p(x,"href","https://huggingface.co/docs/accelerate/index"),p(x,"rel","nofollow"),p(F,"href","https://pytorch.org/tutorials/beginner/dist_overview.html"),p(F,"rel","nofollow"),p(N,"id","accelerate"),p(N,"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"),p(N,"href","#accelerate"),p(C,"class","relative group"),p(O,"href","https://huggingface.co/docs/accelerate/index"),p(O,"rel","nofollow"),p(L,"href","https://huggingface.co/docs/accelerate/v0.21.0/en/package_reference/state#accelerate.PartialState"),p(L,"rel","nofollow"),p(de,"href","/docs/diffusers/v0.20.0/en/api/pipelines/overview#diffusers.DiffusionPipeline"),p(K,"href","https://huggingface.co/docs/accelerate/v0.21.0/en/package_reference/state#accelerate.PartialState.split_between_processes"),p(K,"rel","nofollow"),p(S,"id","pytorch-distributed"),p(S,"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"),p(S,"href","#pytorch-distributed"),p(D,"class","relative group"),p(le,"href","https://pytorch.org/docs/stable/generated/torch.nn.parallel.DistributedDataParallel.html"),p(le,"rel","nofollow"),p(fe,"href","/docs/diffusers/v0.20.0/en/api/pipelines/overview#diffusers.DiffusionPipeline"),p(ae,"href","https://pytorch.org/docs/stable/distributed.html?highlight=init_process_group#torch.distributed.init_process_group"),p(ae,"rel","nofollow"),p(he,"href","/docs/diffusers/v0.20.0/en/api/pipelines/overview#diffusers.DiffusionPipeline"),p(ie,"href","https://pytorch.org/docs/stable/multiprocessing.html#torch.multiprocessing.spawn"),p(ie,"rel","nofollow")},m(e,n){t(document.head,f),c(e,z,n),c(e,h,n),t(h,_),t(_,I),P(w,I,null),t(h,j),t(h,X),t(X,yt),c(e,Se,n),c(e,J,n),t(J,wt),t(J,x),t(x,_t),t(J,bt),t(J,F),t(F,Mt),t(J,Et),c(e,Ye,n),c(e,ue,n),t(ue,vt),c(e,Qe,n),c(e,C,n),t(C,N),t(N,be),P(q,be,null),t(C,jt),t(C,Me),t(Me,Jt),c(e,Ve,n),c(e,R,n),t(R,Ut),t(R,O),t(O,Tt),t(R,gt),c(e,He,n),c(e,m,n),t(m,$t),t(m,L),t(L,kt),t(m,Pt),t(m,Ee),t(Ee,Zt),t(m,At),t(m,ve),t(ve,Gt),t(m,It),t(m,de),t(de,Ct),t(m,Dt),t(m,je),t(je,zt),t(m,Xt),c(e,xe,n),c(e,W,n),t(W,Nt),t(W,K),t(K,Rt),t(W,Wt),c(e,Fe,n),P(ee,e,n),c(e,qe,n),c(e,U,n),t(U,Bt),t(U,Je),t(Je,St),t(U,Yt),t(U,Ue),t(Ue,Qt),t(U,Vt),c(e,Oe,n),P(te,e,n),c(e,Le,n),P(B,e,n),c(e,Ke,n),c(e,D,n),t(D,S),t(S,Te),P(se,Te,null),t(D,Ht),t(D,ge),t(ge,xt),c(e,et,n),c(e,Y,n),t(Y,Ft),t(Y,le),t(le,$e),t($e,qt),t(Y,Ot),c(e,tt,n),c(e,b,n),t(b,Lt),t(b,ke),t(ke,Kt),t(b,es),t(b,Pe),t(Pe,ts),t(b,ss),t(b,fe),t(fe,ls),t(b,rs),c(e,st,n),P(re,e,n),c(e,lt,n),c(e,y,n),t(y,as),t(y,ae),t(ae,Ze),t(Ze,os),t(y,is),t(y,Ae),t(Ae,ns),t(y,cs),t(y,Ge),t(Ge,ps),t(y,us),t(y,Ie),t(Ie,ds),t(y,fs),c(e,rt,n),c(e,M,n),t(M,hs),t(M,he),t(he,ms),t(M,ys),t(M,Ce),t(Ce,ws),t(M,_s),t(M,De),t(De,bs),t(M,Ms),c(e,at,n),P(oe,e,n),c(e,ot,n),c(e,E,n),t(E,Es),t(E,ie),t(ie,ze),t(ze,vs),t(E,js),t(E,Xe),t(Xe,Js),t(E,Us),t(E,Ne),t(Ne,Ts),t(E,gs),c(e,it,n),P(ne,e,n),c(e,nt,n),c(e,T,n),t(T,$s),t(T,Re),t(Re,ks),t(T,Ps),t(T,We),t(We,Zs),t(T,As),c(e,ct,n),P(ce,e,n),pt=!0},p(e,[n]){const pe={};n&2&&(pe.$$scope={dirty:n,ctx:e}),B.$set(pe)},i(e){pt||(Z(w.$$.fragment,e),Z(q.$$.fragment,e),Z(ee.$$.fragment,e),Z(te.$$.fragment,e),Z(B.$$.fragment,e),Z(se.$$.fragment,e),Z(re.$$.fragment,e),Z(oe.$$.fragment,e),Z(ne.$$.fragment,e),Z(ce.$$.fragment,e),pt=!0)},o(e){A(w.$$.fragment,e),A(q.$$.fragment,e),A(ee.$$.fragment,e),A(te.$$.fragment,e),A(B.$$.fragment,e),A(se.$$.fragment,e),A(re.$$.fragment,e),A(oe.$$.fragment,e),A(ne.$$.fragment,e),A(ce.$$.fragment,e),pt=!1},d(e){s(f),e&&s(z),e&&s(h),G(w),e&&s(Se),e&&s(J),e&&s(Ye),e&&s(ue),e&&s(Qe),e&&s(C),G(q),e&&s(Ve),e&&s(R),e&&s(He),e&&s(m),e&&s(xe),e&&s(W),e&&s(Fe),G(ee,e),e&&s(qe),e&&s(U),e&&s(Oe),G(te,e),e&&s(Le),G(B,e),e&&s(Ke),e&&s(D),G(se),e&&s(et),e&&s(Y),e&&s(tt),e&&s(b),e&&s(st),G(re,e),e&&s(lt),e&&s(y),e&&s(rt),e&&s(M),e&&s(at),G(oe,e),e&&s(ot),e&&s(E),e&&s(it),G(ne,e),e&&s(nt),e&&s(T),e&&s(ct),G(ce,e)}}}const $l={local:"distributed-inference-with-multiple-gpus",sections:[{local:"accelerate",title:"\u{1F917} Accelerate"},{local:"pytorch-distributed",title:"PyTorch Distributed"}],title:"Distributed inference with multiple GPUs"};function kl(Be){return Jl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Il extends Ml{constructor(f){super();El(this,f,kl,gl,vl,{})}}export{Il as default,$l as metadata};
