Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

accelerate

> 编程语言
Open source

A simple way to launch, train, and use PyTorch models on almost any device and distributed configuration, automatic mixed precision (including fp8), and easy

9.8K stars0 likes2 views
WebsiteGitHub

About

A simple way to launch, train, and use PyTorch models on almost any device and distributed configuration, automatic mixed precision (including fp8), and easy


<br>

<a href="https://github.com/huggingface/accelerate/blob/main/LICENSE"></a>
<a href="https://huggingface.co/docs/accelerate/index.html"></a>
<a href="https://github.com/huggingface/accelerate/releases"></a>
<a href="https://github.com/huggingface/accelerate/blob/main/CODE_OF_CONDUCT.md"></a>

Run your *raw* PyTorch training script on any kind of device

Easy to integrate

Accelerate was created for PyTorch users who like to write the training loop of PyTorch models but are reluctant to write and maintain the boilerplate code needed to use multi-GPUs/TPU/fp16.

Accelerate abstracts exactly and only the boilerplate code related to multi-GPUs/TPU/fp16 and leaves the rest of your code unchanged.

Here is an example:

…

As you can see in this example, by adding 5-lines to any standard PyTorch training script you can now run on any kind of single or distributed node setting (single CPU, single GPU, multi-GPUs and TPUs) as well as with or without mixed precision (fp8, fp16, bf16).

In particular, the same code can then be run without modification on your local machine for debugging or your training environment.

Accelerate even handles the device placement for you (which requires a few more changes to your code, but is safer in general), so you can even simplify your training loop further:

…

Want to learn more? Check out the documentation or have a look at our examples.

Launching script

Accelerate also provides an optional CLI tool that allows you to quickly configure and test your training environment before launching the scripts. No need to remember how to use torch.distributed.run or to write a specific launcher for TPU training! On your machine(s) just run:

bash
accelerate config

and answer the questions asked. This will generate a config file that will be used automatically to properly set the default options when doing

bash
accelerate launch my_script.py --args_to_my_script

For instance, here is how you would run the GLUE example on the MRPC task (from the root of the repo):

bash
accelerate launch examples/nlp_example.py

This CLI tool is optional, and you can still use python my_script.py or python -m torchrun my_script.py at your convenience.

You can also directly pass in the arguments you would to torchrun as arguments to accelerate launch if you wish to not run accelerate config.

For example, here is how to launch on two GPUs:

bash
accelerate launch --multi_gpu --num_processes 2 examples/nlp_example.py

To learn more, check the CLI documentation available here.

Or view the configuration zoo here

Launching multi-CPU run using MPI

Here is another way to launch multi-CPU run using MPI. You can learn how to install Open MPI on this page. You can use Intel MPI or MVAPICH as well. Once you have MPI setup on your cluster, just run:

bash
accelerate config

Answer the questions that are asked, selecting to run using multi-CPU, and answer "yes" when asked if you want accelerate to launch mpirun. Then, use accelerate launch with your script like:

bash
accelerate launch examples/nlp_example.py

Alternatively, you can use mpirun directly, without using the CLI like:

bash
mpirun -np 2 python examples/nlp_example.py

Launching training using DeepSpeed

Accelerate supports training on single/multiple GPUs using DeepSpeed. To use it, you don't need to change anything in your training code; you can set everything using just accelerate config. However, if you desire to tweak your DeepSpeed related args from your Python script, we provide you the DeepSpeedPlugin.

…

Note: DeepSpeed support is experimental for now. In case you get into some problem, please open an issue.

Launching your training from a notebook

Accelerate also provides a notebook_launcher function you can use in a notebook to launch a distributed training. This is especially useful for Colab or Kaggle notebooks with a TPU backend. Just define your training loop in a training_function then in your last cell, add:

python
from accelerate import notebook_launcher

notebook_launcher(training_function)

An example can be found in this notebook.

Why should I use Accelerate?

You should use Accelerate when you want to easily run your training scripts in a distributed environment without having to renounce full control over your training loop. This is not a high-level framework above PyTorch, just a thin wrapper so you don't have to learn a new library. In fact, the whole API of Accelerate is in one class, the Accelerator object.

Why shouldn't I use Accelerate?

You shouldn't use Accelerate if you don't want to write a training loop yourself. There are plenty of high-level libraries above PyTorch that will offer you that, Accelerate is not one of them.

Frameworks using Accelerate

