---
title: "Introducing 🤗 Accelerate"
description: "🤗 Accelerate lets PyTorch users keep their own training loops while running the same script on CPU, single or multi-GPU, multi-node, TPU, and with mixed precision, by adding about five lines: an Accelerator object, accelerator.prepare() for model/optimizer/dataloader, and accelerator.backward(). prepare() wraps the model in the right container such as DistributedDataParallel, wraps the optimizer for mixed precision, and shards any sampler's indices per process using synchronized RNGs instead of requiring DistributedSampler."
url: "https://swe.quest/articles/introducing-accelerate-aaf88192c9f162b5"
canonical: "https://huggingface.co/blog/accelerate-library"
source: "Hugging Face"
published: "2021-04-16"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 7
tags: ["model-training","python","machine-learning"]
---

# Introducing 🤗 Accelerate

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2021-04-16, 7 min read, Announcement. Original: [https://huggingface.co/blog/accelerate-library](https://huggingface.co/blog/accelerate-library)

## Summary

🤗 Accelerate lets PyTorch users keep their own training loops while running the same script on CPU, single or multi-GPU, multi-node, TPU, and with mixed precision, by adding about five lines: an Accelerator object, accelerator.prepare() for model/optimizer/dataloader, and accelerator.backward(). prepare() wraps the model in the right container such as DistributedDataParallel, wraps the optimizer for mixed precision, and shards any sampler's indices per process using synchronized RNGs instead of requiring DistributedSampler. Distributed evaluation uses accelerator.gather plus truncation of padded batches. An \`accelerate config\` / \`accelerate launch\` CLI replaces torch.distributed.launch arguments and can target SageMaker.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)

## Prerequisites

- PyTorch training loops ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- distributed data parallel training ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- mixed precision training ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))

## Keywords

Hugging Face Accelerate, PyTorch, DistributedDataParallel, TPU, mixed precision, AWS SageMaker

## Related posts

- [From PyTorch DDP to Accelerate to Trainer, mastery of distributed training with ease](https://swe.quest/articles/from-pytorch-ddp-to-accelerate-to-trainer-mastery-of-distributed-training-with-8ad821e28b1383c4.md): Hugging Face · 2022-10-21 · Medium · 9 min read · Model training, Python, Machine learning
  Converting a basic PyTorch MNIST training script to multi-GPU Distributed Data Parallel training is shown at three levels of abstraction.
- [Accelerate 1.0.0](https://swe.quest/articles/accelerate-1-0-0-3876b57c9168d12c.md): Hugging Face · 2024-09-13 · Medium · 5 min read · Model training, Python, Machine learning
  Hugging Face has published the first release candidates for Accelerate 1.0.0.
- [Accelerate Large Model Training using DeepSpeed](https://swe.quest/articles/accelerate-large-model-training-using-deepspeed-d18dbe7623c821c0.md): Hugging Face · 2022-06-28 · Medium · 8 min read · Model training, Python, Performance engineering
  Hugging Face Accelerate can enable DeepSpeed ZeRO data parallelism, which shards optimizer states, gradients and parameters across GPUs and optionally offloads them to CPU, with no or minimal code changes.
- [Accelerate Large Model Training using PyTorch Fully Sharded Data Parallel](https://swe.quest/articles/accelerate-large-model-training-using-pytorch-fully-sharded-data-parallel-513a65557fbde722.md): Hugging Face · 2022-05-02 · Hard · 12 min read · Model training, Machine learning, Python, Performance engineering
  Hugging Face Accelerate exposes PyTorch FullyShardedDataParallel (FSDP), which shards parameters, gradients and optimizer states across GPUs (ZeRO stage 2/3) with optional CPU offload, and does so without changes to training code.
- [How 🤗 Accelerate runs very large models thanks to PyTorch](https://swe.quest/articles/how-accelerate-runs-very-large-models-thanks-to-pytorch-00771d3f91bebb0b.md): Hugging Face · 2022-09-27 · Medium · 11 min read · Inference & serving, Memory management, Python, LLMs
  Accelerate loads and runs models too large for a single GPU or for CPU RAM by changing PyTorch's usual load path.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
