Mesh-TensorFlow: Model Parallelism for Supercomputers (TF Dev Summit ‘19)

TensorFlow · Beginner ·🧠 Large Language Models ·7y ago

Key Takeaways

Mesh-TensorFlow is introduced as a language for specifying distributed tensor computations, allowing for model parallelism and data parallelism, and is demonstrated on the Transformer sequence-to-sequence model with up to 5 billion parameters on TPU meshes of up to 512 cores. The speaker, Noam Shazeer, discusses the limitations of batch-splitting and the benefits of Mesh-TensorFlow, including improved performance and scalability.

Full Transcript

[Music] uh hi my name is no shazir um I'm going to tell you about mesh tensor flow which is a system we built uh uh for training giant models on TPU pods so so we're going to talk about uh data parallelism and model parallelism and uh that also about why I want to train giant models and why we need model parallelism to do it then then I'll tell you about the mesh tensor flow system so first uh data parallelism this is how roughly everybody trains neural networks if you have uh distributed Hardware this is what we use on TPU Pods at Google um and generally you put your entire model on every device split up a training batch into a lot of little trunks one on each device run it then add all the gradients on the parameters across all the devices and do your update um this this works really well the communication is fast on on uh on our kinds of networks on lots of different types of networks in fact um so this is roughly what everyone's doing uh the great things about it are it's Universal you can use any model architecture um fast to compile because you're writing spmd code you're writing code for what one device is doing and then uh you can compile it and send it to every device uh which is using the same code and you get roughly full utilization because every device is doing roughly the same thing so if uh they're all similar then uh nobody's waiting for anybody else and uh the communication is f the the only problem is that you cannot train giant models because your entire model has to fit on every device so why do I want to train giant models well I like uh working on language modeling there are lots of important applications machine translation question answering uh dialogue sentimental analysis lots of interesting things to do with language and we find that quality improves with model size so a bigger model tends to know more about the world understand things better and give you overall better results there's plenty of data out there to train a giant model just download the text to the web common crawl whatever and uh and you've got uh you've got billions to trillions of words of training data and in fact you can train one big model and then F tuna to do lots of different things uh there's been a lot of research open Ai and bird at Google on um on transfer uh learning in language so it's a great candidate for building giant models now uh as an example I uh trained a Transformer language model with the roughly a 100 million parameters on the text of Wikipedia the Abraham Lincoln article was in the dev set in the heldout set and I told it to generate a random Abraham Lincoln article and it looks roughly grammatical uh remembers that somehow that he's a politician American politician there's plenty it doesn't know about the world like who Abraham Lincoln was or that America doesn't have a prime minister and lots of other stuff um but if you make the similar model just bigger here's with five billion parameters instead of 100 million and now it seems to have picked up a lot more about Abraham Lincoln roughly half of that stuff is correct but you know mostly it's fake news but there are more important uh applications out there than than generating fake news um but but this is just a nice demonstration that that model size is important um what would a model look like with a trillion parameters uh we have not done that yet but we hope to do to do that soon um okay so if all the parameters will not fit on One Core we need to do something called Model parallelism which means that we're splitting the model itself between different devices and that should let us train really large models and it should also be very good for inference latency because now the computation for one example can be split across multiple devices the problem is it's very tricky to design these kinds of algorithms um how do people tend to do it now well you use device placement you say this operation's going on this device this operation's going on that device tensor flow makes it easy to do that still It's tricky to design an efficient algorithm and you end up with a giant graph if you're generating enough operations to go on 2,000 different cores um here's an example of some uh model parallelism by device placement from uh Google neural machine trans ation they had eight lstms which they distributed across eight different gpus the softmax layer they put somewhere else and you need some kind of uh interesting pipelining to keep all the gpus busy it works but uh you know a lot of work to to get this thing to work right now we're going to take a totally different approach which is going to be inspired by what works well about synchronous data parallelism so we will have every processor involved in every operation uh we're going to use spmd style programming where you'll have the same program on every device and it's going to use Collective communication like all reduce um just like uh data parallelism um and the way and our library for doing this is called mesh tensorflow we should be able to implement data parallelism model parallelism we should be able to split in different dimensions like uh split a an image or video spatially or any sorts of combinations of these things and we're uh targeting Hardware where you have a homogeneous set of similar processors ideally um well connected like a TPU pod we've got these two-dimensional supercomputers at Google that we that we've been using uh and you're going to view your set of processors as an n-dimensional mesh it doesn't have to correspond to a physical n-dimensional mesh you could view a two dimensional mesh of processors is a one-dimensional mesh um but of course performance will depend on uh on those considerations so how does this all work well in data parallelism you can view it as splitting the batch dimension of the computation across all your processors so any tensor that has a batch Dimension is going to be split across all the processors and any tensor that does not have a batch Dimension meaning the uh meaning the parameters gets fully replicated now we're going to do the same thing but for model parallelism we will choose different dimensions to split so maybe Dimensions representing the sizes of hidden layers and we will decide to split those Dimensions across the uh set of processors so and the communication will happen us usually an operation will not involve communication but some operations will involve Collective commun communication like all reduce particularly when you're reducing outs split dimensions and this is going to be somewhat similar to how uh how things work in synchronous data parallelism okay so let's do an example a simple three layer neural network input layer x hidden layer H output layer Y and we have two weight matrices W and V the data parallel way to do this is that we're going to split anything with a batch Dimension meaning the activations x h and y so all of those tensors are split evenly across processors and each tensor that does not have a batch Dimension W and V will be replicated across every processor so here it's showing what processor zero is doing what processor one is doing they're both doing something roughly similar except they have different halves of the activations you don't see any communication in the forwards paths but if you were to see the backwards pass where you're Computing the parameter gradients you would see some mat moles where the split Dimension b gets uh gets reduced out and there would be some all reduces in there so we're going to now instead of splitting B let's split the size of the Hidden layer Dimension H so we do that and now X and Y the input and output are fully replicated because they do not have an H Dimension but the hidden layer H is split because it does have an H Dimension and the parameter matrices W and V also have an H Dimension so they're split so again you have a parallel computation on on the two processors and you see an all reduce communication when you're Computing why because we're reducing out the split Dimension H we didn't have to split H instead we could have split D which is the uh dimension of of X and Y so uh in that case you would have a different pattern of which tensors are split and which ones are replicated and you'd have communication in different places and if you want to get really fancy let's split let's let's do data parallelism and model parallelism at once we're going to split Dimension B the batch across one axis of our two-dimensional supercomputer and we're going to split the hidden layer H across the other axis of our mesh of processor so now we have different tensors being either split in one dimension and replicated in the other or the or since tensor H has both of those Dimensions it ends up tiled among all the processors and there are going to be all reduced Communications in there um but not across all the processors they'll be partitioned all reduces just across rows or just across columns so the general case is give all of the tensor Dimensions names and the we Define the layout of the communication as a map from tensor Dimensions to mesh Dimensions saying which tensor Dimensions get split across which mesh dimensions for example in the previous slide we had the batch tensor Dimension split across processor rows and the hidden size dimension split across processor columns we did this to our Transformer machine translation language mod model and here are the layouts we use for data parallelism model parallelism and combined parallelism for that uh for the model parallelism it works to split the size of the vocabulary the size of the feedforward Hidden layer and the number of attention heads and if you do that you end up splitting up all of your communication very nicely and and get a nice model parallel algorithm and that can also be combined with data parallelism by splitting the batch across the other dimension of the supercomputer now picking a good layout is for now something that you need a well-trained human to do uh you need to make sure that all of your expensive operations are split you're not allowed to split the same two dimensions of the same tensor across different dimensions of the mesh uh and depending on what dimensions you chop up it may result in more or less communication so example model data parallelism you'd like the batch to be big otherwise you're going to get a lot of communication similarly if you're splitting up a hidden layer you might want that layer to be really big um so how do you use mesh tensor flow well download our open- source repository you build a graph in Python much like a regular tensorflow graph uh except that you're using named Dimensions um you define what your mesh is and how it maps to your physical processors uh you define your layout of what gets split across what and then mesh tensorflow turns your mesh tensor flow graph into part of a tensor flow graph and you still use tensorflow for anything else you want to use it for like the data pipelines and everything else um so so far we've trained Transformer models on with up to five billion parameters on entire TPU pods getting uh good performance out of the thing um and uh these giant models give state-of-the-art quality on on uh on some Benchmark tasks like in language modeling and machine translation not surprisingly uh bigger models are better lots of people are finding that out um and in the future we would like to try even bigger models uh I think with some uh well-placed uh sparsity we we would have the computation to train models with a trillion parameters we've tried up to a couple hundred billion for now and it runs um so next thing is uh see if we can get a trillion parameter model to run and give us great quality and um this should be useful for other things like low latency inference and situations where you have giant um uh inputs that you want to process and for now what works well we have uh we're emitting spmd code for uh for TPU including Cloud TPU so this runs nicely on TPU pods and um for CPU and GPU it's still emitting the oldfashioned device placement code so it runs but not as scalable um everything is out there on GitHub and uh runs with tensor flow one not yet with tensorflow two uh we're uh and then uh in the future we want to uh use this for different types of models it would be great to automate the process of choosing a distributed layout because then you wouldn't need to know about mesh tensor flow and it would just figure out how to distribute your computation for you uh and we welcome uh contributions to the open source code uh or um just contact us and um I'd like to thank uh all of my collaborators uh the the authors of uh of our uh paper um also like to thank the tensorflow teams and xlaa team for uh for a lot of technical support and help with all of this implementing what we needed to be implemented and uh everything's out there in our our open source repository uh thank you [Music]

