final words thom

#63
by thomwolf HF staff - opened
Files changed (2) hide show
  1. dist/index.html +64 -60
  2. src/index.html +64 -60
dist/index.html CHANGED
@@ -1900,6 +1900,65 @@
1900
  <li>Experiment with several micro batch size (mbs) to aim for an optimal balance between max GBS, model size, compute, and communication.</li>
1901
  </ul>
1902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1903
  <!-- <p>We can roughly summarize the journey to the best configuration in the following diagram:</p>
1904
 
1905
  <p><img alt="image.png" src="/assets/images/placeholder.png" /></p>
@@ -2552,76 +2611,21 @@
2552
  <h2>Conclusion</h2>
2553
 
2554
 
2555
- <p>Congratulations, dear reader, you made it to the end! We've completed quite a journey: we started from understanding how to train a simple model on a single GPU, all the way to mastering all the intricate techniques used to efficiently train massive language models like Llama-405B and DeepSeek-V3 on thousands of GPUs. By now, you can read a diagram, like Llama-3's 4D parallel setup, with ease:</p>
2556
 
2557
  <p><img alt="image.png" src="/assets/images/conclusion_llama3_parallelism.png" /></p>
2558
 
2559
  <p>Orchestrating large clusters of GPUs to train LLMs efficiently is no easy feat. We learned how to optimize computations and communications between GPUs such that they run with maximum utilization at all times. It involves choosing the right parallelization strategy for a given model and cluster size, overlapping communication and computation where possible, and writing custom kernels that take into account the hardware layout to perform an operation as fast as possible on the GPU.</p>
2560
 
2561
- <p>You might still believe that this knowledge is a bit niche and only concerns the small set of people that pretrain LLMs. Historically, that mayb be true, but as models are growing rapidly even people who want to fine-tune models require distributd training setups. So diving deeper into all things distributed might prove very timely.</p>
2562
-
2563
- <p>This has been a long learning journey, but not just for you! Running thousands of benchmarks on a GPU cluster was more challenging than we anticipated and we want to share a few highlights of our learning experience.</p>
2564
-
2565
- <h3>What we learned</h3>
2566
-
2567
- <p>Our goal for this blogpost was not only to discuss theory and implementations but provide actual data points as well. So the plan was simple: lets run every possible distributed configuration for every model and a number of cluster sizes (namely 1-64 nodes of 8xH100s). Even after excluding impossible configuration we still needed to run thousands of experiments. </p>
2568
-
2569
- <aside>We want to take this opportunity to apologize to our co-workers for blocking most of the science cluster and in turn forgive any threats that may have been whispered.</aside>
2570
-
2571
- <p>
2572
- On paper this sounds easy enough: we can easily launch big arrays of jobs on our cluster. However, when we launched the first batches is when the troubles began:
2573
- </p>
2574
-
2575
- <ul>
2576
- <li>PyTorch processes would sometimes fail to clean up properly</li>
2577
- <li>Slurm job manager would forcefully terminate jobs, leading to node failures </li>
2578
- <li>Simple benchmarks that should take minutes would stretch into hours</li>
2579
- <li>Some jobs would hang indefinitely</li>
2580
- </ul>
2581
-
2582
- <p>So in order to run all experiments in a finite amount of time required some additional engineering. In particular we spent a significant amount of time on the following:</p>
2583
-
2584
- <ul>
2585
- <li>Minimizing cluster restart times and optimize idle time</li>
2586
- <li>Analyzing detailed NCCL debug logs</li>
2587
- <li>Understand memory usage patterns and CUDA memory allocator behaviors</li>
2588
- <li>Improving pipeline parallelism performance on multi-node</li>
2589
- </ul>
2590
-
2591
- <p>These challenges deserve their own story, but they taught us valuable lessons about the complexities of distributed training infrastructure. What looks simple in theory often requires careful attention to many moving parts in practice.</p>
2592
-
2593
- <!--
2594
- <p>Let's analyze the results of our benchmarks and understand how different configurations affect each other. All benchmarks were run with a sequence length of 4096 and a global batch size of 1M tokens. We'll look at two key visualizations that help illustrate our findings.
2595
- </p>
2596
-
2597
- <p>First, let's examine this heatmap visualization:</p>
2598
-
2599
- <p><img alt="image.png" src="/assets/images/what_we_learnt_heatmap.svg" /></p>
2600
- <p>Heatmap visualization showing the optimal training configurations across different model sizes and compute node counts. For each combination, the configuration details include Data Parallelism (DP), Tensor Parallelism (TP), Pipeline Parallelism (PP), Gradient Accumulation Steps (GAS), Micro Batch Size (MBS), and ZeRO optimization stage. The color intensity indicates the Model FLOPs Utilization (MFU), with brighter colors representing higher efficiency.</p>
2601
 
