---
title: "Accelerate Large Model Training using PyTorch Fully Sharded Data Parallel"
description: "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."
url: "https://swe.quest/articles/accelerate-large-model-training-using-pytorch-fully-sharded-data-parallel-513a65557fbde722"
canonical: "https://huggingface.co/blog/pytorch-fsdp"
source: "Hugging Face"
published: "2022-05-02"
difficulty: "hard"
kind: "How-to"
reading_minutes: 12
tags: ["model-training","machine-learning","python","performance"]
---

# Accelerate Large Model Training using PyTorch Fully Sharded Data Parallel

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-05-02, 12 min read, How-to. Original: [https://huggingface.co/blog/pytorch-fsdp](https://huggingface.co/blog/pytorch-fsdp)

## Summary

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. On 2x24GB Titan RTX GPUs, FSDP gives 2-3x larger batch sizes than DDP for GPT-2 Large. It also trains GPT-2 XL (1.5B), which DDP cannot fit even at batch size 1, and with CPU offload it can do so on a single GPU. DDP with FP16 remained fastest in wall-clock time. Practical caveats: tune the auto-wrap min\_num\_params, prepare the model before creating the optimizer because parameter flattening loses parameter groups, and note that mixed precision was not yet supported.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.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))
- Distributed Data Parallel
- GPU memory constraints ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))

## Keywords

PyTorch FSDP, Hugging Face Accelerate, ZeRO, DeepSpeed, FairScale, GPT-2, DDP

## Related posts

- [Fully Sharded Data Parallel: faster AI training with fewer GPUs](https://swe.quest/articles/fully-sharded-data-parallel-faster-ai-training-with-fewer-gpus-9a4d28846db69a7b.md): Meta Engineering · 2021-07-15 · Hard · 8 min read · Model training, Python
  Fully Sharded Data Parallel (FSDP) shards model parameters, gradients and optimizer states across data-parallel GPU workers.
- [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.
- [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.
- [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.
- [Accelerate ND-Parallel: A guide to Efficient Multi-GPU Training](https://swe.quest/articles/accelerate-nd-parallel-a-guide-to-efficient-multi-gpu-training-b84f16c2d8888d39.md): Hugging Face · 2025-08-08 · Hard · 18 min read · Model training, Distributed systems, Python
  Accelerate's ParallelismConfig, also exposed through Axolotl config fields, lets you compose data parallelism, FSDP, tensor parallelism and context parallelism in one training setup.

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)
