Mesh-TensorFlow: Deep Learning for Supercomputers

Noam Shazeer, Youlong Cheng, Niki Parmar, Dustin Tran, Ashish Vaswani, Penporn Koanantakool, Peter Hawkins, HyoukJoong Lee, Mingsheng Hong, Cliff Young, Ryan Sepassi, Blake A. Hechtman

TL;DR

Mesh-TensorFlow is a powerful language extension that moves beyond simple data parallelism by allowing developers to split any tensor dimension across a multi-dimensional mesh of processors. This framework enabled the training of massive Transformer models with up to 5 billion parameters, setting new state-of-the-art records in language modeling and translation.

The Limits of Data Parallelism

In the world of distributed deep learning, data parallelism (or batch-splitting) is king. It’s simple: you give every processor a copy of the model and a different slice of the data. However, this approach hits a wall when models get too big. If a model’s parameters and activations exceed the memory of a single chip (like a GPU or TPU), data parallelism simply fails.

The alternative is model parallelism, where the model itself is split across devices. While effective, model parallelism is notoriously difficult to implement. Developers often have to manually write complex communication code, and the resulting programs are frequently inefficient or hard to optimize for large clusters. The authors sought a way to make complex distribution strategies as easy to specify as standard data-parallel ones.

Enter Mesh-TensorFlow

The authors introduced Mesh-TensorFlow, a language for specifying general distributed tensor computations. Its core innovation lies in two abstractions:

  1. Named Dimensions: Unlike standard TensorFlow where dimensions are just indices (0, 1, 2), Mesh-TensorFlow gives them names (e.g., "batch", "hidden", "heads").
  2. Processor Meshes: It treats a cluster of processors as an $n$-dimensional grid (a "mesh") with its own named dimensions (e.g., "rows", "cols").

By defining a computation layout—a simple mapping of tensor dimensions to mesh dimensions—the user can decide exactly how data is distributed. For example, mapping the "batch" dimension to the "rows" mesh dimension creates data parallelism. Mapping the "hidden" dimension to the "cols" mesh dimension creates model parallelism.

Performance characteristics of different computation layouts in Mesh-TensorFlow.

The system then automatically compiles these high-level descriptions into a Single-Program-Multiple-Data (SPMD) program. This program runs the same operations on every processor but handles the necessary collective communication (like Allreduce) behind the scenes to ensure the math remains correct.

Key Insights and Scaling Efficiency

  • Generalized Parallelism: The "aha moment" is that data parallelism is just a special case of a much broader class of distribution strategies. By naming dimensions, we can split any part of the computation (like the hidden layers or attention heads) just as easily as we split the batch.
  • Efficiency at Scale: By combining data and model parallelism on a 2D mesh, developers can scale the number of processors quadratically while only needing to increase the batch size and model size linearly to maintain high efficiency.
  • Model Size Matters: As you scale the Transformer to billions of parameters using Mesh-TensorFlow, performance continues to improve significantly without hitting a plateau.

Unprecedented Results

The researchers evaluated Mesh-TensorFlow by scaling up the Transformer architecture on several major benchmarks, including WMT’14 English-to-French, the One-Billion-Word Benchmark (LM1B), and a massive 5-billion-token Wikipedia dataset.

Language modeling performance scaling with model size up to 5 billion parameters.

The results demonstrated that Mesh-TensorFlow could handle models of unprecedented size:

  • Massive Scale: They successfully trained a Transformer with 5 billion parameters on TPU meshes of up to 512 cores.
  • Language Modeling Record: On the One-Billion-Word benchmark, they achieved a perplexity of 23.5, a significant improvement over the previous best of 26.1.
  • Translation Record: On the WMT’14 English-to-French task, their largest model achieved a BLEU score of 43.9, surpassing the previous state-of-the-art.
  • Hardware Utilization: On their largest models, they maintained over 50% computational efficiency (achieving 6 PFLOP/s out of a theoretical 11.5 PFLOP/s), proving that the framework isn't just flexible, but also highly performant.

Limitations and Future Work

While Mesh-TensorFlow simplifies the implementation of model parallelism, it still requires the user to choose the layout. The authors noted that an automated search for the optimal computation layout would be a valuable future addition.

Additionally, the initial implementation focused on dense tensors. Supporting spatial partitioning (useful for large-scale image processing and convolutions) would require implementing "halo" regions—where processors exchange the edges of their data slices—which was not covered in this paper. Finally, extending full SPMD support to more heterogeneous CPU/GPU clusters remains an ongoing goal.

Summary updated

BibTeX
@inproceedings{shazeer2018mesh,
  author = {Noam Shazeer and Youlong Cheng and Niki Parmar and Dustin Tran and Ashish Vaswani and Penporn Koanantakool and Peter Hawkins and HyoukJoong Lee and Mingsheng Hong and Cliff Young and Ryan Sepassi and Blake A. Hechtman},
  title = {{Mesh-TensorFlow: Deep Learning for Supercomputers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
  url = {https://openreview.net/forum?id=Sy-bSDbd-B},
}
Figure