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 $,A as ye,h as M,f as l,c as m,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 ae,E as ve}from"../chunks/getInferenceSnippets.2234a8dd.js";import{H as le,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/main/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(a){n=M(a,"P",{"data-svelte-h":!0}),j(n)!=="svelte-vnug7f"&&(n.innerHTML=p)},m(a,o){c(a,n,o)},p:F,d(a){a&&l(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.",a,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,a=u(),$(o.$$.fragment),s=u(),e=y("p"),e.innerHTML=f,v=u(),$(T.$$.fragment),U=u(),$(C.$$.fragment)},l(i){n=M(i,"P",{"data-svelte-h":!0}),j(n)!=="svelte-135otxn"&&(n.innerHTML=p),a=m(i),h(o.$$.fragment,i),s=m(i),e=M(i,"P",{"data-svelte-h":!0}),j(e)!=="svelte-4ue5fd"&&(e.innerHTML=f),v=m(i),h(T.$$.fragment,i),U=m(i),h(C.$$.fragment,i)},m(i,x){c(i,n,x),c(i,a,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&&(l(n),l(a),l(s),l(e),l(v),l(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/main/en/package_reference/accelerator#accelerate.Accelerator.on_local_main_process">on_local_main_process()</a>.',a,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,a=u(),$(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-n94yrq"&&(n.innerHTML=p),a=m(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,a,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&&(l(n),l(a)),b(o,e)}}}function Ce(w){let n,p,a,o;return n=new P({props:{id:"local-execution",option:"statements",$$slots:{default:[Te]},$$scope:{ctx:w}}}),a=new P({props:{id:"local-execution",option:"function",$$slots:{default:[Ue]},$$scope:{ctx:w}}}),{c(){$(n.$$.fragment),p=u(),$(a.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(a.$$.fragment,s)},m(s,e){d(n,s,e),c(s,p,e),d(a,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}),a.$set(v)},i(s){o||(_(n.$$.fragment,s),_(a.$$.fragment,s),o=!0)},o(s){g(n.$$.fragment,s),g(a.$$.fragment,s),o=!1},d(s){s&&l(p),b(n,s),b(a,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.",a,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,a=u(),$(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-qoo748"&&(n.innerHTML=p),a=m(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,a,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&&(l(n),l(a)),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/main/en/package_reference/accelerator#accelerate.Accelerator.on_main_process">on_main_process()</a>.',a,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,a=u(),$(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-11igt8f"&&(n.innerHTML=p),a=m(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,a,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&&(l(n),l(a)),b(o,e)}}}function Ze(w){let n,p,a,o;return n=new P({props:{id:"main-execution",option:"statement",$$slots:{default:[Ge]},$$scope:{ctx:w}}}),a=new P({props:{id:"main-execution",option:"function",$$slots:{default:[Je]},$$scope:{ctx:w}}}),{c(){$(n.$$.fragment),p=u(),$(a.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(a.$$.fragment,s)},m(s,e){d(n,s,e),c(s,p,e),d(a,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}),a.$set(v)},i(s){o||(_(n.$$.fragment,s),_(a.$$.fragment,s),o=!0)},o(s){g(n.$$.fragment,s),g(a.$$.fragment,s),o=!1},d(s){s&&l(p),b(n,s),b(a,s)}}}function ke(w){let n,p='Use the <a href="/docs/accelerate/main/en/package_reference/accelerator#accelerate.Accelerator.on_process">on_process()</a> method and specify the process index to execute a function on.',a,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,a=u(),$(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-kmf00x"&&(n.innerHTML=p),a=m(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,a,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&&(l(n),l(a)),b(o,e)}}}function Be(w){let n,p='Use the <a href="/docs/accelerate/main/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.',a,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,a=u(),$(o.$$.fragment)},l(e){n=M(e,"P",{"data-svelte-h":!0}),j(n)!=="svelte-154foa6"&&(n.innerHTML=p),a=m(e),h(o.$$.fragment,e)},m(e,f){c(e,n,f),c(e,a,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&&(l(n),l(a)),b(o,e)}}}function Xe(w){let n,p,a,o;return n=new P({props:{id:"specific-execution",option:"specific process",$$slots:{default:[ke]},$$scope:{ctx:w}}}),a=new P({props:{id:"specific-execution",option:"local process",$$slots:{default:[Be]},$$scope:{ctx:w}}}),{c(){$(n.$$.fragment),p=u(),$(a.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(a.$$.fragment,s)},m(s,e){d(n,s,e),c(s,p,e),d(a,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}),a.$set(v)},i(s){o||(_(n.$$.fragment,s),_(a.$$.fragment,s),o=!0)},o(s){g(n.$$.fragment,s),g(a.$$.fragment,s),o=!1},d(s){s&&l(p),b(n,s),b(a,s)}}}function Ie(w){let n,p,a,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,z,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.",R,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/main/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 ae({props:{title:"Execution process",local:"execution-process",headingTag:"h1"}}),i=new ae({props:{title:"Execute on one process",local:"execute-on-one-process",headingTag:"h2"}}),Z=new le({props:{id:"local-execution",options:["statements","function"],$$slots:{default:[Ce]},$$scope:{ctx:w}}}),k=new le({props:{id:"main-execution",options:["statement","function"],$$slots:{default:[Ze]},$$scope:{ctx:w}}}),H=new ae({props:{title:"Execute on a specific process",local:"execute-on-a-specific-process",headingTag:"h2"}}),B=new le({props:{id:"specific-execution",options:["specific process","local process"],$$slots:{default:[Xe]},$$scope:{ctx:w}}}),V=new ae({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(),a=y("p"),o=u(),$(s.$$.fragment),e=u(),f=y("p"),f.textContent=v,T=u(),U=y("p"),U.textContent=C,J=u(),$(i.$$.fragment),x=u(),G=y("p"),G.textContent=ce,S=u(),$(Z.$$.fragment),z=u(),I=y("p"),I.innerHTML=re,R=u(),$(k.$$.fragment),Q=u(),$(H.$$.fragment),q=u(),Y=y("p"),Y.textContent=ie,K=u(),$(B.$$.fragment),D=u(),$(V.$$.fragment),O=u(),W=y("p"),W.textContent=pe,ee=u(),N=y("p"),N.innerHTML=fe,te=u(),$(A.$$.fragment),se=u(),$(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(l),p=m(t),a=M(t,"P",{}),he(a).forEach(l),o=m(t),h(s.$$.fragment,t),e=m(t),f=M(t,"P",{"data-svelte-h":!0}),j(f)!=="svelte-1p9ts9j"&&(f.textContent=v),T=m(t),U=M(t,"P",{"data-svelte-h":!0}),j(U)!=="svelte-k803ca"&&(U.textContent=C),J=m(t),h(i.$$.fragment,t),x=m(t),G=M(t,"P",{"data-svelte-h":!0}),j(G)!=="svelte-40xkhe"&&(G.textContent=ce),S=m(t),h(Z.$$.fragment,t),z=m(t),I=M(t,"P",{"data-svelte-h":!0}),j(I)!=="svelte-bduond"&&(I.innerHTML=re),R=m(t),h(k.$$.fragment,t),Q=m(t),h(H.$$.fragment,t),q=m(t),Y=M(t,"P",{"data-svelte-h":!0}),j(Y)!=="svelte-uxugml"&&(Y.textContent=ie),K=m(t),h(B.$$.fragment,t),D=m(t),h(V.$$.fragment,t),O=m(t),W=M(t,"P",{"data-svelte-h":!0}),j(W)!=="svelte-czwo4s"&&(W.textContent=pe),ee=m(t),N=M(t,"P",{"data-svelte-h":!0}),j(N)!=="svelte-11izu7j"&&(N.innerHTML=fe),te=m(t),h(A.$$.fragment,t),se=m(t),h(E.$$.fragment,t),ne=m(t),L=M(t,"P",{}),he(L).forEach(l),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,a,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,z,r),c(t,I,r),c(t,R,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 me={};r&2&&(me.$$scope={dirty:r,ctx:t}),k.$set(me);const $e={};r&2&&($e.$$scope={dirty:r,ctx:t}),B.$set($e)},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&&(l(p),l(a),l(o),l(e),l(f),l(T),l(U),l(J),l(x),l(G),l(S),l(z),l(I),l(R),l(Q),l(q),l(Y),l(K),l(D),l(O),l(W),l(ee),l(N),l(te),l(se),l(ne),l(L)),l(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};