2602
- <p>To complement this, let's look at the relationships between different parameters:</p>
2603
-
2604
- <iframe id="plotFrame" src="/assets/images/what_we_learnt_parallel_coordinates.html" height="540" width="1000" scrolling="no" frameborder="0"></iframe>
2605
-
2606
- <p>Parallel coordinates plot showing the relationship between different model parallelism configurations (Data Parallel degree, Tensor Parallel degree, Pipeline Parallel degree), training hyperparameters (gradient accumulation steps, micro batch size), ZeRO stage and the resulting Model FLOPs Utilization (MFU). Each line represents a different training configuration, with colors indicating the MFU value - warmer colors show higher efficiency.</p>
2607
-
2608
- <p>From these visualizations, we can draw several important insights:
2609
- </p>
2610
-
2611
- <ol>
2612
- <li>As we increase the number of nodes (higher parallelism), we observe a decrease in efficiency. This effect is particularly pronounced for smaller models, which have a lower compute-to-model-size ratio. While we might typically compensate for small model size by increasing the batch size, we're constrained by our global batch size limit of 1M.
2613
- </li>
2614
- <li>Larger models present a different challenge. As model size increases, memory requirements grow substantially. This creates two scenarios with fewer nodes: either the model doesn't fit at all, or it barely fits but runs inefficiently due to operating near the GPU memory limits.</li>
2615
- <li>Our benchmarks demonstrate how performance heavily depends on implementation quality. When we first implemented both parallelism strategies, Tensor Parallelism (TP) outperformed Pipeline Parallelism (PP). After optimizing our PP code, it became the faster option. Now that we're improving the communication overlap in our TP implementation, we expect it to regain the performance lead.</li>
2616
- </ol>
2617
- -->
2618
- <p>Reproducing theoretical results in practice is challenging, especially given the limited availability of production training code. Through open-source projects like picotron and nanotron, we hope to make these distributed training techniques more accessible and foster collaboration on simpler, more efficient codebases that help researchers and practitioners make the most of their hardware resources.</p>
2619
 
2620
  <h3>So, what’s next?</h3>
2621
 
2622
- <p>You now have good overview of the main distributed training concepts but at the same time we just scratched to surface of on some aspects. There are many ways to dive deep into a subject but here are some steps that we recommend:</p>
2623
  <ul>
2624
- <li>Carefully read some of the landmark or very recent papers. You can find a list of some of the most impactful papers in <a target="_self" href="#references" class="">References</a>.</li>
2625
  <li>Start from scratch and implement an algorithm yourself. Often a method only fully “clicks” if you implemented it yourself.</li>
2626
  <li>Dive into one of the widely used frameworks and start contributing: fix bugs, answer issues, or implement a new feature. That’s the best way to get in any ML field!</li>
2627
  </ul>
 
1900
  <li>Experiment with several micro batch size (mbs) to aim for an optimal balance between max GBS, model size, compute, and communication.</li>
1901
  </ul>
1902
 
