Amazon SageMaker Model Parallelism: A General and Flexible Framework for Large Model Training

Can Karakus, Rahul Huilgol, Fei Wu, Anirudh Subramanian, Cade Daniel, Derya Çavdar, Teng Xu, Haohan Chen, Arash Rahnama, Luis QuintelaarXiv 2021

Introduction

As deep learning models scale toward billions and trillions of parameters, they inevitably exceed the memory capacity of individual GPUs. This necessitates model parallelism—the distribution of a model's weights and computation across multiple devices. While existing frameworks like Megatron-LM and DeepSpeed provide solutions for standard transformer architectures, they often lack the flexibility required for non-standard models, such as those with conditional execution flows or massive embedding tables. The Amazon SageMaker model parallelism library addresses these challenges with a general, architecture-agnostic framework integrated directly into PyTorch.

Methods: Module-Server and Auto-Partitioning

The library shifts away from the traditional view of a model as a flat sequence of layers. Instead, it treats the model as a hierarchy of PyTorch nn.Module objects. Each GPU operates as an "execution server." When a module assigned to a different GPU is encountered during the forward or backward pass, the local server sends a dynamic execution request to the target device.

Module-Server Request-Response Paradigm

This request-response paradigm allows the framework to support dynamic computational graphs, such as if/else blocks, without requiring a static, pre-compiled schedule. To optimize this distribution, the library includes an auto-partitioning algorithm. It profiles the memory and compute costs of modules through a "tracing" step and uses the D'Hondt method—a proportional allocation algorithm—to balance the workload across available GPUs.

Hybrid Parallelism and Communication

To maximize hardware utilization, the library supports a sophisticated combination of data parallelism (DP), pipeline parallelism (PP), and tensor parallelism (TP). A key innovation is the ability to overlap TP with DP ranks. For models with specific large components, such as massive embedding tables in recommendation systems, the library can split that component across GPUs (TP) while allowing those same GPUs to process different data batches for the rest of the model (DP).

Parallelism Grouping Strategy

Because this dynamic execution can lead to out-of-order communication that might deadlock standard libraries like NCCL, the authors developed a custom Device-to-Device (D2D) backend. Utilizing NVLink and GPUDirect RDMA, this backend handles asynchronous tensor routing efficiently.

Key Results

The framework demonstrates high scalability and performance across various model architectures on AWS infrastructure:

  • NLP Throughput: For a 10B parameter RoBERTa model, the library achieved 385 sequences/second on 16 nodes, a 39% improvement over DeepSpeed. On a 175B parameter GPT-3 model, it scaled to 960 NVIDIA A100 GPUs, maintaining a throughput of 26.5 sequences per second.
  • Recommendation Systems: In evaluations of Neural Collaborative Filtering (NCF) models with massive embedding tables, the TP-over-DP approach provided a 2.5x speedup compared to standard Megatron-style baselines.

Conclusion

The Amazon SageMaker model parallelism library provides a flexible and performant alternative to architecture-specific distributed training tools. By prioritizing a hierarchical module view and dynamic execution, it enables researchers to scale complex, non-standard models with minimal code changes. While the initial tracing step presents a potential bottleneck for multi-trillion parameter models, the framework's general-purpose design represents a significant step toward more accessible large-scale model training.

Summary updated

BibTeX
@misc{karakus2021amazon,
  author = {Can Karakus and Rahul Huilgol and Fei Wu and Anirudh Subramanian and Cade Daniel and Derya Çavdar and Teng Xu and Haohan Chen and Arash Rahnama and Luis Quintela},
  title = {{Amazon SageMaker Model Parallelism: A General and Flexible Framework for Large Model Training}},
  year = {2021},
  eprint = {2111.05972},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2111.05972},
}
Figure