Original Description

Batch-splitting (data-parallelism) is the dominant distributed Deep Neural Network (DNN) training strategy, due to its universal applicability and its amenability to Single-Program-Multiple-Data (SPMD) programming. However, batch-splitting suffers from problems including the inability to train very large models (due to memory constraints), high latency, and inefficiency at small batch sizes. All of these can be solved by more general distribution strategies (model-parallelism). Unfortunately, efficient model-parallel algorithms tend to be complicated to discover, describe, and to implement, particularly on large clusters. We introduce Mesh-TensorFlow, a language for specifying a general class of distributed tensor computations. Where data-parallelism can be viewed as splitting tensors and operations along the "batch" dimension, in Mesh-TensorFlow, the user can specify any tensor-dimensions to be split across any dimensions of a multi-dimensional mesh of processors. A Mesh-TensorFlow graph compiles into a SPMD program consisting of parallel operations coupled with collective communication primitives such as Allreduce. We use Mesh-TensorFlow to implement an efficient data-parallel, model-parallel version of the Transformer sequence-to-sequence model. Using TPU meshes of up to 512 cores, we train Transformer models with up to 5 billion parameters, surpassing state of the art results on WMT'14 English-to-French translation task and the one-billion-word language modeling benchmark. Mesh-Tensorflow is available at https://github.com/tensorflow/mesh . Speaker: Noam Shazeer, Google See the revamped dev site → https://www.tensorflow.org/ Watch all TensorFlow Dev Summit '19 sessions → http://bit.ly/TFDS19Sessions Subscribe to the TensorFlow YouTube channel → https://bit.ly/TensorFlow1 Music by Terra Monk → http://bit.ly/TerraMonkTFDS Event Photo Album → http://bit.ly/TFSummit19 event: TensorFlow Dev Summit 2019; re_ty: Publish; product: TensorFlow - TensorFlow Cor
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from TensorFlow · TensorFlow · 0 of 60

