import{s as D,o as K,n as q}from"../chunks/scheduler.b9285784.js";import{S as O,i as ee,e as c,s as r,c as M,h as te,a as p,d as a,b as i,f as P,g as v,j as U,k as E,l as ae,m as l,n as $,t as x,o as I,p as j}from"../chunks/index.26bc89a1.js";import{T as le}from"../chunks/Tip.e4eba3d6.js";import{C as se,H as re,E as ie}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.7242ff19.js";import{C as Q}from"../chunks/CodeBlock.c8ee1711.js";function ne(_){let s,m='To get a better idea of this process, make sure to check out the <a href="basic_tutorials/overview">Tutorials</a>!';return{c(){s=c("p"),s.innerHTML=m},l(n){s=p(n,"P",{"data-svelte-h":!0}),U(s)!=="svelte-1bhu5i7"&&(s.innerHTML=m)},m(n,b){l(n,s,b)},p:q,d(n){n&&a(s)}}}function oe(_){let s,m,n,b,u,G,f,A,h,N="Accelerate is a library that enables the same PyTorch code to be run across any distributed configuration by adding just four lines of code! In short, training and inference at scale made simple, efficient and adaptable.",k,w,Z,g,H=`Built on <code>torch_xla</code> and <code>torch.distributed</code>, Accelerate takes care of the heavy lifting, so you don’t have to write any custom code to adapt to these platforms.
Convert existing codebases to utilize <a href="usage_guides/deepspeed">DeepSpeed</a>, perform <a href="usage_guides/fsdp">fully sharded data parallelism</a>, and have automatic support for mixed-precision training!`,B,o,z,T,Y="This code can then be launched on any system through Accelerate’s CLI interface:",R,y,V,d,L='<div class="w-full flex flex-col space-y-4 md:space-y-0 md:grid md:grid-cols-2 md:gap-y-4 md:gap-x-5"><a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./basic_tutorials/overview"><div class="w-full text-center bg-gradient-to-br from-blue-400 to-blue-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Tutorials</div> <p class="text-gray-700">Learn the basics and become familiar with using Accelerate. Start here if you are using Accelerate for the first time!</p></a> <a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./usage_guides/explore"><div class="w-full text-center bg-gradient-to-br from-indigo-400 to-indigo-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">How-to guides</div> <p class="text-gray-700">Practical guides to help you achieve a specific goal. Take a look at these guides to learn how to use Accelerate to solve real-world problems.</p></a> <a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./concept_guides/gradient_synchronization"><div class="w-full text-center bg-gradient-to-br from-pink-400 to-pink-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Conceptual guides</div> <p class="text-gray-700">High-level explanations for building a better understanding of important topics such as avoiding subtle nuances and pitfalls in distributed training and DeepSpeed.</p></a> <a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./package_reference/accelerator"><div class="w-full text-center bg-gradient-to-br from-purple-400 to-purple-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Reference</div> <p class="text-gray-700">Technical descriptions of how Accelerate classes and methods work.</p></a></div>',W,J,X,C,S;return u=new se({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),f=new re({props:{title:"Accelerate",local:"accelerate",headingTag:"h1"}}),w=new Q({props:{code:"JTJCJTIwZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBBY2NlbGVyYXRvciUwQSUyQiUyMGFjY2VsZXJhdG9yJTIwJTNEJTIwQWNjZWxlcmF0b3IoKSUwQSUwQSUyQiUyMG1vZGVsJTJDJTIwb3B0aW1pemVyJTJDJTIwdHJhaW5pbmdfZGF0YWxvYWRlciUyQyUyMHNjaGVkdWxlciUyMCUzRCUyMGFjY2VsZXJhdG9yLnByZXBhcmUoJTBBJTJCJTIwJTIwJTIwJTIwJTIwbW9kZWwlMkMlMjBvcHRpbWl6ZXIlMkMlMjB0cmFpbmluZ19kYXRhbG9hZGVyJTJDJTIwc2NoZWR1bGVyJTBBJTJCJTIwKSUwQSUwQSUyMCUyMGZvciUyMGJhdGNoJTIwaW4lMjB0cmFpbmluZ19kYXRhbG9hZGVyJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwb3B0aW1pemVyLnplcm9fZ3JhZCgpJTBBJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRzJTJDJTIwdGFyZ2V0cyUyMCUzRCUyMGJhdGNoJTBBJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRzJTIwJTNEJTIwaW5wdXRzLnRvKGRldmljZSklMEElMjAlMjAlMjAlMjAlMjAlMjB0YXJnZXRzJTIwJTNEJTIwdGFyZ2V0cy50byhkZXZpY2UpJTBBJTIwJTIwJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsKGlucHV0cyklMEElMjAlMjAlMjAlMjAlMjAlMjBsb3NzJTIwJTNEJTIwbG9zc19mdW5jdGlvbihvdXRwdXRzJTJDJTIwdGFyZ2V0cyklMEElMkIlMjAlMjAlMjAlMjAlMjBhY2NlbGVyYXRvci5iYWNrd2FyZChsb3NzKSUwQSUyMCUyMCUyMCUyMCUyMCUyMG9wdGltaXplci5zdGVwKCklMEElMjAlMjAlMjAlMjAlMjAlMjBzY2hlZHVsZXIuc3RlcCgp",highlighted:`<span class="hljs-addition">+ from accelerate import Accelerator</span>
<span class="hljs-addition">+ accelerator = Accelerator()</span>

