Buckets:
| import{s as be,o as we,n as Te}from"../chunks/scheduler.b9285784.js";import{S as xe,i as Me,e as s,s as l,c as z,h as He,a as o,d as a,b as i,f as ge,g as A,j as p,k as ve,l as Pe,m as r,n as E,t as j,o as I,p as U}from"../chunks/index.26bc89a1.js";import{T as Le}from"../chunks/Tip.e4eba3d6.js";import{C as Ce,H as ke,E as Se}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.ca265e81.js";function De(S){let n,d=`Synchronization of the main torch (or CUDA or XLA) random number generator will affect any other potential random | |
| artifacts you could have in your dataset (like random data augmentation) in the sense that all processes will get | |
| the same random numbers from the torch random modules (so will apply the same random data augmentation if it’s | |
| controlled by torch).`;return{c(){n=s("p"),n.textContent=d},l(c){n=o(c,"P",{"data-svelte-h":!0}),p(n)!=="svelte-1pu9s3f"&&(n.textContent=d)},m(c,h){r(c,n,h)},p:Te,d(c){c&&a(n)}}}function ze(S){let n,d=`The randomization part of your custom sampler, batch sampler or iterable dataset should be done using a local | |
| <code>torch.Generator</code> object (in PyTorch >= 1.6), see the traditional <code>RandomSampler</code>, as an example.`;return{c(){n=s("p"),n.innerHTML=d},l(c){n=o(c,"P",{"data-svelte-h":!0}),p(n)!=="svelte-1ffnyf3"&&(n.innerHTML=d)},m(c,h){r(c,n,h)},p:Te,d(c){c&&a(n)}}}function Ae(S){let n,d,c,h,u,q,_,O,$,ne=`Internally, Accelerate works by first analyzing the environment in which the script is launched to determine which | |
| kind of distributed setup is used, how many different processes there are and which one the current script is in. All | |
| that information is stored in the <code>~AcceleratorState</code>.`,R,y,le=`This class is initialized the first time you instantiate an <a href="/docs/accelerate/pr_4073/en/package_reference/accelerator#accelerate.Accelerator">~Accelerator</a> as well as performing any | |
| specific initialization your distributed setup needs. Its state is then uniquely shared through all instances of | |
| <a href="/docs/accelerate/pr_4073/en/package_reference/state#accelerate.state.AcceleratorState">AcceleratorState</a>. (The same can also be done with the <a href="/docs/accelerate/pr_4073/en/package_reference/state#accelerate.PartialState">PartialState</a>, a more barebones version it inherits)`,G,g,ie='Then, when calling <a href="/docs/accelerate/pr_4073/en/package_reference/accelerator#accelerate.Accelerator.prepare">prepare()</a>, the library:',F,v,se='<li>wraps your model(s) in the container adapted for the distributed setup,</li> <li>wraps your optimizer(s) in an <a href="/docs/accelerate/pr_4073/en/package_reference/torch_wrappers#accelerate.optimizer.AcceleratedOptimizer">AcceleratedOptimizer</a>,</li> <li>wraps your scheduler(s) in an <a href="/docs/accelerate/pr_4073/en/package_reference/torch_wrappers#accelerate.scheduler.AcceleratedScheduler">AcceleratedScheduler</a></li> <li>creates a new version of your dataloader(s) in a <a href="/docs/accelerate/pr_4073/en/package_reference/torch_wrappers#accelerate.data_loader.DataLoaderShard">DataLoaderShard</a> or <a href="/docs/accelerate/pr_4073/en/package_reference/torch_wrappers#accelerate.data_loader.DataLoaderDispatcher">DataLoaderDispatcher</a></li>',W,L,oe=`While the model(s), optimizer(s), and scheduler(s) are just put in simple wrappers, the dataloader(s) are re-created. This is mostly | |
| because PyTorch does not let the user change the <code>batch_sampler</code> of a dataloader once it’s been created and the | |
| library handles the sharding of your data between processes by changing that <code>batch_sampler</code> to yield every other | |
| <code>num_processes</code> batches (if enabled).`,X,T,ce='The <a href="/docs/accelerate/pr_4073/en/package_reference/torch_wrappers#accelerate.data_loader.DataLoaderShard">DataLoaderShard</a> subclasses <code>DataLoader</code> to add the following functionality:',Y,b,pe=`<li>it synchronizes the appropriate random number generator of all processes at each new iteration, to ensure any | |
| randomization (like shuffling) is done the exact same way across processes.</li> <li>it puts the batches on the proper device before yielding them (unless you have opted out of | |
| <code>device_placement=True</code>).</li>`,B,w,de='The <a href="/docs/accelerate/pr_4073/en/package_reference/torch_wrappers#accelerate.data_loader.DataLoaderDispatcher">DataLoaderDispatcher</a> subclasses differs from the <a href="/docs/accelerate/pr_4073/en/package_reference/torch_wrappers#accelerate.data_loader.DataLoaderShard">DataLoaderShard</a> in that when iterating through the <code>DataLoader</code>, the data is all starting from process 0 and <em>then</em> split and sent off to each process rather than it happening at the dataset level.',J,x,he="The random number generator synchronization will by default synchronize:",K,M,me="<li>the <code>generator</code> attribute of a given sampler (like the PyTorch <code>RandomSampler</code>) for PyTorch >= 1.6</li> <li>the main random number generator in PyTorch <=1.5.1</li>",N,H,fe=`You can choose which random number generator(s) to synchronize with the <code>rng_types</code> argument of the main | |
| <a href="/docs/accelerate/pr_4073/en/package_reference/accelerator#accelerate.Accelerator">Accelerator</a>. In PyTorch >= 1.6, it is recommended to rely on a local <code>generator</code> to avoid | |
| setting the same seed in the main random number generator in all processes.`,Q,m,V,f,Z,P,ue='If you have <a href="https://github.com/pytorch/data/tree/main" rel="nofollow"><code>torchdata>=0.8.0</code></a> installed, and you have passed <code>use_stateful_dataloader=True</code> into your <a href="/docs/accelerate/pr_4073/en/package_reference/utilities#accelerate.DataLoaderConfiguration">DataLoaderConfiguration</a>, these classes will directly inherit from <code>StatefulDataLoader</code> instead, and maintain a <code>state_dict</code>.',ee,C,_e='For more details about the internals, see the <a href="../package_reference/torch_wrappers">Internals page</a>.',te,k,ae,D,re;return u=new Ce({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),_=new ke({props:{title:"Accelerate’s internal mechanisms",local:"accelerates-internal-mechanisms",headingTag:"h1"}}),m=new Le({props:{warning:!0,$$slots:{default:[De]},$$scope:{ctx:S}}}),f=new Le({props:{$$slots:{default:[ze]},$$scope:{ctx:S}}}),k=new Se({props:{source:"https://github.com/huggingface/accelerate/blob/main/docs/source/concept_guides/internal_mechanism.md"}}),{c(){n=s("meta"),d=l(),c=s("p"),h=l(),z(u.$$.fragment),q=l(),z(_.$$.fragment),O=l(),$=s("p"),$.innerHTML=ne,R=l(),y=s("p"),y.innerHTML=le,G=l(),g=s("p"),g.innerHTML=ie,F=l(),v=s("ul"),v.innerHTML=se,W=l(),L=s("p"),L.innerHTML=oe,X=l(),T=s("p"),T.innerHTML=ce,Y=l(),b=s("ul"),b.innerHTML=pe,B=l(),w=s("p"),w.innerHTML=de,J=l(),x=s("p"),x.textContent=he,K=l(),M=s("ul"),M.innerHTML=me,N=l(),H=s("p"),H.innerHTML=fe,Q=l(),z(m.$$.fragment),V=l(),z(f.$$.fragment),Z=l(),P=s("p"),P.innerHTML=ue,ee=l(),C=s("p"),C.innerHTML=_e,te=l(),z(k.$$.fragment),ae=l(),D=s("p"),this.h()},l(e){const t=He("svelte-u9bgzb",document.head);n=o(t,"META",{name:!0,content:!0}),t.forEach(a),d=i(e),c=o(e,"P",{}),ge(c).forEach(a),h=i(e),A(u.$$.fragment,e),q=i(e),A(_.$$.fragment,e),O=i(e),$=o(e,"P",{"data-svelte-h":!0}),p($)!=="svelte-1i5bxcr"&&($.innerHTML=ne),R=i(e),y=o(e,"P",{"data-svelte-h":!0}),p(y)!=="svelte-1d0n907"&&(y.innerHTML=le),G=i(e),g=o(e,"P",{"data-svelte-h":!0}),p(g)!=="svelte-1g9w4gj"&&(g.innerHTML=ie),F=i(e),v=o(e,"UL",{"data-svelte-h":!0}),p(v)!=="svelte-1k3wofv"&&(v.innerHTML=se),W=i(e),L=o(e,"P",{"data-svelte-h":!0}),p(L)!=="svelte-1xlmls8"&&(L.innerHTML=oe),X=i(e),T=o(e,"P",{"data-svelte-h":!0}),p(T)!=="svelte-14z5l4c"&&(T.innerHTML=ce),Y=i(e),b=o(e,"UL",{"data-svelte-h":!0}),p(b)!=="svelte-zg63ut"&&(b.innerHTML=pe),B=i(e),w=o(e,"P",{"data-svelte-h":!0}),p(w)!=="svelte-2lqf2f"&&(w.innerHTML=de),J=i(e),x=o(e,"P",{"data-svelte-h":!0}),p(x)!=="svelte-rp8jqi"&&(x.textContent=he),K=i(e),M=o(e,"UL",{"data-svelte-h":!0}),p(M)!=="svelte-1nv6po7"&&(M.innerHTML=me),N=i(e),H=o(e,"P",{"data-svelte-h":!0}),p(H)!=="svelte-r6620x"&&(H.innerHTML=fe),Q=i(e),A(m.$$.fragment,e),V=i(e),A(f.$$.fragment,e),Z=i(e),P=o(e,"P",{"data-svelte-h":!0}),p(P)!=="svelte-mu4tkg"&&(P.innerHTML=ue),ee=i(e),C=o(e,"P",{"data-svelte-h":!0}),p(C)!=="svelte-12lucyn"&&(C.innerHTML=_e),te=i(e),A(k.$$.fragment,e),ae=i(e),D=o(e,"P",{}),ge(D).forEach(a),this.h()},h(){ve(n,"name","hf:doc:metadata"),ve(n,"content",Ee)},m(e,t){Pe(document.head,n),r(e,d,t),r(e,c,t),r(e,h,t),E(u,e,t),r(e,q,t),E(_,e,t),r(e,O,t),r(e,$,t),r(e,R,t),r(e,y,t),r(e,G,t),r(e,g,t),r(e,F,t),r(e,v,t),r(e,W,t),r(e,L,t),r(e,X,t),r(e,T,t),r(e,Y,t),r(e,b,t),r(e,B,t),r(e,w,t),r(e,J,t),r(e,x,t),r(e,K,t),r(e,M,t),r(e,N,t),r(e,H,t),r(e,Q,t),E(m,e,t),r(e,V,t),E(f,e,t),r(e,Z,t),r(e,P,t),r(e,ee,t),r(e,C,t),r(e,te,t),E(k,e,t),r(e,ae,t),r(e,D,t),re=!0},p(e,[t]){const $e={};t&2&&($e.$$scope={dirty:t,ctx:e}),m.$set($e);const ye={};t&2&&(ye.$$scope={dirty:t,ctx:e}),f.$set(ye)},i(e){re||(j(u.$$.fragment,e),j(_.$$.fragment,e),j(m.$$.fragment,e),j(f.$$.fragment,e),j(k.$$.fragment,e),re=!0)},o(e){I(u.$$.fragment,e),I(_.$$.fragment,e),I(m.$$.fragment,e),I(f.$$.fragment,e),I(k.$$.fragment,e),re=!1},d(e){e&&(a(d),a(c),a(h),a(q),a(O),a($),a(R),a(y),a(G),a(g),a(F),a(v),a(W),a(L),a(X),a(T),a(Y),a(b),a(B),a(w),a(J),a(x),a(K),a(M),a(N),a(H),a(Q),a(V),a(Z),a(P),a(ee),a(C),a(te),a(ae),a(D)),a(n),U(u,e),U(_,e),U(m,e),U(f,e),U(k,e)}}}const Ee='{"title":"Accelerate’s internal mechanisms","local":"accelerates-internal-mechanisms","sections":[],"depth":1}';function je(S){return we(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Re extends xe{constructor(n){super(),Me(this,n,je,Ae,be,{})}}export{Re as component}; | |
Xet Storage Details
- Size:
- 9.81 kB
- Xet hash:
- 899b80e67072b98d89df2e41f949be259bc732784802762c0758f0ba2548ae5b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.