Buckets:

HuggingFaceDocBuilder's picture
download
raw
16 kB
import{s as be,o as ye,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 _,t as d,o as g,p as b}from"../chunks/index.26bc89a1.js";import{C as je,H as ce,E as Te}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.7a0ae628.js";import{C as k}from"../chunks/CodeBlock.844ff9c3.js";import{H as re,a as A}from"../chunks/HfOption.76c7ca3e.js";function Ce(y){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/pr_4021/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-1c066hr"&&(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),_(o,f,v),r(f,s,v),r(f,t,v),r(f,M,v),r(f,j,v),r(f,U,v),_(T,f,v),B=!0},p:P,i(f){B||(d(o.$$.fragment,f),d(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)),b(o,f),b(T,f)}}}function Ue(y){let n,p='For a function that should only be executed once, use <a href="/docs/accelerate/pr_4021/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-1ua89kl"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),_(o,t,i),s=!0},p:P,i(t){s||(d(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),b(o,t)}}}function Ge(y){let n,p,l,o;return n=new A({props:{id:"local-execution",option:"statements",$$slots:{default:[Ce]},$$scope:{ctx:y}}}),l=new A({props:{id:"local-execution",option:"function",$$slots:{default:[Ue]},$$scope:{ctx:y}}}),{c(){$(n.$$.fragment),p=u(),$(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(l.$$.fragment,s)},m(s,t){_(n,s,t),r(s,p,t),_(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||(d(n.$$.fragment,s),d(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 Je(y){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),_(o,t,i),s=!0},p:P,i(t){s||(d(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),b(o,t)}}}function Ze(y){let n,p='For a function that should only be executed once across all processes, use <a href="/docs/accelerate/pr_4021/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-1ei08f6"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),_(o,t,i),s=!0},p:P,i(t){s||(d(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),b(o,t)}}}function ke(y){let n,p,l,o;return n=new A({props:{id:"main-execution",option:"statement",$$slots:{default:[Je]},$$scope:{ctx:y}}}),l=new A({props:{id:"main-execution",option:"function",$$slots:{default:[Ze]},$$scope:{ctx:y}}}),{c(){$(n.$$.fragment),p=u(),$(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(l.$$.fragment,s)},m(s,t){_(n,s,t),r(s,p,t),_(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||(d(n.$$.fragment,s),d(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 Be(y){let n,p='Use the <a href="/docs/accelerate/pr_4021/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-eb3owo"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),_(o,t,i),s=!0},p:P,i(t){s||(d(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),b(o,t)}}}function Xe(y){let n,p='Use the <a href="/docs/accelerate/pr_4021/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-1n01lp1"&&(n.innerHTML=p),l=m(t),h(o.$$.fragment,t)},m(t,i){r(t,n,i),r(t,l,i),_(o,t,i),s=!0},p:P,i(t){s||(d(o.$$.fragment,t),s=!0)},o(t){g(o.$$.fragment,t),s=!1},d(t){t&&(a(n),a(l)),b(o,t)}}}function Ie(y){let n,p,l,o;return n=new A({props:{id:"specific-execution",option:"specific process",$$slots:{default:[Be]},$$scope:{ctx:y}}}),l=new A({props:{id:"specific-execution",option:"local process",$$slots:{default:[Xe]},$$scope:{ctx:y}}}),{c(){$(n.$$.fragment),p=u(),$(l.$$.fragment)},l(s){h(n.$$.fragment,s),p=m(s),h(l.$$.fragment,s)},m(s,t){_(n,s,t),r(s,p,t),_(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||(d(n.$$.fragment,s),d(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 He(y){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/pr_4021/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:y}}}),J=new re({props:{id:"main-execution",options:["statement","function"],$$slots:{default:[ke]},$$scope:{ctx:y}}}),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:y}}}),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-yvqv3c"&&(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),_(s,e,c),r(e,t,c),_(i,e,c),r(e,M,c),r(e,j,c),r(e,U,c),r(e,T,c),r(e,f,c),_(v,e,c),r(e,z,c),r(e,X,c),r(e,R,c),_(G,e,c),r(e,q,c),r(e,I,c),r(e,Q,c),_(J,e,c),r(e,K,c),_(H,e,c),r(e,O,c),r(e,Y,c),r(e,D,c),_(Z,e,c),r(e,ee,c),_(V,e,c),r(e,te,c),r(e,W,c),r(e,se,c),r(e,N,c),r(e,ne,c),_(E,e,c),r(e,oe,c),_(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 _e={};c&2&&(_e.$$scope={dirty:c,ctx:e}),J.$set(_e);const de={};c&2&&(de.$$scope={dirty:c,ctx:e}),Z.$set(de)},i(e){ae||(d(s.$$.fragment,e),d(i.$$.fragment,e),d(v.$$.fragment,e),d(G.$$.fragment,e),d(J.$$.fragment,e),d(H.$$.fragment,e),d(Z.$$.fragment,e),d(V.$$.fragment,e),d(E.$$.fragment,e),d(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),b(s,e),b(i,e),b(v,e),b(G,e),b(J,e),b(H,e),b(Z,e),b(V,e),b(E,e),b(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(y){return ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pe extends Me{constructor(n){super(),we(this,n,Ve,He,be,{})}}export{Pe as component};

Xet Storage Details

Size:
16 kB
·
Xet hash:
72c57098354a8dca7c57a40610f624cafbd718c704fe825cad4f7408b0da8141

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.