75 lines
4.1 KiB
Markdown
75 lines
4.1 KiB
Markdown
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
|
the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
specific language governing permissions and limitations under the License.
|
|
|
|
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
|
rendered properly in your Markdown viewer.
|
|
-->
|
|
|
|
# Accelerate
|
|
|
|
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.
|
|
|
|
```diff
|
|
+ from accelerate import Accelerator
|
|
+ accelerator = Accelerator()
|
|
|
|
+ model, optimizer, training_dataloader, scheduler = accelerator.prepare(
|
|
+ model, optimizer, training_dataloader, scheduler
|
|
+ )
|
|
|
|
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)
|
|
+ accelerator.backward(loss)
|
|
optimizer.step()
|
|
scheduler.step()
|
|
```
|
|
|
|
Built on `torch_xla` and `torch.distributed`, 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 [DeepSpeed](usage_guides/deepspeed), perform [fully sharded data parallelism](usage_guides/fsdp), and have automatic support for mixed-precision training!
|
|
|
|
<Tip>
|
|
|
|
To get a better idea of this process, make sure to check out the [Tutorials](basic_tutorials/overview)!
|
|
|
|
</Tip>
|
|
|
|
|
|
This code can then be launched on any system through Accelerate's CLI interface:
|
|
```bash
|
|
accelerate launch {my_script.py}
|
|
```
|
|
|
|
<div class="mt-10">
|
|
<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>
|
|
</div>
|