1903
+ <h3>Benchmarking thousands of configurations</h3>
1904
+
1905
+ <p>Now that we've covered the step-by-step, let's implement this search process in real-life.</p>
1906
+
1907
+ <p>You will find, in the <a href="https://github.com/huggingface/nanotron">nanotron</a> repository, several scripts you can use to run all the experiments we discussed above and be able to benchmark your own model and cluster in real life.</p>
1908
+
1909
+ <p>We actually ran ourself benchmarks on <strong>several thousands of distributed configurations</strong> covering every model size we've discussed above as well as a very large number of cluster configurations (namely 1-64 nodes of 8xH100s) we could try in order to produce the results we've covered up to now in this book.</p>
1910
+ <aside>We want to take this opportunity to apologize to our co-workers for blocking most of the science cluster and in turn forgive any threats that may have been whispered.</aside>
1911
+
1912
+ <p>Now let's take a step back to gather and analyze the results of all our benchmarks and see if, beyond theory, we can actually discover on real-world data how various configurations fare against each other.</p>
1913
+
1914
+ <p>All the following benchmarks were conducted with a sequence length of 4096 and a global batch size of 1M tokens. We gathered all the top configurations for each model and cluster size and plotted them in the following heatmaps:</p>
1915
+ </p>
1916
+
1917
+ <div class="large-image-background">
1918
+ <p><img alt="image.png" src="/assets/images/what_we_learnt_heatmap.svg" /></p>
1919
+ </div>
1920
+ <div class="figure-legend">
1921
+ <p>Heatmap visualization showing the optimal training configurations across different model sizes and compute node counts (we have 8 GPUs per node). For each combination, the configuration details include Data Parallelism (DP), Tensor Parallelism (TP), Pipeline Parallelism (PP), Gradient Accumulation Steps (GAS), Micro Batch Size (MBS), and ZeRO optimization stage. The color intensity indicates the Model FLOPs Utilization (MFU), with brighter colors representing higher efficiency.</p>
1922
+ </div>
1923
+ <p>From this high-level visualization, we can draw several important insights:
1924
+ </p>
1925
+
1926
+ <p>First, as we increase the number of nodes (higher parallelism), we observe a decrease in efficiency. This effect is particularly pronounced for smaller models, which have a lower compute-to-model-size ratio. While we might typically compensate for small model size by increasing the batch size, we're constrained by our global batch size limit of 1M.
1927
+ </p>
1928
+
1929
+ <p>Second, Larger models present a different challenge. As model size increases, memory requirements grow substantially. This creates two scenarios with fewer nodes: either the model doesn't fit at all, or it barely fits but runs inefficiently due to operating near the GPU memory limits (see for instance the 80B parameter model training on 4 nodes).</p>
1930
+
1931
+
1932
+ <p>Finally, our benchmarks show how performance heavily depends on implementation quality. When we first implemented both parallelism strategies, Tensor Parallelism (TP) outperformed Pipeline Parallelism (PP). After optimizing our PP code, it became the faster option. Now that we're improving the communication overlap in our TP implementation, we expect it to regain the performance lead.</p>
1933
+
1934
+ <h3>Lessons learned on benchmarking</h3>
1935
+
1936
+ <p>Our goal for this book was not only to discuss theory and implementations but provide actual data points as well. So the plan was simple: lets run every possible distributed configuration for every model and a number of cluster sizes (namely 1-64 nodes of 8xH100s). Even after excluding impossible configuration we still needed to run thousands of experiments. </p>
1937
+
1938
+ <p>
1939
+ On paper this sounds easy enough: we can easily launch big arrays of jobs on our cluster. However, as soon as we launched the first batches of experiments, troubles began:
1940
+ </p>
1941
+
1942
+ <ul>
1943
+ <li>PyTorch processes would sometimes fail to clean up properly</li>
1944
+ <li>Slurm job manager would forcefully terminate jobs, leading to node failures </li>
1945
+ <li>Simple benchmarks that should take minutes would stretch into hours</li>
1946
+ <li>Some jobs would hang indefinitely</li>
1947
+ </ul>
1948
+
1949
+ <p>Running all experiments in a finite amount of time required additional engineering and we ended up spending a significant amount of time on things like:</p>
1950
+
1951
+ <ul>
1952
+ <li>Minimizing cluster restart times and optimize idle time</li>
1953
+ <li>Analyzing detailed NCCL debug logs</li>
1954
+ <li>Understand memory usage patterns and CUDA memory allocator behaviors</li>
1955
+ <li>Improving pipeline parallelism performance on multi-node</li>
1956
+ </ul>
1957
+
1958
+ <p>These challenges deserve their own story, but they taught us valuable lessons about the complexities of distributed training infrastructure. What looks simple in theory often requires careful attention to many moving parts in practice.</p>
1959
+
1960
+ <p>Reproducing theoretical results in practice is challenging, especially given the limited availability of production training code. Through open-source projects like <a target="_blank" href="https://github.com/huggingface/nanotron">nanotron</a> and <a target="_blank" href="https://github.com/huggingface/picotron">picotron</a>, we hope we can help making distributed training techniques more accessible as well as collaborating on simple and efficient codebases that help researchers and practitioners take the most out of their hardware resources.</p>
1961
+
1962
  <!-- <p>We can roughly summarize the journey to the best configuration in the following diagram:</p>
