---
title: "Accelerate Large Model Training using DeepSpeed"
description: "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."
url: "https://swe.quest/articles/accelerate-large-model-training-using-deepspeed-d18dbe7623c821c0"
canonical: "https://huggingface.co/blog/accelerate-deepspeed"
source: "Hugging Face"
published: "2022-06-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["model-training","python","performance"]
---

# Accelerate Large Model Training using DeepSpeed

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-06-28, 8 min read, How-to. Original: [https://huggingface.co/blog/accelerate-deepspeed](https://huggingface.co/blog/accelerate-deepspeed)

## Summary

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. On two 24GB Titan RTX GPUs, ZeRO Stage-2 allowed 5x larger batches than DDP for DeBERTa-XL (900M) and gave about a 3.5x training speedup with no accuracy loss. BlenderBot-400M fine-tuning saw 2x batch size and a ~1.44x training speedup. ZeRO Stage-3 with CPU offload made GPT-2 XL (1.5B) trainable at batch size 16 where DDP ran out of memory even at batch size 1. The post includes the accelerate config, DeepSpeed JSON configs, and the DummyOptim/DummyScheduler changes needed when the optimizer and scheduler are defined in the DeepSpeed config.

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)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- PyTorch training loops ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- 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

DeepSpeed, ZeRO, Hugging Face Accelerate, PyTorch DDP, DeBERTa, BlenderBot, GPT-2 XL

## Related posts

- [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.
- [Incredibly Fast BLOOM Inference with DeepSpeed and Accelerate](https://swe.quest/articles/incredibly-fast-bloom-inference-with-deepspeed-and-accelerate-7d1957ba474cbad5.md): Hugging Face · 2022-09-16 · Hard · 9 min read · Inference & serving, LLMs, Performance engineering, Hardware
  Running the 176B-parameter BLOOM model (352GB in bf16) for inference is benchmarked across HuggingFace Accelerate, DeepSpeed-Inference and DeepSpeed ZeRO-Inference on an 8x80GB A100 node, with 8-bit quantized variants via BitsAndBytes and DeepSpeed.
- [From DeepSpeed to FSDP and Back Again with Hugging Face Accelerate](https://swe.quest/articles/from-deepspeed-to-fsdp-and-back-again-with-hugging-face-accelerate-15016dbd4b4a46b2.md): Hugging Face · 2024-06-13 · Hard · 6 min read · Model training, Machine learning, Python
  DeepSpeed ZeRO-3 and PyTorch FSDP gave different training results on Mistral-7B loaded in bfloat16 because DeepSpeed silently upcasts flattened parameters and optimizer state to fp32, while FSDP keeps them in the loaded dtype.
- [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.
- [Fine-tuning Llama 2 70B using PyTorch FSDP](https://swe.quest/articles/fine-tuning-llama-2-70b-using-pytorch-fsdp-0e8dde34b4ad3fd0.md): Hugging Face · 2023-09-13 · Hard · 10 min read · Model training, LLMs, Hardware, Python
  Full fine-tuning of Llama 2 70B across two nodes of 8×A100 80GB GPUs with PyTorch FSDP, Hugging Face Accelerate, Transformers and TRL, addressing three obstacles.

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)