← Previous Next →
1 The TensorFlow YouTube Channel is Here!
The TensorFlow YouTube Channel is Here!
TensorFlow
2 Answering Your TF Questions #AskTensorFlow
Answering Your TF Questions #AskTensorFlow
TensorFlow
3 Chatting With the TensorFlow Community (TensorFlow Meets)
Chatting With the TensorFlow Community (TensorFlow Meets)
TensorFlow
4 All About TensorFlow Code (Coding TensorFlow)
All About TensorFlow Code (Coding TensorFlow)
TensorFlow
5 TensorFlow: an ML platform for solving impactful and challenging problems
TensorFlow: an ML platform for solving impactful and challenging problems
TensorFlow
6 Keynote (TensorFlow Dev Summit 2018)
Keynote (TensorFlow Dev Summit 2018)
TensorFlow
7 tf.data: Fast, flexible, and easy-to-use input pipelines (TensorFlow Dev Summit 2018)
tf.data: Fast, flexible, and easy-to-use input pipelines (TensorFlow Dev Summit 2018)
TensorFlow
8 Eager Execution (TensorFlow Dev Summit 2018)
Eager Execution (TensorFlow Dev Summit 2018)
TensorFlow
9 Machine Learning in JavaScript (TensorFlow Dev Summit 2018)
Machine Learning in JavaScript (TensorFlow Dev Summit 2018)
TensorFlow
10 Training Performance: A user’s guide to converge faster (TensorFlow Dev Summit 2018)
Training Performance: A user’s guide to converge faster (TensorFlow Dev Summit 2018)
TensorFlow
11 The Practitioner's Guide with TF High Level APIs (TensorFlow Dev Summit 2018)
The Practitioner's Guide with TF High Level APIs (TensorFlow Dev Summit 2018)
TensorFlow
12 Distributed TensorFlow (TensorFlow Dev Summit 2018)
Distributed TensorFlow (TensorFlow Dev Summit 2018)
TensorFlow
13 Debugging TensorFlow with TensorBoard plugins (TensorFlow Dev Summit 2018)
Debugging TensorFlow with TensorBoard plugins (TensorFlow Dev Summit 2018)
TensorFlow
14 TensorFlow Lite (TensorFlow Dev Summit 2018)
TensorFlow Lite (TensorFlow Dev Summit 2018)
TensorFlow
15 Searching Over Ideas (TensorFlow Dev Summit 2018)
Searching Over Ideas (TensorFlow Dev Summit 2018)
TensorFlow
16 Reconstructing Fusion Plasmas (TensorFlow Dev Summit 2018)
Reconstructing Fusion Plasmas (TensorFlow Dev Summit 2018)
TensorFlow
17 Nucleus: TensorFlow toolkit for Genomics (TensorFlow Dev Summit 2018)
Nucleus: TensorFlow toolkit for Genomics (TensorFlow Dev Summit 2018)
TensorFlow
18 Open Source Collaboration (TensorFlow Dev Summit 2018)
Open Source Collaboration (TensorFlow Dev Summit 2018)
TensorFlow
19 Swift for TensorFlow - TFiwS (TensorFlow Dev Summit 2018)
Swift for TensorFlow - TFiwS (TensorFlow Dev Summit 2018)
TensorFlow
20 TensorFlow Hub (TensorFlow Dev Summit 2018)
TensorFlow Hub (TensorFlow Dev Summit 2018)
TensorFlow
21 Applied AI at The Coca-Cola Company (TensorFlow Dev Summit 2018)
Applied AI at The Coca-Cola Company (TensorFlow Dev Summit 2018)
TensorFlow
22 Real-World Robot Learning (TensorFlow Dev Summit 2018)
Real-World Robot Learning (TensorFlow Dev Summit 2018)
TensorFlow
23 TensorFlow Extended (TFX) (TensorFlow Dev Summit 2018)
TensorFlow Extended (TFX) (TensorFlow Dev Summit 2018)
TensorFlow
24 Project Magenta (TensorFlow Dev Summit 2018)
Project Magenta (TensorFlow Dev Summit 2018)
TensorFlow
25 TensorFlow Dev Summit 2018 - Livestream
TensorFlow Dev Summit 2018 - Livestream
TensorFlow
26 Introducing TensorFlow Lite (Coding TensorFlow)
Introducing TensorFlow Lite (Coding TensorFlow)
TensorFlow
27 TensorFlow Dev Summit 2018 Highlights
TensorFlow Dev Summit 2018 Highlights
TensorFlow
28 Jeff Dean, Head of AI at Google discusses the impact of ML (TensorFlow Meets)
Jeff Dean, Head of AI at Google discusses the impact of ML (TensorFlow Meets)
TensorFlow
29 TensorFlow Mobile vs. TF Lite and More! #AskTensorFlow
TensorFlow Mobile vs. TF Lite and More! #AskTensorFlow
TensorFlow
30 Using TensorFlow to enable research & production across many fields (TensorFlow Meets)
Using TensorFlow to enable research & production across many fields (TensorFlow Meets)
TensorFlow
31 Teaching TensorFlow for Deep Learning at Stanford University (TensorFlow Meets)
Teaching TensorFlow for Deep Learning at Stanford University (TensorFlow Meets)
TensorFlow
32 TensorFlow Lite for Android (Coding TensorFlow)
TensorFlow Lite for Android (Coding TensorFlow)
TensorFlow
33 Using the tf.data API to build input pipelines (TensorFlow Meets)
Using the tf.data API to build input pipelines (TensorFlow Meets)
TensorFlow
34 Training Models in the Cloud & the Benefits of AI Toolkits #AskTensorFlow
Training Models in the Cloud & the Benefits of AI Toolkits #AskTensorFlow
TensorFlow
35 Execute operations immediately with TensorFlow's Eager Execution (TensorFlow Meets)
Execute operations immediately with TensorFlow's Eager Execution (TensorFlow Meets)
TensorFlow
36 TensorFlow Lite for iOS (Coding TensorFlow)
TensorFlow Lite for iOS (Coding TensorFlow)
TensorFlow
37 Get started with TensorFlow's High-Level APIs (Google I/O '18)
Get started with TensorFlow's High-Level APIs (Google I/O '18)
TensorFlow
38 TensorFlow for JavaScript (Google I/O '18)
TensorFlow for JavaScript (Google I/O '18)
TensorFlow
39 TensorFlow in production: TF Extended, TF Hub, and TF Serving (Google I/O '18)
TensorFlow in production: TF Extended, TF Hub, and TF Serving (Google I/O '18)
TensorFlow
40 Get started with TensorFlow's High-Level APIs in 5 mins |  Google I/O 2018
Get started with TensorFlow's High-Level APIs in 5 mins | Google I/O 2018
TensorFlow
41 TensorFlow and deep reinforcement learning, without a PhD (Google I/O '18)
TensorFlow and deep reinforcement learning, without a PhD (Google I/O '18)
TensorFlow
42 TensorFlow Lite for mobile developers (Google I/O '18)
TensorFlow Lite for mobile developers (Google I/O '18)
TensorFlow
43 Advances in machine learning and TensorFlow (Google I/O '18)
Advances in machine learning and TensorFlow (Google I/O '18)
TensorFlow
44 Distributed TensorFlow training (Google I/O '18)
Distributed TensorFlow training (Google I/O '18)
TensorFlow
45 Classification using neural networks & ML regression models #AskTensorFlow
Classification using neural networks & ML regression models #AskTensorFlow
TensorFlow
46 TensorFlow and Keras in R - Josh Gordon meets with J.J. Allaire (TensorFlow Meets)
TensorFlow and Keras in R - Josh Gordon meets with J.J. Allaire (TensorFlow Meets)
TensorFlow
47 Focus on your experiment with TensorFlow Estimators (TensorFlow Meets)
Focus on your experiment with TensorFlow Estimators (TensorFlow Meets)
TensorFlow
48 How to get started with AI/ML, retraining models, & more! #AskTensorFlow
How to get started with AI/ML, retraining models, & more! #AskTensorFlow
TensorFlow
49 TensorFlow - the deep learning solution for mobile platforms (TensorFlow Meets)
TensorFlow - the deep learning solution for mobile platforms (TensorFlow Meets)
TensorFlow
50 MiniGo: TensorFlow Meets Andrew Jackson (TensorFlow Meets)
MiniGo: TensorFlow Meets Andrew Jackson (TensorFlow Meets)
TensorFlow
51 The growth of TensorFlow with added support for JS & Swift (TensorFlow Meets)
The growth of TensorFlow with added support for JS & Swift (TensorFlow Meets)
TensorFlow
52 At the intersection of TensorFlow & nuclear physics (TensorFlow Meets)
At the intersection of TensorFlow & nuclear physics (TensorFlow Meets)
TensorFlow
53 NVidia TensorRT: high-performance deep learning inference accelerator (TensorFlow Meets)
NVidia TensorRT: high-performance deep learning inference accelerator (TensorFlow Meets)
TensorFlow
54 Try TensorFlow.js in your browser (Coding TensorFlow)
Try TensorFlow.js in your browser (Coding TensorFlow)
TensorFlow
55 TensorFlow Hub: reusing machine learning modules (TensorFlow Meets)
TensorFlow Hub: reusing machine learning modules (TensorFlow Meets)
TensorFlow
56 How to use TensorFlow in PyCharm (TensorFlow Tip of the Week)
How to use TensorFlow in PyCharm (TensorFlow Tip of the Week)
TensorFlow
57 Training models faster with TensorFlow Hub (TensorFlow Meets)
Training models faster with TensorFlow Hub (TensorFlow Meets)
TensorFlow
58 Prepare your dataset for machine learning (Coding TensorFlow)
Prepare your dataset for machine learning (Coding TensorFlow)
TensorFlow
59 Using ML to predict insulin use for Type 1 Diabetes (TensorFlow Meets)
Using ML to predict insulin use for Type 1 Diabetes (TensorFlow Meets)
TensorFlow
60 TFX: an end-to-end machine learning platform for TensorFlow (TensorFlow Meets)
TFX: an end-to-end machine learning platform for TensorFlow (TensorFlow Meets)
TensorFlow

Mesh-TensorFlow is a language for specifying distributed tensor computations, enabling model parallelism and data parallelism for large-scale deep learning models. The speaker demonstrates its application on the Transformer sequence-to-sequence model, achieving state-of-the-art results. This lesson teaches the basics of Mesh-TensorFlow and its benefits for LLM training.

Key Takeaways
  1. Install Mesh-TensorFlow from GitHub
  2. Understand the basics of SPMD programming
  3. Split tensors and operations along any dimension using Mesh-TensorFlow
  4. Implement data-parallel and model-parallel versions of the Transformer sequence-to-sequence model
  5. Train large-scale LLMs using TPU meshes and Mesh-TensorFlow
💡 Mesh-TensorFlow enables efficient model parallelism and data parallelism for large-scale deep learning models, overcoming the limitations of batch-splitting and achieving state-of-the-art results.

Related Reads

Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →