import{s as _e,o as ge,n as F}from"../chunks/scheduler.defa9a21.js";import{S as be,i as we,g as y,s as u,r as m,A as ye,h as M,f as a,c as $,j as he,u as h,x as j,k as de,y as Me,a as c,v as d,d as _,t as g,w as b}from"../chunks/index.fe795e71.js";import{T as xe}from"../chunks/Tip.179eb360.js";import{C as X}from"../chunks/CodeBlock.204b6c34.js";import{H as le,E as ve}from"../chunks/getInferenceSnippets.2234a8dd.js";import{H as ae,a as P}from"../chunks/HfOption.3c290b0f.js";function je(w){let n,p='For standalone <code>print</code> statements that aren’t wrapped in <code>accelerator.is_local_main_process</code>, replace <code>print</code> with Accelerate’s <a href="/docs/accelerate/v1.10.1/en/package_reference/accelerator#accelerate.Accelerator.print">print()</a> method to only print once per process.';return{c(){n=y("p"),n.innerHTML=p},l(l){n=M(l,"P",{"data-svelte-h":!0}),j(n)!=="svelte-1pppgfb"&&(n.innerHTML=p)},m(l,o){c(l,n,o)},p:F,d(l){l&&a(n)}}}function Te(w){let n,p="You should use <code>accelerator.is_local_main_process</code> to indicate code that should only be executed once.",l,o,s,e,f="You could also wrap a statement with <code>accelerator.is_local_main_process</code>.",v,T,U,C,J;return o=new X({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEElMEFwcm9ncmVzc19iYXIlMjAlM0QlMjB0cWRtKHJhbmdlKGFyZ3MubWF4X3RyYWluX3N0ZXBzKSUyQyUyMGRpc2FibGUlM0Rub3QlMjBhY2NlbGVyYXRvci5pc19sb2NhbF9tYWluX3Byb2Nlc3Mp",highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm

progress_bar = tqdm(<span class="hljs-built_in">range</span>(args.max_train_steps), disable=<span class="hljs-keyword">not</span> accelerator.is_local_main_process)`,wrap:!1}}),T=new xe({props:{warning:!1,$$slots:{default:[je]},$$scope:{ctx:w}}}),C=new X({props:{code:"aWYlMjBhY2NlbGVyYXRvci5pc19sb2NhbF9tYWluX3Byb2Nlc3MlM0ElMEElMjAlMjAlMjAlMjBwcmludCglMjJBY2NlbGVyYXRlJTIwaXMlMjB0aGUlMjBiZXN0JTIyKQ==",highlighted:`<span class="hljs-keyword">if</span> accelerator.is_local_main_process:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Accelerate is the best&quot;</span>)`,wrap:!1}}),{c(){n=y("p"),n.innerHTML=p,l=u(),m(o.$$.fragment),s=u(),e=y("p"),e.innerHTML=f,v=u(),m(T.$$.fragment),U=u(),m(C.$$.fragment)},l(i){n=M(i,"P",{"data-svelte-h":!0}),j(n)!=="svelte-135otxn"&&(n.innerHTML=p),l=$(i),h(o.$$.fragment,i),s=$(i),e=M(i,"P",{"data-svelte-h":!0}),j(e)!=="svelte-4ue5fd"&&(e.innerHTML=f),v=$(i),h(T.$$.fragment,i),U=$(i),h(C.$$.fragment,i)},m(i,x){c(i,n,x),c(i,l,x),d(o,i,x),c(i,s,x),c(i,e,x),c(i,v,x),d(T,i,x),c(i,U,x),d(C,i,x),J=!0},p(i,x){const G={};x&2&&(G.$$scope={dirty:x,ctx:i}),T.$set(G)},i(i){J||(_(o.$$.fragment,i),_(T.$$.fragment,i),_(C.$$.fragment,i),J=!0)},o(i){g(o.$$.fragment,i),g(T.$$.fragment,i),g(C.$$.fragment,i),J=!1},d(i){i&&(a(n),a(l),a(s),a(e),a(v),a(U)),b(o,i),b(T,i),b(C,i)}}}function Ue(w){let n,p='For a function that should only be executed once, use <a href="/docs/accelerate/v1.10.1/en/package_reference/accelerator#accelerate.Accelerator.on_local_main_process">on_local_main_process()</a>.',l,o,s;return o=new X({props:{code:"JTQwYWNjZWxlcmF0b3Iub25fbG9jYWxfbWFpbl9wcm9jZXNzJTBBZGVmJTIwZG9fbXlfdGhpbmcoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMlNvbWV0aGluZyUyMGRvbmUlMjBvbmNlJTIwcGVyJTIwc2VydmVyJTIyJTBBJTIwJTIwJTIwJTIwZG9fdGhpbmdfb25jZV9wZXJfc2VydmVyKCk=",highlighted:`<span class="hljs-meta">@accelerator.on_local_main_process</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">do_my_thing</span>():
    <span class="hljs-string">&quot;Something done once per server&quot;</span>
    do_thing_once_per_server()`,wrap:!1}}),{c(){n=y("p"),n.innerHTML=p,l=u(),m(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-18u7yti"&&(n.innerHTML=p),l=$(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,l,f),d(o,e,f),s=!0},p:F,i(e){s||(_(o.$$.fragment,e),s=!0)},o(e){g(o.$$.fragment,e),s=!1},d(e){e&&(a(n),a(l)),b(o,e)}}}function Ce(w){let n,p,l,o;return n=new P({props:{id:"local-execution",option:"statements",$$slots:{default:[Te]},$$scope:{ctx:w}}}),l=new P({props:{id:"local-execution",option:"function",$$slots:{default:[Ue]},$$scope:{ctx:w}}}),{c(){m(n.$$.fragment),p=u(),m(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=$(s),h(l.$$.fragment,s)},m(s,e){d(n,s,e),c(s,p,e),d(l,s,e),o=!0},p(s,e){const f={};e&2&&(f.$$scope={dirty:e,ctx:s}),n.$set(f);const v={};e&2&&(v.$$scope={dirty:e,ctx:s}),l.$set(v)},i(s){o||(_(n.$$.fragment,s),_(l.$$.fragment,s),o=!0)},o(s){g(n.$$.fragment,s),g(l.$$.fragment,s),o=!1},d(s){s&&a(p),b(n,s),b(l,s)}}}function Ge(w){let n,p="You should use <code>accelerator.is_main_process</code> to indicate code that should only be executed once across all processes.",l,o,s;return o=new X({props:{code:"aWYlMjBhY2NlbGVyYXRvci5pc19tYWluX3Byb2Nlc3MlM0ElMEElMjAlMjAlMjAlMjByZXBvLnB1c2hfdG9faHViKCk=",highlighted:`<span class="hljs-keyword">if</span> accelerator.is_main_process:
    repo.push_to_hub()`,wrap:!1}}),{c(){n=y("p"),n.innerHTML=p,l=u(),m(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-qoo748"&&(n.innerHTML=p),l=$(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,l,f),d(o,e,f),s=!0},p:F,i(e){s||(_(o.$$.fragment,e),s=!0)},o(e){g(o.$$.fragment,e),s=!1},d(e){e&&(a(n),a(l)),b(o,e)}}}function Je(w){let n,p='For a function that should only be executed once across all processes, use <a href="/docs/accelerate/v1.10.1/en/package_reference/accelerator#accelerate.Accelerator.on_main_process">on_main_process()</a>.',l,o,s;return o=new X({props:{code:"JTQwYWNjZWxlcmF0b3Iub25fbWFpbl9wcm9jZXNzJTBBZGVmJTIwZG9fbXlfdGhpbmcoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMlNvbWV0aGluZyUyMGRvbmUlMjBvbmNlJTIwcGVyJTIwc2VydmVyJTIyJTBBJTIwJTIwJTIwJTIwZG9fdGhpbmdfb25jZSgp",highlighted:`<span class="hljs-meta">@accelerator.on_main_process</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">do_my_thing</span>():
    <span class="hljs-string">&quot;Something done once per server&quot;</span>
    do_thing_once()`,wrap:!1}}),{c(){n=y("p"),n.innerHTML=p,l=u(),m(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-96r5hb"&&(n.innerHTML=p),l=$(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,l,f),d(o,e,f),s=!0},p:F,i(e){s||(_(o.$$.fragment,e),s=!0)},o(e){g(o.$$.fragment,e),s=!1},d(e){e&&(a(n),a(l)),b(o,e)}}}function Ze(w){let n,p,l,o;return n=new P({props:{id:"main-execution",option:"statement",$$slots:{default:[Ge]},$$scope:{ctx:w}}}),l=new P({props:{id:"main-execution",option:"function",$$slots:{default:[Je]},$$scope:{ctx:w}}}),{c(){m(n.$$.fragment),p=u(),m(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=$(s),h(l.$$.fragment,s)},m(s,e){d(n,s,e),c(s,p,e),d(l,s,e),o=!0},p(s,e){const f={};e&2&&(f.$$scope={dirty:e,ctx:s}),n.$set(f);const v={};e&2&&(v.$$scope={dirty:e,ctx:s}),l.$set(v)},i(s){o||(_(n.$$.fragment,s),_(l.$$.fragment,s),o=!0)},o(s){g(n.$$.fragment,s),g(l.$$.fragment,s),o=!1},d(s){s&&a(p),b(n,s),b(l,s)}}}function ke(w){let n,p='Use the <a href="/docs/accelerate/v1.10.1/en/package_reference/accelerator#accelerate.Accelerator.on_process">on_process()</a> method and specify the process index to execute a function on.',l,o,s;return o=new X({props:{code:"JTQwYWNjZWxlcmF0b3Iub25fcHJvY2Vzcyhwcm9jZXNzX2luZGV4JTNEMCklMEFkZWYlMjBkb19teV90aGluZygpJTNBJTBBJTIwJTIwJTIwJTIwJTIyU29tZXRoaW5nJTIwZG9uZSUyMG9uJTIwcHJvY2VzcyUyMGluZGV4JTIwMCUyMiUwQSUyMCUyMCUyMCUyMGRvX3RoaW5nX29uX2luZGV4X3plcm8oKQ==",highlighted:`<span class="hljs-meta">@accelerator.on_process(<span class="hljs-params">process_index=<span class="hljs-number">0</span></span>)</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">do_my_thing</span>():
    <span class="hljs-string">&quot;Something done on process index 0&quot;</span>
    do_thing_on_index_zero()`,wrap:!1}}),{c(){n=y("p"),n.innerHTML=p,l=u(),m(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-1x5hhab"&&(n.innerHTML=p),l=$(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,l,f),d(o,e,f),s=!0},p:F,i(e){s||(_(o.$$.fragment,e),s=!0)},o(e){g(o.$$.fragment,e),s=!1},d(e){e&&(a(n),a(l)),b(o,e)}}}function Be(w){let n,p='Use the <a href="/docs/accelerate/v1.10.1/en/package_reference/accelerator#accelerate.Accelerator.on_local_process">on_local_process()</a> method and specify the local process index to execute a function on.',l,o,s;return o=new X({props:{code:"JTQwYWNjZWxlcmF0b3Iub25fbG9jYWxfcHJvY2Vzcyhsb2NhbF9wcm9jZXNzX2lkeCUzRDApJTBBZGVmJTIwZG9fbXlfdGhpbmcoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMlNvbWV0aGluZyUyMGRvbmUlMjBvbiUyMHByb2Nlc3MlMjBpbmRleCUyMDAlMjBvbiUyMGVhY2glMjBzZXJ2ZXIlMjIlMEElMjAlMjAlMjAlMjBkb190aGluZ19vbl9pbmRleF96ZXJvX29uX2VhY2hfc2VydmVyKCk=",highlighted:`<span class="hljs-meta">@accelerator.on_local_process(<span class="hljs-params">local_process_idx=<span class="hljs-number">0</span></span>)</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">do_my_thing</span>():
    <span class="hljs-string">&quot;Something done on process index 0 on each server&quot;</span>
    do_thing_on_index_zero_on_each_server()`,wrap:!1}}),{c(){n=y("p"),n.innerHTML=p,l=u(),m(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-rh25ym"&&(n.innerHTML=p),l=$(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,l,f),d(o,e,f),s=!0},p:F,i(e){s||(_(o.$$.fragment,e),s=!0)},o(e){g(o.$$.fragment,e),s=!1},d(e){e&&(a(n),a(l)),b(o,e)}}}function Xe(w){let n,p,l,o;return n=new P({props:{id:"specific-execution",option:"specific process",$$slots:{default:[ke]},$$scope:{ctx:w}}}),l=new P({props:{id:"specific-execution",option:"local process",$$slots:{default:[Be]},$$scope:{ctx:w}}}),{c(){m(n.$$.fragment),p=u(),m(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=$(s),h(l.$$.fragment,s)},m(s,e){d(n,s,e),c(s,p,e),d(l,s,e),o=!0},p(s,e){const f={};e&2&&(f.$$scope={dirty:e,ctx:s}),n.$set(f);const v={};e&2&&(v.$$scope={dirty:e,ctx:s}),l.$set(v)},i(s){o||(_(n.$$.fragment,s),_(l.$$.fragment,s),o=!0)},o(s){g(n.$$.fragment,s),g(l.$$.fragment,s),o=!1},d(s){s&&a(p),b(n,s),b(l,s)}}}function Ie(w){let n,p,l,o,s,e,f,v="When working with distributed training systems, it is important to manage how and when processes are executed across GPUs. Some processes are completed faster than others, and some processes shouldn’t begin if others haven’t finished yet. Accelerate provides tools for orchestrating when processes are executed to ensure everything remains synchronized across all devices.",T,U,C="This tutorial will teach you how to execute a process on only one machine and how to delay execution until all processes have reached a certain point.",J,i,x,G,ce="Certain code only needs to be run once on a given machine, such as printing a log statement or only displaying one progress bar on the local main process.",S,Z,R,I,re="You could also direct Accelerate to execute code once across <em>all processes</em> regardless of the number of machines. This is useful if you’re uploading a final model to the Hub.",z,k,Q,H,q,Y,ie="Accelerate can also help you execute functions that should only be executed on a specific process or a local process index.",K,B,D,V,O,W,pe="When you run your script on several GPUs at the same time, some code may be executed faster than others. You might need to wait for all processes to reach a certain point before executing the next set of instructions. For instance, you shouldn’t save a model before making sure every process is done with training.",ee,N,fe='To do this, add <a href="/docs/accelerate/v1.10.1/en/package_reference/accelerator#accelerate.Accelerator.wait_for_everyone">wait_for_everyone()</a> in your code. This blocks all processes that have finished first from continuing until all remaining processes have reached the same point (this has no effect if you’re running on a single GPU or CPU).',te,A,se,E,ne,L,oe;return s=new le({props:{title:"Execution process",local:"execution-process",headingTag:"h1"}}),i=new le({props:{title:"Execute on one process",local:"execute-on-one-process",headingTag:"h2"}}),Z=new ae({props:{id:"local-execution",options:["statements","function"],$$slots:{default:[Ce]},$$scope:{ctx:w}}}),k=new ae({props:{id:"main-execution",options:["statement","function"],$$slots:{default:[Ze]},$$scope:{ctx:w}}}),H=new le({props:{title:"Execute on a specific process",local:"execute-on-a-specific-process",headingTag:"h2"}}),B=new ae({props:{id:"specific-execution",options:["specific process","local process"],$$slots:{default:[Xe]},$$scope:{ctx:w}}}),V=new le({props:{title:"Defer execution",local:"defer-execution",headingTag:"h2"}}),A=new X({props:{code:"YWNjZWxlcmF0b3Iud2FpdF9mb3JfZXZlcnlvbmUoKQ==",highlighted:"accelerator.wait_for_everyone()",wrap:!1}}),E=new ve({props:{source:"https://github.com/huggingface/accelerate/blob/main/docs/source/basic_tutorials/execution.md"}}),{c(){n=y("meta"),p=u(),l=y("p"),o=u(),m(s.$$.fragment),e=u(),f=y("p"),f.textContent=v,T=u(),U=y("p"),U.textContent=C,J=u(),m(i.$$.fragment),x=u(),G=y("p"),G.textContent=ce,S=u(),m(Z.$$.fragment),R=u(),I=y("p"),I.innerHTML=re,z=u(),m(k.$$.fragment),Q=u(),m(H.$$.fragment),q=u(),Y=y("p"),Y.textContent=ie,K=u(),m(B.$$.fragment),D=u(),m(V.$$.fragment),O=u(),W=y("p"),W.textContent=pe,ee=u(),N=y("p"),N.innerHTML=fe,te=u(),m(A.$$.fragment),se=u(),m(E.$$.fragment),ne=u(),L=y("p"),this.h()},l(t){const r=ye("svelte-u9bgzb",document.head);n=M(r,"META",{name:!0,content:!0}),r.forEach(a),p=$(t),l=M(t,"P",{}),he(l).forEach(a),o=$(t),h(s.$$.fragment,t),e=$(t),f=M(t,"P",{"data-svelte-h":!0}),j(f)!=="svelte-1p9ts9j"&&(f.textContent=v),T=$(t),U=M(t,"P",{"data-svelte-h":!0}),j(U)!=="svelte-k803ca"&&(U.textContent=C),J=$(t),h(i.$$.fragment,t),x=$(t),G=M(t,"P",{"data-svelte-h":!0}),j(G)!=="svelte-40xkhe"&&(G.textContent=ce),S=$(t),h(Z.$$.fragment,t),R=$(t),I=M(t,"P",{"data-svelte-h":!0}),j(I)!=="svelte-bduond"&&(I.innerHTML=re),z=$(t),h(k.$$.fragment,t),Q=$(t),h(H.$$.fragment,t),q=$(t),Y=M(t,"P",{"data-svelte-h":!0}),j(Y)!=="svelte-uxugml"&&(Y.textContent=ie),K=$(t),h(B.$$.fragment,t),D=$(t),h(V.$$.fragment,t),O=$(t),W=M(t,"P",{"data-svelte-h":!0}),j(W)!=="svelte-czwo4s"&&(W.textContent=pe),ee=$(t),N=M(t,"P",{"data-svelte-h":!0}),j(N)!=="svelte-nvrmdr"&&(N.innerHTML=fe),te=$(t),h(A.$$.fragment,t),se=$(t),h(E.$$.fragment,t),ne=$(t),L=M(t,"P",{}),he(L).forEach(a),this.h()},h(){de(n,"name","hf:doc:metadata"),de(n,"content",He)},m(t,r){Me(document.head,n),c(t,p,r),c(t,l,r),c(t,o,r),d(s,t,r),c(t,e,r),c(t,f,r),c(t,T,r),c(t,U,r),c(t,J,r),d(i,t,r),c(t,x,r),c(t,G,r),c(t,S,r),d(Z,t,r),c(t,R,r),c(t,I,r),c(t,z,r),d(k,t,r),c(t,Q,r),d(H,t,r),c(t,q,r),c(t,Y,r),c(t,K,r),d(B,t,r),c(t,D,r),d(V,t,r),c(t,O,r),c(t,W,r),c(t,ee,r),c(t,N,r),c(t,te,r),d(A,t,r),c(t,se,r),d(E,t,r),c(t,ne,r),c(t,L,r),oe=!0},p(t,[r]){const ue={};r&2&&(ue.$$scope={dirty:r,ctx:t}),Z.$set(ue);const $e={};r&2&&($e.$$scope={dirty:r,ctx:t}),k.$set($e);const me={};r&2&&(me.$$scope={dirty:r,ctx:t}),B.$set(me)},i(t){oe||(_(s.$$.fragment,t),_(i.$$.fragment,t),_(Z.$$.fragment,t),_(k.$$.fragment,t),_(H.$$.fragment,t),_(B.$$.fragment,t),_(V.$$.fragment,t),_(A.$$.fragment,t),_(E.$$.fragment,t),oe=!0)},o(t){g(s.$$.fragment,t),g(i.$$.fragment,t),g(Z.$$.fragment,t),g(k.$$.fragment,t),g(H.$$.fragment,t),g(B.$$.fragment,t),g(V.$$.fragment,t),g(A.$$.fragment,t),g(E.$$.fragment,t),oe=!1},d(t){t&&(a(p),a(l),a(o),a(e),a(f),a(T),a(U),a(J),a(x),a(G),a(S),a(R),a(I),a(z),a(Q),a(q),a(Y),a(K),a(D),a(O),a(W),a(ee),a(N),a(te),a(se),a(ne),a(L)),a(n),b(s,t),b(i,t),b(Z,t),b(k,t),b(H,t),b(B,t),b(V,t),b(A,t),b(E,t)}}}const He='{"title":"Execution process","local":"execution-process","sections":[{"title":"Execute on one process","local":"execute-on-one-process","sections":[],"depth":2},{"title":"Execute on a specific process","local":"execute-on-a-specific-process","sections":[],"depth":2},{"title":"Defer execution","local":"defer-execution","sections":[],"depth":2}],"depth":1}';function Ye(w){return ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Fe extends be{constructor(n){super(),we(this,n,Ye,Ie,_e,{})}}export{Fe as component};
