Skip to content
Accelerate ND-Parallel: A Guide to Efficient Multi-GPU Training
Source: huggingface.co

Accelerate ND-Parallel: A Guide to Efficient Multi-GPU Training

Sources: https://huggingface.co/blog/accelerate-nd-parallel, Hugging Face Blog

Overview

Training extremely large models across many GPUs requires more than just letting data flow through a single device. Accelerate, together with Axolotl, provides a quick and integrated way to compose multiple parallelism strategies in your training script. The goal is to minimize communication overhead while maximizing data throughput and memory efficiency as models scale to tens or hundreds of billions of parameters. The ND-Parallel approach blends data parallelism, memory-aware sharding, and model parallel strategies into a single, configurable workflow. In this paradigm, Data Parallelism (DP) is the top-most level: the model, gradients, and optimizer states are replicated across devices and data is evenly distributed. If the model is too large for one device, Fully Sharded Data Parallel (FSDP) shards weights, gradients, and optimizer states across GPUs, trading memory for communication. Tensor Parallel (TP) distributes linear computations across devices, while Context Parallel (CP) shards sequences so attention matrices grow less memory-heavy for long contexts. The framework also supports combining these strategies across nodes, creating a world size that grows with the number of devices in the cluster. Axolotl’s configuration model mirrors Accelerate’s ParallelismConfig, enabling users to set degrees for each strategy and how they are composed. As models scale to very long sequences or hundreds of billions of parameters, communication patterns and memory layout become the dominant bottlenecks. ND-Parallel is framed to help users reason about these trade-offs and select configurations that minimize inter-device communication while preserving throughput. The article walks through the behavior of DP, FSDP, TP, and CP, how they interact, and when to compose them to achieve practical training performance. You’ll also find a walkthrough of how model shards are gathered and reduced, how devices across nodes participate in all-reduces and reduce-scatters, and how the world size affects scaling. The end-to-end training script in the Accelerate repository demonstrates setting up the dataloader, optimizer, and training loop, and saving the trained model. The ND-Parallel capability is integrated into Axolotl for fine-tuning at scale, making it straightforward to add one or more parallelism strategies to your existing configs.

Key features

  • Compose multiple parallelism strategies (DP, FSDP, TP, CP) in a single training script via Accelerate and Axolotl.
  • Control the degree of each strategy using ParallelismConfig in Accelerate or via Axolotl config fields (e.g., dp_replicate_size, tp_size, dp_shard_size).
  • Top-level data parallelism (DP) replicates model, gradients, and optimizer states across devices and partitions data batches; supports multi-node setups.
  • Fully Sharded Data Parallel (FSDP) shards model weights, gradients, and optimizer states to fit large models; tuning granularity affects memory vs. communication trade-offs.
  • Tensor Parallel (TP) distributes linear layers’ computation across devices to achieve static memory partitioning without dynamic sharding during runtime; best within a single node due to higher inter-device communication.
  • Context Parallel (CP) shards sequences to mitigate attention memory growth for very long contexts, enabling training with large sequence lengths.
  • Cross-node scaling with both intra- and inter-node communication backends to support multi-node configurations while leveraging fast intra-node links (e.g., NVLink) and slower inter-node networks (e.g., Infiniband).
  • End-to-end training example in Accelerate and integration with Axolotl to streamline fine-tuning at scale.
  • Memory–compute trade-offs, including offloading options, to enable training larger models within practical hardware limits.

Common use cases

  • Fine-tuning or training models with tens to hundreds of billions of parameters across many GPUs.
  • Scenarios requiring very large context lengths (long-sequence fine-tuning) where attention memory dominates compute.
  • Users seeking to minimize communication overhead while maximizing data throughput by composing DP with FSDP, TP, and CP.
  • Settings where multi-node clusters are available and where a single-node approach cannot fit the model in memory.
  • Situations where Cy collaboration between Accelerate and Axolotl simplifies adding multiple parallelism strategies to existing training configs.

Setup & installation

The article references configuring and using Accelerate together with Axolotl, including an end-to-end training script in the Accelerate repository. It mentions the ParallelismConfig class in Accelerate and the corresponding Axolotl configuration fields to enable ND-Parallel, but does not provide exact setup commands in the excerpt.

Note: Exact installation and setup commands are not provided in the source excerpt. See the Accelerate repository and Axolotl documentation for concrete commands and configuration files.

# Setup & installation commands are not provided in the source excerpt.

Quick start

The piece points to a minimal runnable example in the Accelerate repository that demonstrates:

  • setting up a dataloader, an optimizer, and a training loop,
  • applying one or more ND-Parallel strategies via the ParallelismConfig (dp_replicate_size, tp_size, dp_shard_size),
  • and saving the trained model after training.

Quick-start code is not included in the provided excerpt. A minimal runnable example can be found in the Accelerate repo alongside the ND-Parallel configurations and Axolotl integration.

# Quickstart example not provided in the source excerpt.

Pros and cons

  • Pros
  • Enables training large models by combining data parallelism with memory-efficient sharding and model/sequence partitioning.
  • Reduces peak memory usage compared to full-data-parallel replication alone, through FSDP and CP strategies.
  • Can scale across multiple nodes, leveraging intra-node fast communication and inter-node networks for distributed training.
  • Flexible configuration via ParallelismConfig and Axolotl to tailor memory and compute trade-offs to the use case.
  • Cons
  • Complexity of configuration grows with the number of strategies and their interactions, requiring careful tuning.
  • FSDP across multiple nodes can incur high communication overhead; there is a recommended limit to avoid cross-full-node FSDP in some scenarios.
  • Tensor Parallel (TP) is most effective within a single node and can introduce synchronization overhead; use in combination with other strategies for multi-node setups.
  • Context Parallel (CP) adds additional data partitioning and may require custom data handling for long sequences.

Alternatives (brief comparisons)

| Approach | Notes | Typical use-case focus |---|---|---| | ND-Parallel (Accelerate + Axolotl) | Combines DP, FSDP, TP, CP under a unified config; end-to-end training script examples provided in the Accelerate repo | Large-scale training with multiple parallelism strategies in one pipeline |DeepSpeed ZeRO-3 | Memory savings via ZeRO-3 inspired sharding; strong single-system scaling, often used with MSAs | Very large models on multiple GPUs with ZeRO-based memory optimization |Single-node DP | Simple data-parallel replication on a single node | Models that fit within a single-node memory budget but require higher throughput |

Licensing or price

License information is not explicitly provided in the source excerpt.

References

More resources