import{s as P,o as Q,n as D}from"../chunks/scheduler.defa9a21.js";import{S as K,i as q,g as c,s as i,r as M,A as O,h as p,f as a,c as n,j as F,u as v,x as U,k as X,y as ee,a as l,v as I,d as x,t as $,w as j}from"../chunks/index.fe795e71.js";import{T as te}from"../chunks/Tip.179eb360.js";import{C as L}from"../chunks/CodeBlock.204b6c34.js";import{H as ae,E as le}from"../chunks/getInferenceSnippets.2234a8dd.js";function se(_){let s,u='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=u},l(r){s=p(r,"P",{"data-svelte-h":!0}),U(s)!=="svelte-1bhu5i7"&&(s.innerHTML=u)},m(r,b){l(r,s,b)},p:D,d(r){r&&a(s)}}}function re(_){let s,u,r,b,m,C,f,S="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.",G,h,A,w,E=`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!`,k,o,Z,g,N="This code can then be launched on any system through Accelerate’s CLI interface:",B,J,R,d,H='<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>',V,T,z,y,W;return m=new ae({props:{title:"Accelerate",local:"accelerate",headingTag:"h1"}}),h=new L({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 te({props:{$$slots:{default:[se]},$$scope:{ctx:_}}}),J=new L({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMCU3Qm15X3NjcmlwdC5weSU3RA==",highlighted:"accelerate launch {my_script.py}",wrap:!1}}),T=new le({props:{source:"https://github.com/huggingface/accelerate/blob/main/docs/source/index.md"}}),{c(){s=c("meta"),u=i(),r=c("p"),b=i(),M(m.$$.fragment),C=i(),f=c("p"),f.textContent=S,G=i(),M(h.$$.fragment),A=i(),w=c("p"),w.innerHTML=E,k=i(),M(o.$$.fragment),Z=i(),g=c("p"),g.textContent=N,B=i(),M(J.$$.fragment),R=i(),d=c("div"),d.innerHTML=H,V=i(),M(T.$$.fragment),z=i(),y=c("p"),this.h()},l(e){const t=O("svelte-u9bgzb",document.head);s=p(t,"META",{name:!0,content:!0}),t.forEach(a),u=n(e),r=p(e,"P",{}),F(r).forEach(a),b=n(e),v(m.$$.fragment,e),C=n(e),f=p(e,"P",{"data-svelte-h":!0}),U(f)!=="svelte-15uru8x"&&(f.textContent=S),G=n(e),v(h.$$.fragment,e),A=n(e),w=p(e,"P",{"data-svelte-h":!0}),U(w)!=="svelte-lsunxv"&&(w.innerHTML=E),k=n(e),v(o.$$.fragment,e),Z=n(e),g=p(e,"P",{"data-svelte-h":!0}),U(g)!=="svelte-ssi2o8"&&(g.textContent=N),B=n(e),v(J.$$.fragment,e),R=n(e),d=p(e,"DIV",{class:!0,"data-svelte-h":!0}),U(d)!=="svelte-11thknd"&&(d.innerHTML=H),V=n(e),v(T.$$.fragment,e),z=n(e),y=p(e,"P",{}),F(y).forEach(a),this.h()},h(){X(s,"name","hf:doc:metadata"),X(s,"content",ie),X(d,"class","mt-10")},m(e,t){ee(document.head,s),l(e,u,t),l(e,r,t),l(e,b,t),I(m,e,t),l(e,C,t),l(e,f,t),l(e,G,t),I(h,e,t),l(e,A,t),l(e,w,t),l(e,k,t),I(o,e,t),l(e,Z,t),l(e,g,t),l(e,B,t),I(J,e,t),l(e,R,t),l(e,d,t),l(e,V,t),I(T,e,t),l(e,z,t),l(e,y,t),W=!0},p(e,[t]){const Y={};t&2&&(Y.$$scope={dirty:t,ctx:e}),o.$set(Y)},i(e){W||(x(m.$$.fragment,e),x(h.$$.fragment,e),x(o.$$.fragment,e),x(J.$$.fragment,e),x(T.$$.fragment,e),W=!0)},o(e){$(m.$$.fragment,e),$(h.$$.fragment,e),$(o.$$.fragment,e),$(J.$$.fragment,e),$(T.$$.fragment,e),W=!1},d(e){e&&(a(u),a(r),a(b),a(C),a(f),a(G),a(A),a(w),a(k),a(Z),a(g),a(B),a(R),a(d),a(V),a(z),a(y)),a(s),j(m,e),j(h,e),j(o,e),j(J,e),j(T,e)}}}const ie='{"title":"Accelerate","local":"accelerate","sections":[],"depth":1}';function ne(_){return Q(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class me extends K{constructor(s){super(),q(this,s,ne,re,P,{})}}export{me as component};
