AI/ML, Cloud Computing, Data Analytics

4 Mins Read

Efficient Neural Network Training with FSDP

Voiced by Amazon Polly


Training large AI models has become a powerful tool as it is one of the complicated tasks while developing an AI model and also requires significant computing resources. Imagine training a massive neural network with billions of parameters, like a complex language model. Here’s what it needs:

  1. Lots of Data: These models learn from vast amounts of data, like text or images.
  2. Heavy Computing Power: Processing all this data requires significant computing power, often in the form of multiple GPUs.
  3. Memory: The model itself can be enormous, and it must have a lot of memory to store its parameters, i.e., weights and biases that influence its decisions.

Keeping these in mind, training such models comes with a lot of hurdles, such as:

  1. Memory Bottleneck: A single GPU might not have enough memory to hold the entire model. It limits the size and increases the complexity of training.
  2. Data Parallelism Bottleneck: This technique distributes the model across multiple GPUs, but it replicates the entire model on each one, causing memory redundancy.
  3. Communication Overhead: As Data Parallelism occurs, GPUs must constantly communicate updates, which will slow down the process, especially with large models.

To overcome these challenges, a technique called ‘Fully Sharded Data Parallel (FSDP)’ was designed to train even larger models efficiently.

Introduction to FSDP

FSDP, Fully Sharded Data Parallel, is a distributed training technique that efficiently trains large neural networks on multiple GPUs or machines. A shard means one portion. FSDP addresses the memory limitations of traditional Distributed Data Parallelism techniques, where each GPU holds a full copy of the model’s parameters.

Let’s break down these terms to understand the core concept of FSDP:

  • Fully Sharded: This refers to how FSDP divides the model’s parameters (weights and biases) into smaller pieces called shards. Each GPU in the training process holds only its assigned shards, significantly reducing memory usage per GPU.
  • Data Parallel: This is a common technique for training large models on multiple GPUs. Each GPU gets a different batch of data to process, and the results are combined to update the model parameters. Even though FSDP builds upon this same concept, it brings a new element to the table called the sharding element to address memory limitations.

There are various ways of incorporating FSDP into our AI model training, which includes:

  • PyTorch API: PyTorch provides the primary API for FSDP training. This API offers a convenient way to wrap different models together and control sharding behavior.
  • Hugging Face Library: ‘Accelerate’, available on the Hugging Face Platform, provides a higher-level abstraction on top of FSDP. It allows users to set up simple configurations and integrates with other deep learning frameworks such as PyTorch and TensorFlow.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

How does FSDP Work?

At a high level, FSDP works as follows:

  1. Sharding the Model (Constructor): FSDP divides the model parameters into smaller chunks during initialization. Each worker gets assigned a unique shard.
  2. Forward Pass:
    1. Gathering the Shards: Before performing the forward computation, FSDP gathers all parameter shards from all workers to reconstruct the complete model parameters for that specific FSDP unit.
    2. Computation: The forward pass is executed once the full parameters are available.
    3. Discarding the Shards: After the computation, the temporary, gathered parameters are discarded, freeing up memory for the next step.
  3. Backward Pass:
    1. Gathering the Shards again: Similar to the forward pass, FSDP gathers all parameter shards to create the complete set for backward computation.
    2. Backpropagation: The backward pass calculates the gradients for the loss function.
    3. Distributing the Gradients: FSDP utilizes a “reduce-scatter” operation to distribute the calculated gradients efficiently across all workers. Each worker receives a portion of the updated gradients relevant to its shard.
    4. Cleaning Up: As with the parameters, the temporarily gathered parameters are discarded after processing.

Benefits and Drawbacks of FSDP

In addition to the above discussed bottlenecks, below are the advantages we get by using FSDP to train large models:

  1. Shard Management: FSDP acts as a controller, assigning shards to different GPUs and managing their updates. This ensures all GPUs collaborate effectively to train the model.
  2. No Redundancy: Unlike other Data Parallel mechanisms, FSDP avoids replicating the entire model, and instead, each GPU only holds its assigned shard, saving the memory.
  3. Smarter Communication: FSDP optimizes communication between GPUs. It considers communication and computation a single unit, allowing for more efficient training.
  4. Flexibility: FSDP offers different sharding strategies for customizing how parameters are split. This allows you to tailor the approach to your specific model architecture and hardware setup.

While FSDP is a powerful tool to train massive models, which offers several advantages, it also comes with a few drawbacks that require careful consideration, such as:

  1. Impact on Training Speed: Increased communication can slow the training speed, particularly if the network bandwidth is limited or the model has frequent parameter updates. While FSDP overlaps communication and computation, this overhead might still be significant.
  2. Tuning of Network Topology: The FSDP’s optimal communication performance also depends on the network topology, such as the physical layout of GPUs. FSDP might require tuning the setup, including architecture and hardware, to minimize communication bottlenecks.
  3. Limited Inference Support: while FSDP is efficient at training large models, it is not optimized for low-latency inference tasks. The sharding process may become overhead while running the model for predictions.
  4. Code Debugging: Using FSDP often involves code modifications to modules and configuring sharding strategies. This will introduce complexity and debugging challenges compared to traditional Data Parallel mechanisms.


In conclusion, FSDP’s ability to train massive models opens a new chapter in deep learning. It empowers researchers to explore other AI territories, potentially leading to groundbreaking advancements that shape the future of artificial intelligence.

Drop a query if you have any questions regarding FSDP and we will get back to you quickly.

Empowering organizations to become ‘data driven’ enterprises with our Cloud experts.

  • Reduced infrastructure costs
  • Timely data-driven decisions
Get Started

About CloudThat

CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 650k+ professionals in 500+ cloud certifications and completed 300+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery PartnerAWS Microsoft Workload PartnersAmazon EC2 Service Delivery Partner, and many more.

To get started, go through our Consultancy page and Managed Services PackageCloudThat’s offerings.


1. When should I use FSDP over DDP?

ANS: – Use FSDP when training a model that wouldn’t fit on a single GPU’s memory with DDP. FSDP is efficient when dealing with very large models or when you want to leverage larger batch sizes for faster training.

2. Does FSDP always improve training speed?

ANS: – While FSDP is good for larger models, the increased communication overhead can impact training speed. This trade-off depends on your specific model, hardware setup, and dataset size.

WRITTEN BY Yaswanth Tippa

Yaswanth Tippa is working as a Research Associate - Data and AIoT at CloudThat. He is a highly passionate and self-motivated individual with experience in data engineering and cloud computing with substantial expertise in building solutions for complex business problems involving large-scale data warehousing and reporting.



    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!