<span class="hljs-addition">+ model, optimizer, training_dataloader, scheduler = accelerator.prepare(</span>
<span class="hljs-addition">+     model, optimizer, training_dataloader, scheduler</span>
<span class="hljs-addition">+ )</span>

  for batch in training_dataloader:
      optimizer.zero_grad()
      inputs, targets = batch
      inputs = inputs.to(device)
      targets = targets.to(device)
      outputs = model(inputs)
      loss = loss_function(outputs, targets)
<span class="hljs-addition">+     accelerator.backward(loss)</span>
      optimizer.step()
      scheduler.step()`,wrap:!1}}),o=new le({props:{$$slots:{default:[ne]},$$scope:{ctx:_}}}),y=new Q({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMCU3Qm15X3NjcmlwdC5weSU3RA==",highlighted:"accelerate launch {my_script.py}",wrap:!1}}),J=new ie({props:{source:"https://github.com/huggingface/accelerate/blob/main/docs/source/index.md"}}),{c(){s=c("meta"),m=r(),n=c("p"),b=r(),M(u.$$.fragment),G=r(),M(f.$$.fragment),A=r(),h=c("p"),h.textContent=N,k=r(),M(w.$$.fragment),Z=r(),g=c("p"),g.innerHTML=H,B=r(),M(o.$$.fragment),z=r(),T=c("p"),T.textContent=Y,R=r(),M(y.$$.fragment),V=r(),d=c("div"),d.innerHTML=L,W=r(),M(J.$$.fragment),X=r(),C=c("p"),this.h()},l(e){const t=te("svelte-u9bgzb",document.head);s=p(t,"META",{name:!0,content:!0}),t.forEach(a),m=i(e),n=p(e,"P",{}),P(n).forEach(a),b=i(e),v(u.$$.fragment,e),G=i(e),v(f.$$.fragment,e),A=i(e),h=p(e,"P",{"data-svelte-h":!0}),U(h)!=="svelte-15uru8x"&&(h.textContent=N),k=i(e),v(w.$$.fragment,e),Z=i(e),g=p(e,"P",{"data-svelte-h":!0}),U(g)!=="svelte-lsunxv"&&(g.innerHTML=H),B=i(e),v(o.$$.fragment,e),z=i(e),T=p(e,"P",{"data-svelte-h":!0}),U(T)!=="svelte-ssi2o8"&&(T.textContent=Y),R=i(e),v(y.$$.fragment,e),V=i(e),d=p(e,"DIV",{class:!0,"data-svelte-h":!0}),U(d)!=="svelte-11thknd"&&(d.innerHTML=L),W=i(e),v(J.$$.fragment,e),X=i(e),C=p(e,"P",{}),P(C).forEach(a),this.h()},h(){E(s,"name","hf:doc:metadata"),E(s,"content",de),E(d,"class","mt-10")},m(e,t){ae(document.head,s),l(e,m,t),l(e,n,t),l(e,b,t),$(u,e,t),l(e,G,t),$(f,e,t),l(e,A,t),l(e,h,t),l(e,k,t),$(w,e,t),l(e,Z,t),l(e,g,t),l(e,B,t),$(o,e,t),l(e,z,t),l(e,T,t),l(e,R,t),$(y,e,t),l(e,V,t),l(e,d,t),l(e,W,t),$(J,e,t),l(e,X,t),l(e,C,t),S=!0},p(e,[t]){const F={};t&2&&(F.$$scope={dirty:t,ctx:e}),o.$set(F)},i(e){S||(x(u.$$.fragment,e),x(f.$$.fragment,e),x(w.$$.fragment,e),x(o.$$.fragment,e),x(y.$$.fragment,e),x(J.$$.fragment,e),S=!0)},o(e){I(u.$$.fragment,e),I(f.$$.fragment,e),I(w.$$.fragment,e),I(o.$$.fragment,e),I(y.$$.fragment,e),I(J.$$.fragment,e),S=!1},d(e){e&&(a(m),a(n),a(b),a(G),a(A),a(h),a(k),a(Z),a(g),a(B),a(z),a(T),a(R),a(V),a(d),a(W),a(X),a(C)),a(s),j(u,e),j(f,e),j(w,e),j(o,e),j(y,e),j(J,e)}}}const de='{"title":"Accelerate","local":"accelerate","sections":[],"depth":1}';function ce(_){return K(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class we extends O{constructor(s){super(),ee(this,s,ce,oe,D,{})}}export{we as component};