1963
 
1964
  <p><img alt="image.png" src="/assets/images/placeholder.png" /></p>
 
2611
  <h2>Conclusion</h2>
2612
 
2613
 
2614
+ <p>Congratulations, dear reader, you made it to the end! We've completed quite a journey: we started from understanding how to train a simple model on a single GPU, all the way to mastering all the intricate techniques used to efficiently train massive language models like Llama-405B and DeepSeek-V3 on thousands of GPUs. By now, you can read a diagram, like Llama-3's 4D parallel setup, with (relative) ease:</p>
2615
 
2616
  <p><img alt="image.png" src="/assets/images/conclusion_llama3_parallelism.png" /></p>
2617
 
2618
  <p>Orchestrating large clusters of GPUs to train LLMs efficiently is no easy feat. We learned how to optimize computations and communications between GPUs such that they run with maximum utilization at all times. It involves choosing the right parallelization strategy for a given model and cluster size, overlapping communication and computation where possible, and writing custom kernels that take into account the hardware layout to perform an operation as fast as possible on the GPU.</p>
2619
 
2620
+ <p>You might still believe that this knowledge is a bit niche and only concerns the small set of people that pretrain LLMs. Historically, that may have been true, but as both the <a target="_blank" href="https://huggingface.co">AI builder community</a> and model sizes are growing rapidly, the community of people using distributed techniques for inference, fine-tuning and training is increasing exponentially as well making distributed training setups more and more common. Diving deeper into all things distributed might thus prove very timely.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2621
 
2622
+ <p>This has been a long learning journey, but not just for you! Running thousands of benchmarks on a GPU cluster was more challenging than we anticipated and we want to share a few highlights of our own learning experience as well.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2623
 
2624
  <h3>So, what’s next?</h3>
2625
 
2626
+ <p>You now have good overview of the main distributed training concepts but at the same time we just scratched to surface of several of these tools and techniques. There are many ways to dive deep into a subject but here are some steps that we recommend:</p>
2627
  <ul>
2628
+ <li>Carefully read some of the landmark or very recent papers. You can find a very extenside list of the most impactful papers, blog posts and books in <a target="_self" href="#references" class="">References</a>.</li>
2629
  <li>Start from scratch and implement an algorithm yourself. Often a method only fully “clicks” if you implemented it yourself.</li>
2630
  <li>Dive into one of the widely used frameworks and start contributing: fix bugs, answer issues, or implement a new feature. That’s the best way to get in any ML field!</li>
