import{s as ye,o as be,n as P}from"../chunks/scheduler.b9285784.js";import{S as Me,i as we,e as w,s as u,c as $,h as xe,a as x,d as a,b as m,f as ge,g as h,j as C,k as ie,l as ve,m as r,n as d,t as _,o as g,p as y}from"../chunks/index.26bc89a1.js";import{C as je,H as ce,E as Te}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.e364eac2.js";import{C as k}from"../chunks/CodeBlock.804615c8.js";import{H as re,a as A}from"../chunks/HfOption.76c7ca3e.js";function Ce(b){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,t,i="You could also wrap a statement with <code>accelerator.is_local_main_process</code>.",M,j,S='<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.</p>',U,T,B;return o=new k({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 k({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=w("p"),n.innerHTML=p,l=u(),$(o.$$.fragment),s=u(),t=w("p"),t.innerHTML=i,M=u(),j=w("blockquote"),j.innerHTML=S,U=u(),$(T.$$.fragment),this.h()},l(f){n=x(f,"P",{"data-svelte-h":!0}),C(n)!=="svelte-135otxn"&&(n.innerHTML=p),l=m(f),h(o.$$.fragment,f),s=m(f),t=x(f,"P",{"data-svelte-h":!0}),C(t)!=="svelte-4ue5fd"&&(t.innerHTML=i),M=m(f),j=x(f,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),C(j)!=="svelte-1jytl10"&&(j.innerHTML=S),U=m(f),h(T.$$.fragment,f),this.h()},h(){ie(j,"class","tip")},m(f,v){r(f,n,v),r(f,l,v),d(o,f,v),r(f,s,v),r(f,t,v),r(f,M,v),r(f,j,v),r(f,U,v),d(T,f,v),B=!0},p:P,i(f){B||(_(o.$$.fragment,f),_(T.$$.fragment,f),B=!0)},o(f){g(o.$$.fragment,f),g(T.$$.fragment,f),B=!1},d(f){f&&(a(n),a(l),a(s),a(t),a(M),a(j),a(U)),y(o,f),y(T,f)}}}function Ue(b){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>.',l,o,s;return o=new k({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=w("p"),n.innerHTML=p,l=u(),$(o.$$.fragment)},l(t){n=x(t,"P",{"data-svelte-h":!0}),C(n)!=="svelte-n94yrq"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),d(o,t,i),s=!0},p:P,i(t){s||(_(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),y(o,t)}}}function Ge(b){let n,p,l,o;return n=new A({props:{id:"local-execution",option:"statements",$$slots:{default:[Ce]},$$scope:{ctx:b}}}),l=new A({props:{id:"local-execution",option:"function",$$slots:{default:[Ue]},$$scope:{ctx:b}}}),{c(){$(n.$$.fragment),p=u(),$(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(l.$$.fragment,s)},m(s,t){d(n,s,t),r(s,p,t),d(l,s,t),o=!0},p(s,t){const i={};t&2&&(i.$$scope={dirty:t,ctx:s}),n.$set(i);const M={};t&2&&(M.$$scope={dirty:t,ctx:s}),l.$set(M)},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),y(n,s),y(l,s)}}}function Je(b){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 k({props:{code:"aWYlMjBhY2NlbGVyYXRvci5pc19tYWluX3Byb2Nlc3MlM0ElMEElMjAlMjAlMjAlMjByZXBvLnB1c2hfdG9faHViKCk=",highlighted:`<span class="hljs-keyword">if</span> accelerator.is_main_process:
    repo.push_to_hub()`,wrap:!1}}),{c(){n=w("p"),n.innerHTML=p,l=u(),$(o.$$.fragment)},l(t){n=x(t,"P",{"data-svelte-h":!0}),C(n)!=="svelte-qoo748"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),d(o,t,i),s=!0},p:P,i(t){s||(_(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),y(o,t)}}}function Ze(b){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>.',l,o,s;return o=new k({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=w("p"),n.innerHTML=p,l=u(),$(o.$$.fragment)},l(t){n=x(t,"P",{"data-svelte-h":!0}),C(n)!=="svelte-11igt8f"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),d(o,t,i),s=!0},p:P,i(t){s||(_(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),y(o,t)}}}function ke(b){let n,p,l,o;return n=new A({props:{id:"main-execution",option:"statement",$$slots:{default:[Je]},$$scope:{ctx:b}}}),l=new A({props:{id:"main-execution",option:"function",$$slots:{default:[Ze]},$$scope:{ctx:b}}}),{c(){$(n.$$.fragment),p=u(),$(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(l.$$.fragment,s)},m(s,t){d(n,s,t),r(s,p,t),d(l,s,t),o=!0},p(s,t){const i={};t&2&&(i.$$scope={dirty:t,ctx:s}),n.$set(i);const M={};t&2&&(M.$$scope={dirty:t,ctx:s}),l.$set(M)},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),y(n,s),y(l,s)}}}function Be(b){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.',l,o,s;return o=new k({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=w("p"),n.innerHTML=p,l=u(),$(o.$$.fragment)},l(t){n=x(t,"P",{"data-svelte-h":!0}),C(n)!=="svelte-kmf00x"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),d(o,t,i),s=!0},p:P,i(t){s||(_(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),y(o,t)}}}function Xe(b){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.',l,o,s;return o=new k({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=w("p"),n.innerHTML=p,l=u(),$(o.$$.fragment)},l(t){n=x(t,"P",{"data-svelte-h":!0}),C(n)!=="svelte-154foa6"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),d(o,t,i),s=!0},p:P,i(t){s||(_(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),y(o,t)}}}function Ie(b){let n,p,l,o;return n=new A({props:{id:"specific-execution",option:"specific process",$$slots:{default:[Be]},$$scope:{ctx:b}}}),l=new A({props:{id:"specific-execution",option:"local process",$$slots:{default:[Xe]},$$scope:{ctx:b}}}),{c(){$(n.$$.fragment),p=u(),$(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(l.$$.fragment,s)},m(s,t){d(n,s,t),r(s,p,t),d(l,s,t),o=!0},p(s,t){const i={};t&2&&(i.$$scope={dirty:t,ctx:s}),n.$set(i);const M={};t&2&&(M.$$scope={dirty:t,ctx:s}),l.$set(M)},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),y(n,s),y(l,s)}}}function He(b){let n,p,l,o,s,t,i,M,j,S="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.",U,T,B="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.",f,v,z,X,pe="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.",R,G,q,I,fe="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.",Q,J,K,H,O,Y,ue="Accelerate can also help you execute functions that should only be executed on a specific process or a local process index.",D,Z,ee,V,te,W,me="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.",se,N,$e='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).',ne,E,oe,L,le,F,ae;return s=new je({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),i=new ce({props:{title:"Execution process",local:"execution-process",headingTag:"h1"}}),v=new ce({props:{title:"Execute on one process",local:"execute-on-one-process",headingTag:"h2"}}),G=new re({props:{id:"local-execution",options:["statements","function"],$$slots:{default:[Ge]},$$scope:{ctx:b}}}),J=new re({props:{id:"main-execution",options:["statement","function"],$$slots:{default:[ke]},$$scope:{ctx:b}}}),H=new ce({props:{title:"Execute on a specific process",local:"execute-on-a-specific-process",headingTag:"h2"}}),Z=new re({props:{id:"specific-execution",options:["specific process","local process"],$$slots:{default:[Ie]},$$scope:{ctx:b}}}),V=new ce({props:{title:"Defer execution",local:"defer-execution",headingTag:"h2"}}),E=new k({props:{code:"YWNjZWxlcmF0b3Iud2FpdF9mb3JfZXZlcnlvbmUoKQ==",highlighted:"accelerator.wait_for_everyone()",wrap:!1}}),L=new Te({props:{source:"https://github.com/huggingface/accelerate/blob/main/docs/source/basic_tutorials/execution.md"}}),{c(){n=w("meta"),p=u(),l=w("p"),o=u(),$(s.$$.fragment),t=u(),$(i.$$.fragment),M=u(),j=w("p"),j.textContent=S,U=u(),T=w("p"),T.textContent=B,f=u(),$(v.$$.fragment),z=u(),X=w("p"),X.textContent=pe,R=u(),$(G.$$.fragment),q=u(),I=w("p"),I.innerHTML=fe,Q=u(),$(J.$$.fragment),K=u(),$(H.$$.fragment),O=u(),Y=w("p"),Y.textContent=ue,D=u(),$(Z.$$.fragment),ee=u(),$(V.$$.fragment),te=u(),W=w("p"),W.textContent=me,se=u(),N=w("p"),N.innerHTML=$e,ne=u(),$(E.$$.fragment),oe=u(),$(L.$$.fragment),le=u(),F=w("p"),this.h()},l(e){const c=xe("svelte-u9bgzb",document.head);n=x(c,"META",{name:!0,content:!0}),c.forEach(a),p=m(e),l=x(e,"P",{}),ge(l).forEach(a),o=m(e),h(s.$$.fragment,e),t=m(e),h(i.$$.fragment,e),M=m(e),j=x(e,"P",{"data-svelte-h":!0}),C(j)!=="svelte-1p9ts9j"&&(j.textContent=S),U=m(e),T=x(e,"P",{"data-svelte-h":!0}),C(T)!=="svelte-k803ca"&&(T.textContent=B),f=m(e),h(v.$$.fragment,e),z=m(e),X=x(e,"P",{"data-svelte-h":!0}),C(X)!=="svelte-40xkhe"&&(X.textContent=pe),R=m(e),h(G.$$.fragment,e),q=m(e),I=x(e,"P",{"data-svelte-h":!0}),C(I)!=="svelte-bduond"&&(I.innerHTML=fe),Q=m(e),h(J.$$.fragment,e),K=m(e),h(H.$$.fragment,e),O=m(e),Y=x(e,"P",{"data-svelte-h":!0}),C(Y)!=="svelte-uxugml"&&(Y.textContent=ue),D=m(e),h(Z.$$.fragment,e),ee=m(e),h(V.$$.fragment,e),te=m(e),W=x(e,"P",{"data-svelte-h":!0}),C(W)!=="svelte-czwo4s"&&(W.textContent=me),se=m(e),N=x(e,"P",{"data-svelte-h":!0}),C(N)!=="svelte-11izu7j"&&(N.innerHTML=$e),ne=m(e),h(E.$$.fragment,e),oe=m(e),h(L.$$.fragment,e),le=m(e),F=x(e,"P",{}),ge(F).forEach(a),this.h()},h(){ie(n,"name","hf:doc:metadata"),ie(n,"content",Ye)},m(e,c){ve(document.head,n),r(e,p,c),r(e,l,c),r(e,o,c),d(s,e,c),r(e,t,c),d(i,e,c),r(e,M,c),r(e,j,c),r(e,U,c),r(e,T,c),r(e,f,c),d(v,e,c),r(e,z,c),r(e,X,c),r(e,R,c),d(G,e,c),r(e,q,c),r(e,I,c),r(e,Q,c),d(J,e,c),r(e,K,c),d(H,e,c),r(e,O,c),r(e,Y,c),r(e,D,c),d(Z,e,c),r(e,ee,c),d(V,e,c),r(e,te,c),r(e,W,c),r(e,se,c),r(e,N,c),r(e,ne,c),d(E,e,c),r(e,oe,c),d(L,e,c),r(e,le,c),r(e,F,c),ae=!0},p(e,[c]){const he={};c&2&&(he.$$scope={dirty:c,ctx:e}),G.$set(he);const de={};c&2&&(de.$$scope={dirty:c,ctx:e}),J.$set(de);const _e={};c&2&&(_e.$$scope={dirty:c,ctx:e}),Z.$set(_e)},i(e){ae||(_(s.$$.fragment,e),_(i.$$.fragment,e),_(v.$$.fragment,e),_(G.$$.fragment,e),_(J.$$.fragment,e),_(H.$$.fragment,e),_(Z.$$.fragment,e),_(V.$$.fragment,e),_(E.$$.fragment,e),_(L.$$.fragment,e),ae=!0)},o(e){g(s.$$.fragment,e),g(i.$$.fragment,e),g(v.$$.fragment,e),g(G.$$.fragment,e),g(J.$$.fragment,e),g(H.$$.fragment,e),g(Z.$$.fragment,e),g(V.$$.fragment,e),g(E.$$.fragment,e),g(L.$$.fragment,e),ae=!1},d(e){e&&(a(p),a(l),a(o),a(t),a(M),a(j),a(U),a(T),a(f),a(z),a(X),a(R),a(q),a(I),a(Q),a(K),a(O),a(Y),a(D),a(ee),a(te),a(W),a(se),a(N),a(ne),a(oe),a(le),a(F)),a(n),y(s,e),y(i,e),y(v,e),y(G,e),y(J,e),y(H,e),y(Z,e),y(V,e),y(E,e),y(L,e)}}}const Ye='{"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 Ve(b){return be(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pe extends Me{constructor(n){super(),we(this,n,Ve,He,ye,{})}}export{Pe as component};
