This recipe contains information and scripts to produce performance results for the Llama 3 training workload. The scripts help perform environment setup, dataset setup, and launch benchmark jobs. This variant of the workload is best-suited for GPU clusters with
This recipe contains information and scripts to produce performance results for the Llama 3 training workload. The scripts help perform environment setup, dataset setup, and launch benchmark jobs. This variant of the workload is best-suited for GPU clusters with
Performance for Llama 3 training is measured by seconds per iteration, or in other words seconds per training step. This metric is logged for every training step in a .out file which is generated inside of the $STAGE_PATH/results/ folder.
Since the performance fluctuates significantly at the beginning, we are using the last training step timing to obtain throughput value.
grep train_step_timing results/*.out
Epoch 0: : 100%|██████████| 100/100 [18:58<00:00, reduced_train_loss=6.190, global_step=99.00, consumed_samples=12800.0, train_step_timing in s=11.10]
To obtain throughput as a tokens per second measurement, follow this formula:
(sequence length) * (global batch size) / (training_step_timing) = (throughput in tokens per second)
E.g. 8192 * 128 / 11.1 = 94466
To calculate time to train estimate:
(total tokens) / (throughput in tokens per second) / (number of seconds in a day) = (time to train in days)
E.g. 1e12 / 94466 / 86400 = 122.52 days
To calculate the model flops utilization (MFU):
MFU = (global batch size) * (model flops) / (training step time) / (number of GPUs) / (peak GPU FLOPS)
The peak theoretical throughput for H100 FP8 is 1979 TFLOPS and for H100 BF16 is 989 TFLOPS.
The model flops for Llama 3 8b for GBS=1 is 4.74E+14. Calculation shown here.
E.g. Llama 3 8b FP8 on 8x H100 GPUs (GBS=128)
peak FLOPS for H100 = 1979 TFLOPS
training step time = 11.1 s
model flops = 4.74E+14
MFU = 128 * 4.74E+14 / 11.1 / 8 / 1979E+12 = 34.52%
Llama 3 8b BF16 (TP=1, PP=1, MBS=1, VP=1, GA=16) | Throughput on 8x H100 GPUs (GBS=128) | Throughput on 16x H100 GPUs (GBS=256) | Throughput on 32x H100 GPUs (GBS=512) | Throughput on 64x H100 GPUs (GBS=1024) | Throughput on 128x H100 GPUs (GBS=2048) |
---|---|---|---|---|---|
Training step time (seconds per step) | 14.52 | 14.56 | 14.66 | 14.7 | 15.21 |
Throughput in tokens per second | 72216 | 144035 | 286105 | 570654 | 1103039 |
Model flops utilization | 52.79% | 52.64% | 52.28% | 52.14% | 50.39% |
Time to train 1T tokens in days | 160.27 | 80.36 | 40.45 | 20.28 | 10.49 |
Llama 3 8b FP8 (TP=1, PP=1, MBS=1, VP=1, GA=16) | Throughput on 8x H100 GPUs (GBS=128) | Throughput on 16x H100 GPUs (GBS=256) | Throughput on 32x H100 GPUs (GBS=512) | Throughput on 64x H100 GPUs (GBS=1024) | Throughput on 128x H100 GPUs (GBS=2048) |
---|---|---|---|---|---|
Training step time (seconds per step) | 11.1 | 11.15 | 11.2 | 11.24 | 11.28 |
Throughput in tokens per second | 94466 | 188085 | 374491 | 746317 | 1487342 |
Time to train 1T tokens in days | 122.52 | 61.54 | 30.91 | 15.51 | 7.78 |
Performance for Llama 3 training is measured by seconds per iteration, or in other words seconds per training step. This metric is logged for every training step in a .out file which is generated inside of the $STAGE_PATH/results/ folder.
Since the performance fluctuates significantly at the beginning, we are using the last training step timing to obtain throughput value.
grep train_step_timing results/*.out
Epoch 0: : 100%|██████████| 100/100 [20:15<00:00, reduced_train_loss=6.370, global_step=99.00, consumed_samples=12800.0, train_step_timing in s=11.20]
To obtain throughput as a tokens per second measurement, follow this formula:
(sequence length) * (global batch size) / (training_step_timing) = (throughput in tokens per second)
E.g. 8192 * 128 / 11.31 = 92712
To calculate time to train estimate:
(total tokens) / (throughput in tokens per second) / (number of seconds in a day) = (time to train in days)
E.g. 1e12 / 92712 / 86400 = 124.84 days
To calculate the model flops utilization (MFU):
MFU = (global batch size) * (model flops) / (training step time) / (number of GPUs) / (peak GPU FLOPS)
The peak theoretical throughput for H100 FP8 is 1979 TFLOPS and for H100 BF16 is 989 TFLOPS.
The model flops for Llama 3 70b for GBS=1 is 3.94E+15. Calculation shown here.
E.g. Llama 3 70b FP8 on 64x H100 GPUs (GBS=128)
peak FLOPS for H100 = 1979 TFLOPS
training step time = 11.31
model flops = 3.94E+15
MFU = 128 * 3.94E+15 / 11.31 / 64 / 1979E+12 = 35.21%
Llama 3 70b BF16 (TP=4, PP=4, CP=2, VP=5, MBS=1, GA=64) | Throughput on 64x H100 GPUs (GBS=128) | Throughput on 128x H100 GPUs (GBS=256) | Throughput on 256x H100 GPUs (GBS=512) | Throughput on 512x H100 GPUs (GBS=1024) | Throughput on 1024x H100 GPUs (GBS=2048) | Throughput on 2048x H100 GPUs (GBS=4096) |
---|---|---|---|---|---|---|
Training step time (seconds per step) | 15.97 | 16.06 | 16.08 | 16.11 | 16.16 | 16.39 |
Throughput in tokens per second | 65659 | 130582 | 260840 | 520708 | 1038194 | 2047250 |
Model flops utilization | 49.87% | 49.59% | 49.52% | 49.43% | 49.28% | 48.59% |
Time to train 1T tokens in days | 176.28 | 88.63 | 44.37 | 22.23 | 11.15 | 5.65 |
Llama 3 70b FP8 (TP=4, PP=4, CP=2, VP=5, MBS=1, GA=64) | Throughput on 64x H100 GPUs (GBS=128) | Throughput on 128x H100 GPUs (GBS=256) | Throughput on 256x H100 GPUs (GBS=512) | Throughput on 512x H100 GPUs (GBS=1024) | Throughput on 1024x H100 GPUs (GBS=2048) | Throughput on 2048x H100 GPUs (GBS=4096) |
---|---|---|---|---|---|---|
Training step time (seconds per step) | 11.31 | 11.68 | 11.7 | 11.9 | 11.89 | 12 |
Throughput in tokens per second | 92712 | 179551 | 358488 | 704925 | 1411036 | 2796203 |
Time to train 1T tokens in days | 124.84 | 64.46 | 32.29 | 16.42 | 8.2 | 4.14 |
This recipe requires access to Llama 3. Instructions are below if needed.
Create a staging area by running the attached setup.sh. The script converts the docker image from nvcr.io/nvidia/nemo:24.05 to the nvidia+nemo+24.05.sqsh file under the $STAGE_PATH folder and copies NeMo Launcher code from the container. The setup script also downloads Llama3 tokenizer related files from HuggingFace meta-llama/Meta-Llama-3-8B repo using HF_TOKEN
obtained in the previous step. Notice all Llama3 models (8b, 70b, 405b) use the same tokenizer.
# Set the path where all artifacts will be downloaded
export STAGE_PATH=<path to your shared file system folder> (e.g. /lustre/myproject/nemo)
# Set the Slurm partition to launch against
export SLURM_PARTITION="batch"
# Set the Slurm account to launch against
export SLURM_ACCOUNT="account_name"
# Set the number of GPUs per node according to Slurm's gres, this is usually 8 or null - https://slurm.schedmd.com/gres.html
export SLURM_GPU_PER_NODE=null
# Run the setup
bash ./setup.sh
A HuggingFace account is required and you will need to create a HuggingFace access token in order to run the training script. Add the generated token to your environment via export HUGGINGFACE_TOKEN=<your token>
.
Access to Llama 3 must be requested through Meta's website then requested on the HuggingFace Llama page. The approval process is not automatic and could take a day or more. Once access is granted, download the Llama tokenizer. The tokenizer will be needed to prepare the dataset in the next section and will need to be copied to the $STAGE_PATH.
Pre-training a GPT-3 model requires a text-based dataset to be downloaded and pre-processed for the NeMo Framework to ingest the data optimally. The Pile is often used as the dataset for pre-training models. The NeMo Framework contains helper scripts to download and pre-process the dataset. The following steps outline how to download and pre-process the dataset on DGX Cloud with an explanation of key points after.
Make sure $STAGE_PATH/llama-dataset/llama
contains tokenizer files downloaded from previous step.
Run the generate_dataset.sh
script. The script launches several Slurm jobs that will download the dataset from The Pile, pre-process it and save it in a form suitable for subsequent training. The resulting dataset files will be saved under the $STAGE_PATH/llama-dataset
folder. The dataset creation may use up to 100GB. Make sure you have sufficient disk space available.
bash ./generate_dataset.sh
If the dataset generation step was successful there should be 4 idx and 4 bin files in the $STAGE_PATH/llama-dataset folder.
my-llama_00_text_document.bin
my-llama_00_text_document.idx
my-llama_01_text_document.bin
my-llama_01_text_document.idx
my-llama_02_text_document.bin
my-llama_02_text_document.idx
my-llama_03_text_document.bin
my-llama_03_text_document.idx
If that is not the case, check the log files in: $STAGE_PATH/results.data_preparation
Once the environment has been prepared, it is time to train a model. NeMo Framework contains many predefined configuration files for various models including the 8 billion parameter Llama 3 model. This section will demonstrate how to initiate training the model. You can see the default configuration for Llama 3 70b in the NeMo-Framework-Launcher Github repository. We will modify some of these parameters with our launch command.
NeMo Launcher is using the Hydra framework to process command line arguments and pass them down as hyper parameters to a multi-node job performing the training.
Below is a command template for launching Llama 3 70b model training with FP8 precision on a specified number of nodes. The training will run for the first 100 steps and will stop afterwards.
Log files and results will be located under the $STAGE_PATH/results/ folder.
sbatch -A ${SLURM_ACCOUNT} -p ${SLURM_PARTITION} -N ${NUM_NODES} ./launch_llama3_70b.sh
If you would like to run with FP8 precision, simply set the environment variable ENABLE_FP8=true before launching the script. Otherwise, the training will be done using BF16 precision. For instance,
ENABLE_FP8=true sbatch -A ${SLURM_ACCOUNT} -p ${SLURM_PARTITION} -N ${NUM_NODES} ./launch_llama3_8b.sh
Note that it might be necessary to pass --gres gpu:8 to sbatch for certain clusters on encountering errors like GPU not found. See https://slurm.schedmd.com/gres.html
It is important to maintain these values for model parallelism settings in order to accurately assess performance results for completed jobs against expected baseline. For the 70b parameter model:
For the 8b parameter model:
Global batch size ( training.model.global_batch_size) value should be set to <number of nodes> * 16. E.g., 16 * 16 = 256 (in the example above)
.
For the 70b parameter model:
model flops = (sequence length) * ((attention flops) + (mlp flops) + (embedding flops))
model flops breakdown:
attention flops = 12 * (number of layers) * (hidden size)^2 * (1 + (number of query groups)/(number of attention heads) + (sequence length)/(hidden size))
mlp flops = 18 * (number of layers) * (FFN size) * (hidden size)
embedding flops = 6 * (vocab size) * (hidden size)
Llama 3 70b calculation:
sequence length = 8192
attention flops = 12 * 80 * 8192^2 * (1 + 8/64 + 8192/8192) = 136,902,082,560
mlp flops = 18 * 80 * 28672 * 8192 = 338,228,674,560
embedding flops = 6 * 128256 * 8192 = 6,304,038,912
model flops = 8129 * (136,902,082,560 + 338,228,674,560 + 6,304,038,912) = 3.94E+15
For the 8b parameter model:
model flops = (sequence length) * ((attention flops) + (mlp flops) + (embedding flops))
model flops breakdown:
attention flops = 12 * (number of layers) * (hidden size)^2 * (1 + (number of query groups)/(number of attention heads) + (sequence length)/(hidden size))
mlp flops = 18 * (number of layers) * (FFN size) * (hidden size)
embedding flops = 6 * (vocab size) * (hidden size)
Llama 3 8b calculation:
sequence length = 8192
attention flops = 12 * 32 * 4096^2 * (1 + 8/32 + 8192/4096) = 20,937,965,568
mlp flops = 18 * 32 * 14336 * 4096 = 33,822,867,456
embedding flops = 6 * 128256 * 4096 = 3,152,019,456
model flops = 8192 * (20,937,965,568 + 33,822,867,456 + 3,152,019,456) = 4.74E+14