2631
  </ul>
src/index.html CHANGED
@@ -1900,6 +1900,65 @@
1900
  <li>Experiment with several micro batch size (mbs) to aim for an optimal balance between max GBS, model size, compute, and communication.</li>
1901
  </ul>
1902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1903
  <!-- <p>We can roughly summarize the journey to the best configuration in the following diagram:</p>
1904
 
1905
  <p><img alt="image.png" src="/assets/images/placeholder.png" /></p>
@@ -2552,76 +2611,21 @@
2552
  <h2>Conclusion</h2>
2553
 
2554
 
2555
- <p>Congratulations, dear reader, you made it to the end! We've completed quite a journey: we started from understanding how to train a simple model on a single GPU, all the way to mastering all the intricate techniques used to efficiently train massive language models like Llama-405B and DeepSeek-V3 on thousands of GPUs. By now, you can read a diagram, like Llama-3's 4D parallel setup, with ease:</p>
2556
 
2557
  <p><img alt="image.png" src="/assets/images/conclusion_llama3_parallelism.png" /></p>
2558
 
2559
  <p>Orchestrating large clusters of GPUs to train LLMs efficiently is no easy feat. We learned how to optimize computations and communications between GPUs such that they run with maximum utilization at all times. It involves choosing the right parallelization strategy for a given model and cluster size, overlapping communication and computation where possible, and writing custom kernels that take into account the hardware layout to perform an operation as fast as possible on the GPU.</p>
2560
 
2561
- <p>You might still believe that this knowledge is a bit niche and only concerns the small set of people that pretrain LLMs. Historically, that mayb be true, but as models are growing rapidly even people who want to fine-tune models require distributd training setups. So diving deeper into all things distributed might prove very timely.</p>
2562
-
2563
- <p>This has been a long learning journey, but not just for you! Running thousands of benchmarks on a GPU cluster was more challenging than we anticipated and we want to share a few highlights of our learning experience.</p>
2564
-
2565
- <h3>What we learned</h3>
2566
-
2567
- <p>Our goal for this blogpost was not only to discuss theory and implementations but provide actual data points as well. So the plan was simple: lets run every possible distributed configuration for every model and a number of cluster sizes (namely 1-64 nodes of 8xH100s). Even after excluding impossible configuration we still needed to run thousands of experiments. </p>
2568
-
2569
- <aside>We want to take this opportunity to apologize to our co-workers for blocking most of the science cluster and in turn forgive any threats that may have been whispered.</aside>
2570
-
2571
- <p>
2572
- On paper this sounds easy enough: we can easily launch big arrays of jobs on our cluster. However, when we launched the first batches is when the troubles began:
2573
- </p>
2574
-
2575
- <ul>
2576
- <li>PyTorch processes would sometimes fail to clean up properly</li>
2577
- <li>Slurm job manager would forcefully terminate jobs, leading to node failures </li>
2578
- <li>Simple benchmarks that should take minutes would stretch into hours</li>
2579
- <li>Some jobs would hang indefinitely</li>
2580
- </ul>
2581
-
2582
- <p>So in order to run all experiments in a finite amount of time required some additional engineering. In particular we spent a significant amount of time on the following:</p>
2583
-
2584
- <ul>
2585
- <li>Minimizing cluster restart times and optimize idle time</li>
2586
- <li>Analyzing detailed NCCL debug logs</li>
2587
- <li>Understand memory usage patterns and CUDA memory allocator behaviors</li>
2588
- <li>Improving pipeline parallelism performance on multi-node</li>
2589
- </ul>
2590
-
2591
- <p>These challenges deserve their own story, but they taught us valuable lessons about the complexities of distributed training infrastructure. What looks simple in theory often requires careful attention to many moving parts in practice.</p>
2592
-
2593
- <!--
2594
- <p>Let's analyze the results of our benchmarks and understand how different configurations affect each other. All benchmarks were run with a sequence length of 4096 and a global batch size of 1M tokens. We'll look at two key visualizations that help illustrate our findings.
2595
- </p>
2596
-
2597
- <p>First, let's examine this heatmap visualization:</p>
2598
-
2599
- <p><img alt="image.png" src="/assets/images/what_we_learnt_heatmap.svg" /></p>
2600
- <p>Heatmap visualization showing the optimal training configurations across different model sizes and compute node counts. For each combination, the configuration details include Data Parallelism (DP), Tensor Parallelism (TP), Pipeline Parallelism (PP), Gradient Accumulation Steps (GAS), Micro Batch Size (MBS), and ZeRO optimization stage. The color intensity indicates the Model FLOPs Utilization (MFU), with brighter colors representing higher efficiency.</p>
2601
 
