---
title: "From DeepSpeed to FSDP and Back Again with Hugging Face Accelerate"
description: "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."
url: "https://swe.quest/articles/from-deepspeed-to-fsdp-and-back-again-with-hugging-face-accelerate-15016dbd4b4a46b2"
canonical: "https://huggingface.co/blog/deepspeed-to-fsdp-and-back"
source: "Hugging Face"
published: "2024-06-13"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 6
tags: ["model-training","machine-learning","python"]
---

# From DeepSpeed to FSDP and Back Again with Hugging Face Accelerate

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-06-13, 6 min read, Deep dive. Original: [https://huggingface.co/blog/deepspeed-to-fsdp-and-back](https://huggingface.co/blog/deepspeed-to-fsdp-and-back)

## Summary

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. That made the same learning rate converge on one backend and stall on the other. Hugging Face Accelerate 0.30.0 adds automatic fp32 upcasting for FSDP when mixed precision is enabled, so FSDP can run either in a DeepSpeed-like mixed-precision mode or in a low-precision mode for memory-constrained setups. In that aligned mode, throughput on four A100s with Granite 7B is roughly equal: about 3159 vs 3095 tokens/sec/GPU and an MFU of 0.41 vs 0.40.

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)

## Prerequisites

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

## Keywords

Hugging Face Accelerate, DeepSpeed, PyTorch FSDP, ZeRO, bfloat16, Mistral-7B, IBM Granite

## 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.
- [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.
- [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 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.
- [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.

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)
