Carbon-Aware Dynamic Parallelism for Distributed Training
This transcript was made by AI. The open source speech recognition model Whisper (large-v3-turbo) transcribed the recording with faster-whisper. Names and technical terms were checked against the paper, but it can still contain mistakes. The recording is the reference.
0:03 And our final speaker for this session will be Wafik Aboualim from University of Pittsburgh. Wafik will be telling us about Carbon Aware Dynamic Parallelism for Distributed Training. Hi, everyone. Today, I'll be talking about our work, Carbon Aware Dynamic Parallelism for Distributed Training. This is joint work between me and Stephen Lee. So, pre-training is carbon intensive. GPT-3 pre-training is estimated to emit approximately 525 tons of CO2. Meta reports that the training of the llama family costs approximately 11,390 tons of CO2. And as the models scale, we expect that cost to become increasingly more significant. So, there has been, like, multiple approaches in reducing the carbon emissions of jobs. The three main ones were temporal shifting, where you take a job and you run it in a lower intensity period.
1:14 And there's spatial shifting, where you move training to a lower carbon region. And there's elastic scaling, which has been the most recent line of work, which thinks about changing the accelerator count. And that assumes that resources can be released and acquired. Our setting is a little bit different. We sort of assume that the time, location, and accelerator allocation is fixed. And we think about another knob, which is how to change how the workload is being distributed across the accelerators. So, distributed training is the standard. Of course, training large models require multiple accelerators working in parallel. There are three modes of parallelism that are used. The first one is data parallelism, which you basically copy the model over to multiple accelerators and you split the batch size.
2:06 And you do an all-gather, basically. And there's tensor parallelism, where you split the actual computation within each layer within the network. And there's pipeline parallelism, where you split the layers across multiple stages. And it turns out that your choice of parallelism strategy can affect both the power and throughput. So, for tensor parallelism, splitting each layer across the accelerators, it happens that the communication is during forward and the backward passes. But for pipeline parallelism, it splits layers into stages and passes activations and gradients between stages for each micro-batch. Data parallelism is a little bit different. It processes different batch shards and then it averages the gradient through an all-reduce. So, the key idea is each one of these strategies has a different computing communication pattern.
3:04 So, here's an example. So, let's say that you're training a model over eight accelerators. Let's say that you choose your data parallelism dimension to be two, dp equals two. So, that means you're going to copy over the model over to two accelerators. And let's say that you choose your tensor parallelism dimension to be two. Then that means that you're going to take each layer and split it in half between two accelerators. As for the pipeline parallelism, if you choose your dimension to be two, then that means that you're going to split your network into two stages. And it turns out that this constraint has to hold where the product of all the parallelism dimensions has to equal the total number of GPUs that you have.
3:51 So, in our case, two times two times two is eight. So, dynamic parallelism has been a recent line of work where they think about changing the layout of the parallelism during the job, basically. So, instead of choosing one fixed setup at launch, the system can switch between different ways of splitting the work between accelerators. And as we looked before, since each of the parallelism layouts has a different pattern of communication and computations, then that means that changing that layout is going to result in a different power and throughput. So, more data parallelism is generally more compute bound, but the gradient synchronization grows at a large scale. For a tensor parallelism, which we consider to be generally more communication bound. This is because the communication happens within each layer of the network.
4:49 Pipeline parallelism is a little bit in between. However, increasing the pipeline dimension way too much can introduce pipeline bubbles. So, we did a lot of profiling. Our setup was as follows. We thought about a single node. We used four NVIDIA L40s, GPUs, and for the multi-node, we used the NVIDIA A100 nodes. I think we scaled our nodes from two to eight nodes when each node has four GPUs. As for the training stack, we used Megatron Core to do distributed training. And for the power and throughput measurements, we used NVML. So, for each setup, we sweep the valid TPPDP configurations across three models. So, we thought about GPT-2, LLAMA, and Pythia, and we did these profiling. And basically, if you look here, for example, in the GPT2 model, it looks like for the DP4, it has the highest average steady power.
6:07 However, that trend does not follow for the LLAMA model, for example, which you can see that the PP2, DP2 has the highest average steady power. And you can also see that this trend differs between the sizes of the models. So, for example, for the LLAMA model, you can see that the 1B, DP4, is the highest average steady power. But as you scale the size of the LLAMA family, you can see that PP2, DP2 starts to dominate. So, the takeaway is the power draw depends not only on the parallel configuration, but it also depends on the model family and architecture. So, same thing can be said for throughput. So, as you can see here, GPT2, DP4 has the highest throughput. However, if we look at the LLAMA family, it seems the more we scale the size of the model, PP2, DP2 seems to dominate the throughput.
7:17 And the takeaway is also throughput does not only depend on the parallel configuration, but also the model family and architecture. And we tried scaling this. So, we looked at node sizes from two nodes to eight nodes. And it turns out things become less predictable at a larger scale. So, if you look here, you can see as the more we scale the number of nodes, the PP heavy layouts dominate the average power. As you can see for the eight node, the T4, P1, D1 in the orange has the highest average steady power. Same thing can be said for throughput. As you can see, as we scale the pipeline dimension, you can see the throughput increasing. And then at some point for the eight node, the throughput for the pipeline heavy configuration becomes worse because of pipeline bubbles and other factors such as accelerator placement and thermal effects.
8:28 So, the key insights is the single node result that higher tensor parallelism minimizes power does not necessarily hold. And also, the single node result that higher data parallelism maximizes power and throughput also does not necessarily hold at a large scale. And we also noticed that the best parallelism strategy depends on factors such as the model, cluster size, network topology, and so on. So, our idea is to exploit these trade-offs by switching the parallel layout over time to reduce carbon emissions. So, basically, for any training, like the standard practice in training, you choose a parallel configuration and you go with it for the full duration of the training run. But our idea is to treat the TP, PP, DP dimensions as a tunable operating point along the power throughput curve.
9:24 So, when your grid is dirty, you would basically go to a more leaner power, lower power parallel configuration. And when your grid is clean, you can go for a higher throughput parallel configuration. So, basically, this is our system. We did offline profiling of all the parallel configurations. The profiling was done over a bunch of short runs where we did a bunch of warm-up iterations. And then, as soon as the power started being more steady, we did the power sampling. And we also...so, to switch between different parallel configurations, you have to do resharding. So, we also accounted for that as well. So, our system takes the CI trace and the token budget and the deadline. And then, it tries to estimate the best strategy or the best parallel strategy or the best sequence of parallel strategies to go with during training.
10:30 So, as you can see in the graph at the bottom, when the grid is dirty, you would basically...our scheduler would choose the low-power configuration. And then, when the grid is clean, you would go for a more high-throughput configuration. So, we created this scheduler and this was our optimization...we represented the scheduling process as an optimization problem. And during each time step, X sub T pi, which we think of as the parallel configuration, which is running at step T, and it has to hold that at any time step, you can only go with one configuration, hence the sum. And for the objective, our objective was to minimize the total number of...or the total carbon emissions. So, we also had a few constraints. We had to reach the token budget, finish before the deadline, and you can only have at most one configuration per unit time.
11:37 So, we did our evaluation on the May 2024 hourly Electricity Maps traces for three regions on AWS, US West 1, US West 2, US East 2. And we did the...we did the profiling on GPT-2. We trained GPT-2 on A100 GPUs. And we did the profiling on...for the Llama 1B model on four L-40s GPUs. And we varied the token budget between 1B and 8B. And we took 64 randomly sampled chunks of that trace for each model region token budget. And we sort of averaged those to get an estimate. And for the deadline, we went for 25% over the fastest measured static strategy. So, these were our results. So, as you can see, our highest savings were at US West 2 in the green for the 8 billion token budget.
12:45 We were able to get up to 3.87, which we consider to be very modest. And we also noticed that savings are largest when the carbon intensity varies over time. So, for example, if you look at US East 2, which has the lowest carbon...the lowest variation coefficient, it seems like the savings were pretty minimal, almost zero. This is an example episode of our scheduler. And as you can see, during the training time, or in the...so, in the blue is the best static strategy, which is choosing only one static strategy and going with it all the way for the training run. But as you can see, for the fixed start time dynamic parallelism, which is our method, it achieves a lower cumulative CO2. And we also show that even a greedy strategy that basically does not have access to the carbon trace and only chooses leaner configuration when the grid is dirty can also show savings.
14:13 So, in conclusion, parallelism has a coupled non-monotonic effect on both power and throughput. Carbon-aware scheduling can save carbon. And we showed savings up to 3.87 over the best feasible static configuration. For future work, we are thinking that we can scale this approach. We can think about more modes of parallelism, like sequence parallelism and expert parallelism. And we can also think about other knobs, such as batch size and placement strategies. So, placement strategies is basically choosing what GPUs make up the parallel groups. And we were also thinking that introducing all of these knobs is going to make profiling pretty impossible. So, we were also thinking, oh, can we profile all of these strategies in a way that is efficient? Yeah. So, that was it. Thank you so much.
15:11 Like, close form expression for, you know, your ability to, like, utilize things. You can probably estimate power quite well. Have you guys thought about trying to just model that aspect rather than... We'll think about that. And we also noticed that there are a lot of other factors that are not usually optimized for, like, such as thermal effects. We don't really know what happens under the hood on a cluster. And also things like placement strategies. So, if you train on Megatron, for example, it chooses your parallel groups by default. It has its own way of choosing it. But it turns out if there's, like, smarter ways to go about choosing what GPUs make up the parallel groups, so you can actually get more savings that way.
16:21 So, yeah. Just, like, doing this paper, we sort of realized that it's pretty hard to know the power and throughput. Yeah. You just got to improve your model. Yeah. We were also thinking about maybe a found... So, there's, like, a lot of work on doing time series foundation models. And we were thinking maybe we can extend that to have, like, some sort of ETS for distributed training, where you can maybe, like, feed it the distributed code and other factors and maybe, like, a profiling. Yeah. And you can have it basically try to figure out the rest of the electricity trace of your training job. Yeah. That would be an interesting direction. So, the evaluation was done on a simulated refit, right? Yeah. And the cost calculation for the efficiency...
17:24 Yeah. So, basically, we take all of the reshardings of all the parallel configurations. And we sort of average that to get an estimate. And you can see, like, the K bar. This is our estimate. Yeah. Going back to the profiling, how... How often would you think that that has to happen, assuming it is profiling and not a model? Is it, like, each new model or, like, the grid changes? So, this fully depends on what method you have running under the hood. So, if you're running, like, FSDP, which is the standard checkpointing-based sharding, then that would be more expensive because it would be storing into the disk. But then there are newer works that are working on storing or basically changing your configuration by doing, like, by actually sending the optimizer state and others to, like, doing, like, rank-to-rank communication instead of saving onto disk.
18:42 So, it sort of depends on what you think is running under the hood. Yeah. So, I don't know. I guess. Do you expect the benefit to increase or decrease once you increase the training setup to, like, 100 or 1,000 of GPUs? We don't know. We're not sure whether this actually can hold in a real-world setting yet. Yeah. Go ahead and take a look. Go ahead and take a look. Go ahead and take a look.