2602
- <p>To complement this, let's look at the relationships between different parameters:</p>
2603
-
2604
- <iframe id="plotFrame" src="/assets/images/what_we_learnt_parallel_coordinates.html" height="540" width="1000" scrolling="no" frameborder="0"></iframe>
2605
-
2606
- <p>Parallel coordinates plot showing the relationship between different model parallelism configurations (Data Parallel degree, Tensor Parallel degree, Pipeline Parallel degree), training hyperparameters (gradient accumulation steps, micro batch size), ZeRO stage and the resulting Model FLOPs Utilization (MFU). Each line represents a different training configuration, with colors indicating the MFU value - warmer colors show higher efficiency.</p>
2607
-
2608
- <p>From these visualizations, we can draw several important insights:
2609
- </p>
2610
-
2611
- <ol>
2612
- <li>As we increase the number of nodes (higher parallelism), we observe a decrease in efficiency. This effect is particularly pronounced for smaller models, which have a lower compute-to-model-size ratio. While we might typically compensate for small model size by increasing the batch size, we're constrained by our global batch size limit of 1M.
2613
- </li>
2614
- <li>Larger models present a different challenge. As model size increases, memory requirements grow substantially. This creates two scenarios with fewer nodes: either the model doesn't fit at all, or it barely fits but runs inefficiently due to operating near the GPU memory limits.</li>
2615
- <li>Our benchmarks demonstrate how performance heavily depends on implementation quality. When we first implemented both parallelism strategies, Tensor Parallelism (TP) outperformed Pipeline Parallelism (PP). After optimizing our PP code, it became the faster option. Now that we're improving the communication overlap in our TP implementation, we expect it to regain the performance lead.</li>
2616
- </ol>
2617
- -->
2618
- <p>Reproducing theoretical results in practice is challenging, especially given the limited availability of production training code. Through open-source projects like picotron and nanotron, we hope to make these distributed training techniques more accessible and foster collaboration on simpler, more efficient codebases that help researchers and practitioners make the most of their hardware resources.</p>
2619
 
2620
  <h3>So, what’s next?</h3>
2621
 
2622
- <p>You now have good overview of the main distributed training concepts but at the same time we just scratched to surface of on some aspects. There are many ways to dive deep into a subject but here are some steps that we recommend:</p>
2623
  <ul>
2624
- <li>Carefully read some of the landmark or very recent papers. You can find a list of some of the most impactful papers in <a target="_self" href="#references" class="">References</a>.</li>
2625
  <li>Start from scratch and implement an algorithm yourself. Often a method only fully “clicks” if you implemented it yourself.</li>
2626
  <li>Dive into one of the widely used frameworks and start contributing: fix bugs, answer issues, or implement a new feature. That’s the best way to get in any ML field!</li>
2627
  </ul>
 
1900
  <li>Experiment with several micro batch size (mbs) to aim for an optimal balance between max GBS, model size, compute, and communication.</li>
1901
  </ul>
1902
 