If you like the simplicity of Accelerate but would prefer a higher-level abstraction around its capabilities, some frameworks and libraries that are built on top of Accelerate are listed below:

  • Amphion is a toolkit for Audio, Music, and Speech Generation. Its purpose is to support reproducible research and help junior researchers and engineers get started in the field of audio, music, and speech generation research and development.
  • Animus is a minimalistic framework to run machine learning experiments. Animus highlights common "breakpoints" in ML experiments and provides a unified interface for them within IExperiment.
  • Catalyst is a PyTorch framework for Deep Learning Research and Development. It focuses on reproducibility, rapid experimentation, and codebase reuse so you can create something new rather than write yet another train loop. Catalyst provides a Runner to connect all parts of the experiment: hardware backend, data transformations, model training, and inference logic.
  • fastai is a PyTorch framework for Deep Learning that simplifies training fast and accurate neural nets using modern best practices. fastai provides a Learner to handle the training, fine-tuning, and inference of deep learning algorithms.
  • Finetuner is a service that enables models to create higher-quality embeddings for semantic search, visual similarity search, cross-modal text<->image search, recommendation systems, clustering, duplication detection, anomaly detection, or other uses.
  • InvokeAI is a creative engine for Stable Diffusion models, offering industry-leading WebUI, terminal usage support, and serves as the foundation for many commercial products.
  • Kornia is a differentiable library that allows classical computer vision to be integrated into deep learning models. Kornia provides a Trainer with the specific purpose to train and fine-tune the supported deep learning algorithms within the library.
  • Open Assistant is a chat-based assistant that understands tasks, can interact with their party systems, and retrieve information dynamically to do so.
  • pytorch-accelerated is a lightweight training library, with a streamlined feature set centered around a general-purpose Trainer, that places a huge emphasis on simplicity and transparency; enabling users to understand exactly what is going on under the hood, but without having to write and maintain the boilerplate themselves!
  • Stable Diffusion web UI is an open-source browser-based easy-to-use interface based on the Gradio library for Stable Diffusion.
  • torchkeras is a simple tool for training pytorch model just in a keras style, a dynamic and beautiful plot is provided in notebook to monitor your loss or metric.
  • transformers as a tool for helping train state-of-the-art machine learning models in PyTorch, Tensorflow, and JAX. (Accelerate is the backend for the PyTorch side).

Installation

This repository is tested on Python 3.8+ and PyTorch 1.10.0+

You should install Accelerate in a virtual environment. If you're unfamiliar with Python virtual environments, check out the user guide.

First, create a virtual environment with the version of Python you're going to use and activate it.

Then, you will need to install PyTorch: refer to the official installation page regarding the specific install command for your platform. Then Accelerate can be installed using pip as follows:

bash
pip install accelerate

Supported integrations

  • CPU only
  • multi-CPU on one node (machine)
  • multi-CPU on several nodes (machines)
  • single GPU
  • multi-GPU on one node (machine)
  • multi-GPU on several nodes (machines)
  • TPU
  • FP16/BFloat16 mixed precision
  • FP8 mixed precision with Transformer Engine or MS-AMP
  • DeepSpeed support (Experimental)
  • PyTorch Fully Sharded Data Parallel (FSDP) support (Experimental)
  • Megatron-LM support (Experimental)

Citing Accelerate

If you use Accelerate in your publication, please cite it by using the following BibTeX entry.

bibtex
@Misc{accelerate,
  title =        {Accelerate: Training and inference at scale made simple, efficient and adaptable.},
  author =       {Sylvain Gugger and Lysandre Debut and Thomas Wolf and Philipp Schmid and Zachary Mueller and Sourab Mangrulkar and Marc Sun and Benjamin Bossan},
  howpublished = {\\url{https://github.com/huggingface/accelerate}},
  year =         {2022}
}

Issues· 90 open

View all issuesOpen on GitHub
  • #4353

    wait_for_everyone() raises NotImplementedError on MULTI_CPU when the machine has an MPS accelerator (barrier gets device_ids)

    Updated Sep 28, 2026
  • #4339

    FSDP2 get_state_dict() does not preserve tied-weight aliasing

    Updated Sep 26, 2026
  • #4283

    [Bug] RNG state restoration failure swallowed silently — resumed training diverges without warning

    Updated Sep 26, 2026
  • #4204

    `use_stateful_dataloader` + `num_workers>0` draws epoch-0 permutation during `prepare()` before cross-rank RNG sync — corrupts DDP data partition

    Updated Sep 24, 2026
  • #4330

    Resuming with load_state + skip_first_batches (checkpointing example) does not restore the shuffle order

    Updated Sep 24, 2026
  • #3170

    [BUG] Accelerate 1.0.1 failed to train multiple zero-3 models

    wipUpdated Sep 23, 2026
  • #4253

    compile_regions runs the uncompiled model when the root module has an accelerate hook

    Updated Sep 20, 2026
  • #3265

    accelerator.prepare

    Updated Sep 20, 2026
  • #4277

    `simple_launcher` discards the child's error, unlike the elastic launch path

    Updated Sep 18, 2026
  • #4269

    all_gather_into_tensor is deprecated, _gpu_gather warns on every gather

    Updated Sep 16, 2026

> Tags

Python

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言