1903
+ <h3>Benchmarking thousands of configurations</h3>
1904
+
1905
+ <p>Now that we've covered the step-by-step, let's implement this search process in real-life.</p>
1906
+
1907
+ <p>You will find, in the <a href="https://github.com/huggingface/nanotron">nanotron</a> repository, several scripts you can use to run all the experiments we discussed above and be able to benchmark your own model and cluster in real life.</p>
1908
+
1909
+ <p>We actually ran ourself benchmarks on <strong>several thousands of distributed configurations</strong> covering every model size we've discussed above as well as a very large number of cluster configurations (namely 1-64 nodes of 8xH100s) we could try in order to produce the results we've covered up to now in this book.</p>
1910
+ <aside>We want to take this opportunity to apologize to our co-workers for blocking most of the science cluster and in turn forgive any threats that may have been whispered.</aside>
1911
+
1912
+ <p>Now let's take a step back to gather and analyze the results of all our benchmarks and see if, beyond theory, we can actually discover on real-world data how various configurations fare against each other.</p>
1913
+
1914
+ <p>All the following benchmarks were conducted with a sequence length of 4096 and a global batch size of 1M tokens. We gathered all the top configurations for each model and cluster size and plotted them in the following heatmaps:</p>
1915
+ </p>
1916
+
1917
+ <div class="large-image-background">
1918
+ <p><img alt="image.png" src="/assets/images/what_we_learnt_heatmap.svg" /></p>
1919
+ </div>
1920
+ <div class="figure-legend">
1921
+ <p>Heatmap visualization showing the optimal training configurations across different model sizes and compute node counts (we have 8 GPUs per node). For each combination, the configuration details include Data Parallelism (DP), Tensor Parallelism (TP), Pipeline Parallelism (PP), Gradient Accumulation Steps (GAS), Micro Batch Size (MBS), and ZeRO optimization stage. The color intensity indicates the Model FLOPs Utilization (MFU), with brighter colors representing higher efficiency.</p>
1922
+ </div>
1923
+ <p>From this high-level visualization, we can draw several important insights:
1924
+ </p>
1925
+
1926
+ <p>First, as we increase the number of nodes (higher parallelism), we observe a decrease in efficiency. This effect is particularly pronounced for smaller models, which have a lower compute-to-model-size ratio. While we might typically compensate for small model size by increasing the batch size, we're constrained by our global batch size limit of 1M.
1927
+ </p>
1928
+
1929
+ <p>Second, Larger models present a different challenge. As model size increases, memory requirements grow substantially. This creates two scenarios with fewer nodes: either the model doesn't fit at all, or it barely fits but runs inefficiently due to operating near the GPU memory limits (see for instance the 80B parameter model training on 4 nodes).</p>
1930
+
1931
+
1932
+ <p>Finally, our benchmarks show how performance heavily depends on implementation quality. When we first implemented both parallelism strategies, Tensor Parallelism (TP) outperformed Pipeline Parallelism (PP). After optimizing our PP code, it became the faster option. Now that we're improving the communication overlap in our TP implementation, we expect it to regain the performance lead.</p>
1933
+
1934
+ <h3>Lessons learned on benchmarking</h3>
1935
+
1936
+ <p>Our goal for this book was not only to discuss theory and implementations but provide actual data points as well. So the plan was simple: lets run every possible distributed configuration for every model and a number of cluster sizes (namely 1-64 nodes of 8xH100s). Even after excluding impossible configuration we still needed to run thousands of experiments. </p>
1937
+
1938
+ <p>
1939
+ On paper this sounds easy enough: we can easily launch big arrays of jobs on our cluster. However, as soon as we launched the first batches of experiments, troubles began:
1940
+ </p>
1941
+
1942
+ <ul>
1943
+ <li>PyTorch processes would sometimes fail to clean up properly</li>
1944
+ <li>Slurm job manager would forcefully terminate jobs, leading to node failures </li>
1945
+ <li>Simple benchmarks that should take minutes would stretch into hours</li>
1946
+ <li>Some jobs would hang indefinitely</li>
1947
+ </ul>
1948
+
1949
+ <p>Running all experiments in a finite amount of time required additional engineering and we ended up spending a significant amount of time on things like:</p>
1950
+
1951
+ <ul>
1952
+ <li>Minimizing cluster restart times and optimize idle time</li>
1953
+ <li>Analyzing detailed NCCL debug logs</li>
1954
+ <li>Understand memory usage patterns and CUDA memory allocator behaviors</li>
1955
+ <li>Improving pipeline parallelism performance on multi-node</li>
1956
+ </ul>
1957
+
1958
+ <p>These challenges deserve their own story, but they taught us valuable lessons about the complexities of distributed training infrastructure. What looks simple in theory often requires careful attention to many moving parts in practice.</p>
1959
+
1960
+ <p>Reproducing theoretical results in practice is challenging, especially given the limited availability of production training code. Through open-source projects like <a target="_blank" href="https://github.com/huggingface/nanotron">nanotron</a> and <a target="_blank" href="https://github.com/huggingface/picotron">picotron</a>, we hope we can help making distributed training techniques more accessible as well as collaborating on simple and efficient codebases that help researchers and practitioners take the most out of their hardware resources.</p>
1961
+
1962
  <!-- <p>We can roughly summarize the journey to the best configuration in the following diagram:</p>
1963
 
1964
  <p><img alt="image.png" src="/assets/images/placeholder.png" /></p>
 
2611
  <h2>Conclusion</h2>
2612
 
2613
 
2614
+ <p>Congratulations, dear reader, you made it to the end! We've completed quite a journey: we started from understanding how to train a simple model on a single GPU, all the way to mastering all the intricate techniques used to efficiently train massive language models like Llama-405B and DeepSeek-V3 on thousands of GPUs. By now, you can read a diagram, like Llama-3's 4D parallel setup, with (relative) ease:</p>
2615
 
2616
  <p><img alt="image.png" src="/assets/images/conclusion_llama3_parallelism.png" /></p>
2617
 
2618
  <p>Orchestrating large clusters of GPUs to train LLMs efficiently is no easy feat. We learned how to optimize computations and communications between GPUs such that they run with maximum utilization at all times. It involves choosing the right parallelization strategy for a given model and cluster size, overlapping communication and computation where possible, and writing custom kernels that take into account the hardware layout to perform an operation as fast as possible on the GPU.</p>
2619
 
2620
+ <p>You might still believe that this knowledge is a bit niche and only concerns the small set of people that pretrain LLMs. Historically, that may have been true, but as both the <a target="_blank" href="https://huggingface.co">AI builder community</a> and model sizes are growing rapidly, the community of people using distributed techniques for inference, fine-tuning and training is increasing exponentially as well making distributed training setups more and more common. Diving deeper into all things distributed might thus prove very timely.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2621
 
2622
+ <p>This has been a long learning journey, but not just for you! Running thousands of benchmarks on a GPU cluster was more challenging than we anticipated and we want to share a few highlights of our own learning experience as well.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2623
 
2624
  <h3>So, what’s next?</h3>
2625
 
2626
+ <p>You now have good overview of the main distributed training concepts but at the same time we just scratched to surface of several of these tools and techniques. There are many ways to dive deep into a subject but here are some steps that we recommend:</p>
2627
  <ul>
2628
+ <li>Carefully read some of the landmark or very recent papers. You can find a very extenside list of the most impactful papers, blog posts and books in <a target="_self" href="#references" class="">References</a>.</li>
2629
  <li>Start from scratch and implement an algorithm yourself. Often a method only fully “clicks” if you implemented it yourself.</li>
2630
  <li>Dive into one of the widely used frameworks and start contributing: fix bugs, answer issues, or implement a new feature. That’s the best way to get in any ML field!</li>
2631
  </ul>