NVIDIA Deep Learning Examples
NVIDIA Deep Learning Examples
BERT for TensorFlow2
Resource
NVIDIA Deep Learning Examples
NVIDIA Deep Learning Examples
BERT for TensorFlow2

BERT is a method of pre-training language representations which obtains state-of-the-art results on a wide array of NLP tasks.

The performance measurements in this document were conducted at the time of publication and may not reflect the performance achieved from NVIDIA's latest software release. For the most up-to-date performance measurements, go to NVIDIA Data Center Deep Learning Product Performance.

Benchmarking

The following section shows how to run benchmarks measuring the model performance in training and inference modes.

Both of these benchmarking scripts enable you to run a number of epochs, extract performance numbers, and run the BERT model for fine tuning.

Training performance benchmark

Training benchmarking can be performed by running the script:

scripts/finetune_train_benchmark.sh <bert_model> <num_gpu> <batch_size> <precision> <use_xla>

This script runs 800 steps by default on the SQuAD v1.1 dataset and extracts performance numbers for the given configuration. These numbers are saved at /results/squad_train_benchmark_<bert_model>_gpu<num_gpu>_bs<batch_size>.log.

Inference performance benchmark

Inference benchmarking can be performed by running the script:

scripts/finetune_inference_benchmark.sh <bert_model> <batch_size> <precision> <use_xla>

This script runs 1000 eval iterations by default on the SQuAD v1.1 dataset and extracts performance and latency numbers for the given configuration. These numbers are saved at /results/squad_inference_benchmark_<bert_model>_<precision>_bs<batch_size>.log.

Results

The following sections provide details on how we achieved our performance and accuracy in training and inference for fine tuning Question Answering. All results are on BERT-Large model unless otherwise mentioned. All fine tuning results are on SQuAD v1.1 using a sequence length of 384 unless otherwise mentioned.

Training accuracy results

Pre-training accuracy

Our results were obtained by running the scripts/run_pretraining_lamb.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX-2 and NVIDIA DGX A100.

DGX SystemNodes x GPUsPrecisionBatch Size/GPU: Phase1, Phase2Accumulation Steps: Phase1, Phase2Time to Train (Hrs)Final Loss
DGX2H32 x 16FP1656, 102, 62.671.69
DGX2H32 x 16FP3232, 44, 168.021.71
DGXA10032 x 8FP16312, 401, 32.021.68
DGXA10032 x 8TF32176, 222, 63.571.67
Fine-tuning accuracy for SQuAD v1.1: NVIDIA DGX A100 (8x A100 40GB)

Our results were obtained by running the scripts/run_squad.sh training script in the TensorFlow 20.12-py3 NGC container on NVIDIA DGX A100 with 8x A100 80GB GPUs.

GPUs**Batch size / GPU: TF32, FP16 **Accuracy - TF32Accuracy - mixed precisionTime to Train - TF32 (Hrs)Time to Train - mixed precision (Hrs)
838, 7690.8891.120.160.11
Pre-training SQuAD v1.1 stability test: NVIDIA DGX A100 (256x A100 80GB)

The following tables compare Final Loss scores across 3 different training runs with different seeds, for both FP16 and TF32. The runs showcase consistent convergence on all 3 seeds with very little deviation.

FP16, 256x GPUsseed 1seed 2seed 3meanstd
Final Loss1.6571.6611.6831.6670.014
TF32, 256x GPUsseed 1seed 2seed 3meanstd
Final Loss1.671.6541.6361.6530.017
Fine-tuning SQuAD v1.1 stability test: NVIDIA DGX A100 (8x A100 80GB)

The following tables compare F1 scores across 5 different training runs with different seeds, for both FP16 and TF32 respectively using the (NVIDIA Pretrained Checkpoint)[https://ngc.nvidia.com/catalog/models]. The runs showcase consistent convergence on all 5 seeds with very little deviation.

FP16, 8x GPUsseed 1seed 2seed 3seed 4seed 5meanstd
F191.1290.8090.9490.9090.9490.940.11
TF32, 8x GPUsseed 1seed 2seed 3seed 4seed 5meanstd
F190.7990.8890.8090.8890.8390.840.04

Training performance results

Pre-training training performance: Single-node on NVIDIA DGX-2 V100 (16x V100 32GB)

Our results were obtained by running the scripts/run_pretraining_lamb.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX-2 with 16x V100 32GB GPUs. Performance (in sequences per second) is the steady state throughput.

GPUsSequence LengthBatch size / GPU: mixed precision, FP32Gradient Accumulation: mixed precision, FP32Global Batch Size: mixed precision, FP32Throughput - mixed precisionThroughput - FP32Throughput speedup (FP32 - mixed precision)Weak scaling - mixed precisionWeak scaling - FP32
112860 , 321024 , 204861440 , 65536206.549.974.131.001.00
412860 , 32256 , 51261440 , 65536789.75194.024.073.823.88
812860 , 32128 , 25661440 , 655361561.77367.94.257.567.36
1612860 , 3264 , 12861440 , 655363077.99762.224.0414.915.25
151210 , 63072 , 512030720 , 3072040.9511.063.701.001.00
451210 , 6768 , 128030720 , 30720158.543.053.683.873.89
851210 , 6384 , 64030720 , 30720312.0385.513.657.627.73
1651210 , 4192 , 51230720 , 32768614.94161.383.8115.0214.59

Note: The respective values for FP32 runs that use a batch size of 60 and 10 in sequence lengths 128 and 512 are not available due to out of memory errors that arise.

Pre-training training performance: Multi-node on NVIDIA DGX-2H V100 (16x V100 32GB)

Our results were obtained by running the run.sub training script in the TensorFlow 21.02-py3 NGC container using multiple NVIDIA DGX-2 with 16x V100 32GB GPUs. Performance (in sequences per second) is the steady state throughput.

Num NodesSequence LengthBatch size / GPU: mixed precision, FP32Gradient Accumulation: mixed precision, FP32Global Batch Size: mixed precision, FP32Throughput - mixed precisionThroughput - FP32Throughput speedup (FP32 - mixed precision)Weak scaling - mixed precisionWeak scaling - FP32
112860 , 3264 , 12861440 , 655363528.51841.724.191.001.00
412860 , 3216 , 3261440 , 6553613370.213060.494.373.793.64
1612860 , 324 , 861440 , 6553642697.4210383.574.1112.112.34
3212860 , 322 , 461440 , 6553684223.1620094.144.1923.8723.87
151210 , 4192 , 25630720 , 32768678.351803.771.001.00
451210 , 496 , 6430720 , 327682678.29646.764.143.953.59
1651210 , 424 , 3230720 , 327687834.722204.723.5511.5512.25
3251210 , 46 , 1630720 , 3276818786.934196.154.4827.7023.31

Note: The respective values for FP32 runs that use a batch size of 60 and 10 in sequence lengths 128 and 512 are not available due to out of memory errors that arise.

Pre-training training performance: Single-node on NVIDIA DGX A100 (8x A100 80GB)

Our results were obtained by running the scripts/run_pretraining_lamb.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX A100 with 8x A100 80GB GPUs. Performance (in sequences per second) is the steady state throughput.

GPUsSequence LengthBatch size / GPU: mixed precision, TF32Gradient Accumulation: mixed precision, TF32Global Batch Size: mixed precision, FP32Throughput - mixed precisionThroughput - TF32Throughput speedup (TF32 - mixed precision)Weak scaling - mixed precisionWeak scaling -TF32
1128312 , 176256 , 51279872 , 90112485.59282.981.721.001.00
8128312 , 17632 , 6479872 , 901123799.241944.771.957.826.87
151240 , 22768 , 153630720 , 3379296.5254.921.761.001.00
851240 , 2296 , 19230720 , 33792649.69427.391.526.737.78

Note: The respective values for TF32 runs that use a batch size of 312 and 40 in sequence lengths 128 and 512 are not available due to out of memory errors that arise.

Pre-training training performance: Multi-node on NVIDIA DGX A100 (8x A100 80GB)

Our results were obtained by running the scripts/run_pretraining_lamb.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX A100 with 8x A100 40GB GPUs. Performance (in sequences per second) is the steady state throughput.

Num NodesSequence LengthBatch size / GPU: mixed precision, TF32Gradient Accumulation: mixed precision, TF32Global Batch Size: mixed precision, FP32Throughput - mixed precisionThroughput - TF32Throughput speedup (TF32 - mixed precision)Weak scaling - mixed precisionWeak scaling -TF32
1128312 , 17632 , 6479872 , 901123803.822062.981.841.001.00
2128312 , 17616 , 3279872 , 901127551.374084.761.851.991.98
8128312 , 1764 , 879872 , 9011229711.1116134.021.847.817.82
32128312 , 1761 , 279872 , 90112110280.7359569.771.8528.9928.88
151240 , 2296 , 19230720 , 33792749.73431.891.741.001.00
251240 , 2248 , 9630720 , 337921491.87739.142.021.991.71
851240 , 2212 , 2430720 , 337925870.832926.582.017.836.78
3251240 , 223 , 630720 , 3379222506.2311240.52.0030.0226.03

Note: The respective values for TF32 runs that use a batch size of 312 and 40 in sequence lengths 128 and 512 are not available due to out of memory errors that arise.

Fine-tuning training performance for SQuAD v1.1 on NVIDIA DGX-1 V100 (8x V100 16GB)

Our results were obtained by running the scripts/run_squad.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX-1 with 8x V100 16GB GPUs. Performance (in sequences per second) is the mean throughput from 2 epochs.

GPUsBatch size / GPU: mixed precision, FP32Throughput - mixed precisionThroughput - FP32Throughput speedup (FP32 to mixed precision)Weak scaling - FP32Weak scaling - mixed precision
16,339.109.853.971.001.00
46,3128.4836.523.523.293.71
86,3255.3673.033.56.537.41

Note: The respective values for FP32 runs that use a batch size of 6 are not available due to out of memory errors that arise. Batch size of 6 is only available on using FP16.

To achieve these same results, follow the Quick Start Guide outlined above.

Fine-tuning training performance for SQuAD v1.1 on NVIDIA DGX-1 V100 (8x V100 32GB)

Our results were obtained by running the scripts/run_squad.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX-1 with 8x V100 32GB GPUs. Performance (in sequences per second) is the mean throughput from 2 epochs.

GPUsBatch size / GPU: mixed precision, FP32Throughput - mixed precisionThroughput - FP32Throughput speedup (FP32 to mixed precision)Weak scaling - FP32Weak scaling - mixed precision
112,847.0611.114.241.001.00
412,8165.2642.843.863.513.86
812,8330.2985.913.847.027.73

Note: The respective values for FP32 runs that use a batch size of 12 are not available due to out of memory errors that arise. Batch size of 12 is only available on using FP16.

To achieve these same results, follow the Quick Start Guide outlined above.

Fine-tuning training performance for SQuAD v1.1 on NVIDIA DGX A100 (8x A100 80GB)

Our results were obtained by running the scripts/run_squad.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX-2 with 16x V100 32GB GPUs. Performance (in sequences per second) is the mean throughput from 2 epochs.

GPUsBatch size / GPU: mixed precision, TF32Throughput - mixed precisionThroughput - FP32Throughput speedup (FP32 to mixed precision)Weak scaling - FP32Weak scaling - mixed precision
176,38134.2243.93.0571.001.00
876,381048.23341.313.0717.817.77

Note: The respective values for TF32 runs that use a batch size of 76 are not available due to out of memory errors that arise. Batch size of 12 is only available on using FP16.

To achieve these same results, follow the Quick Start Guide outlined above.

Inference performance results

Fine-tuning inference performance for SQuAD v1.1 on NVIDIA DGX-1 V100 (1x V100 16GB)

Our results were obtained by running the scripts/finetune_inference_benchmark.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX-1 with 1x V100 16GB GPUs. Performance numbers (throughput in sequences per second and latency in milliseconds) were averaged from 1000 iterations. Latency is computed as the time taken for a batch to process as they are fed in one after another in the model ie no pipelining.

BERT-LARGE FP16

Sequence LengthBatch SizeThroughput-Average(seq/sec)Throughput speedup (FP32 to mixed precision)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281105.041.2772373549.529.679.7710.16
1282184.91.67148797710.8211.1511.2711.8
1284301.92.44810249813.2513.3813.4513.96
1288421.983.14980965918.9619.1219.219.82
384174.992.1505592213.3413.513.5814.53
3842109.842.70942279218.2118.418.619.39
3844142.583.31350220828.0528.2828.4828.85
3848168.343.82330229447.5247.7447.8648.52

BERT-Large FP32

Sequence LengthBatch SizeThroughput-Average(seq/sec)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
128182.2412.1612.2812.3312.92
1282110.6218.0818.2218.2818.88
1284123.3232.4432.7232.8232.98
1288133.9759.7160.2960.4960.69
384134.8728.6728.9229.0229.33
384240.5449.3449.7449.8650.05
384443.0392.9793.5993.7594.57
384844.03181.71182.34182.48183.03

BERT-Base FP16

Sequence LengthBatch SizeThroughput-Average(seq/sec)Throughput speedup (FP32 to mixed precision)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281236.261.1795895954.234.374.494.59
1282425.11.4415544784.74.844.975.26
1284710.481.9116911075.635.785.936.4
12881081.172.5230327647.47.57.547.73
3841190.531.7571705255.255.355.425.8
3842289.672.2482924566.97.087.247.57
3844404.032.9463283029.91010.0310.13
3848504.243.45015395115.8715.9616.0116.3

BERT-Base FP32

Sequence LengthBatch SizeThroughput-Average(seq/sec)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281200.294.995.085.165.53
1282294.896.786.896.937.37
1284371.6510.7610.8910.9611.92
1288428.5218.6718.8918.9819.17
3841108.439.229.269.3110.24
3842128.8415.5215.615.7116.49
3844137.1329.1729.429.4829.64
3848146.1554.7455.1955.355.54

To achieve these same results, follow the Quick Start Guide outlined above.

Fine-tuning inference performance for SQuAD v1.1 on NVIIDA DGX-1 V100 (1x V100 32GB)

Our results were obtained by running the scripts/finetune_inference_benchmark.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX-1 with 1x V100 32GB GPUs. Performance numbers (throughput in sequences per second and latency in milliseconds) were averaged from 1000 iterations. Latency is computed as the time taken for a batch to process as they are fed in one after another in the model ie no pipelining.

BERTLarge FP16

Sequence LengthBatch SizeThroughput-Average(seq/sec)Throughput speedup (FP32 to mixed precision)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281101.581.2421129869.849.9910.0610.39
1282181.891.6515935711111.1411.211.87
1284295.862.34884090213.5213.6713.7514.5
1288411.293.01024665219.4519.6219.6920.4
384172.952.08369037413.7113.9314.0814.81
3842107.022.58377595418.6918.818.8819.57
3844139.83.1465226228.6128.7528.8829.6
3848163.683.59578207448.8849.0949.1849.77

BERT-Large FP32

Sequence LengthBatch SizeThroughput-Average(seq/sec)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
128181.7812.2312.3712.4313.2
1282110.1318.1618.2918.3719.27
1284125.9631.7632.0932.2132.42
1288136.6358.5558.9359.0559.4
384135.0128.5628.8128.9429.16
384241.4248.2948.5748.6749.02
384444.4390.0390.4390.5990.89
384845.52175.76176.66176.89177.33

BERT-Base FP16

Sequence LengthBatch SizeThroughput-Average(seq/sec)Throughput speedup (FP32 to mixed precision)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281234.851.2175333094.264.334.374.62
1282415.861.4357823514.814.925.065.55
1284680.091.849125865.886.16.26.53
12881030.032.2645487527.777.877.958.53
3841183.181.7009935935.465.565.615.93
3842275.772.1755285587.257.387.447.89
3844385.612.77857039910.3710.5610.6311.1
3848488.453.29232946916.3816.4816.5216.64

BERT-Base FP32

Sequence LengthBatch SizeThroughput-Average(seq/sec)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281192.895.185.35.365.65
1282289.646.9177.227.83
1284367.7910.8810.9811.0211.59
1288454.8517.5917.7617.8117.92
3841107.699.299.379.429.88
3842126.7615.7815.8915.9716.72
3844138.7828.8228.9829.0629.88
3848148.3653.9254.1654.2654.58

To achieve these same results, follow the Quick Start Guide outlined above.

Fine-tuning inference performance for SQuAD v1.1 on NVIDIA DGX A100 (1x A100 80GB)

Our results were obtained by running the scripts/finetune_inference_benchmark.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA DGX-2 with 1x V100 32GB GPUs. Performance numbers (throughput in sequences per second and latency in milliseconds) were averaged from 1000 iterations. Latency is computed as the time taken for a batch to process as they are fed in one after another in the model ie no pipelining.

BERT-Large FP16

Sequence LengthBatch SizeThroughput-Average(seq/sec)Throughput speedup (FP32 to mixed precision)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281145.210.94353476286.897.147.48.35
1282272.811.0939530037.337.617.778.35
1284468.981.2730875738.538.718.839.85
1288705.671.19162768711.3411.6411.913.1
3841118.341.0424594798.458.828.999.52
3842197.81.23147802310.1110.4810.6211.4
3844275.191.26833202714.5414.7314.816.8
3848342.221.41600463423.3823.6423.7524.1

BERT-Large TF32

Sequence LengthBatch SizeThroughput-Average(seq/sec)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281153.96.56.766.867.4
1282249.388.028.228.349.45
1284368.3810.8611.1111.2412.76
1288592.1913.5113.6413.7715.85
3841113.528.819.029.1610.19
3842160.6212.4512.6112.6814.47
3844216.9718.4418.618.718.84
3848241.6833.133.2933.3633.5

BERT-Base FP16

Sequence LengthBatch SizeThroughput-Average(seq/sec)Throughput speedup (FP32 to mixed precision)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281295.011.0140239923.393.593.653.73
1282594.811.0484558983.363.593.684.19
12841043.121.0051455993.833.974.24.44
12881786.251.1982786384.484.734.85.19
3841278.851.1033950623.593.673.994.15
3842464.771.2520068964.34.594.875.29
3844675.821.2648225785.926.156.276.94
3848846.811.311094949.459.659.7411.03

BERT-Base TF32

Sequence LengthBatch SizeThroughput-Average(seq/sec)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281290.933.443.613.734.69
1282567.323.533.643.965.01
12841037.783.853.954.064.58
12881490.685.375.615.666.19
3841252.723.963.964.524.66
3842371.225.395.645.716.38
3844534.327.497.697.768.56
3848645.8812.3912.6112.6712.77

To achieve these same results, follow the Quick Start Guide outlined above.

Fine-tuning inference performance for SQuAD v1.1 on NVIDIA Tesla T4 (1x T4 16GB)

Our results were obtained by running the scripts/finetune_inference_benchmark.sh training script in the TensorFlow 21.02-py3 NGC container on NVIDIA Tesla T4 with 1x T4 16GB GPUs. Performance numbers (throughput in sequences per second and latency in milliseconds) were averaged from 1000 iterations. Latency is computed as the time taken for a batch to process as they are fed in one after another in the model ie no pipelining.

BERT-Large FP16

Sequence LengthBatch SizeThroughput-Average(seq/sec)Throughput speedup (FP32 to mixed precision)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
128157.61.36460554417.3618.1619.0221.67
1282102.762.1798896919.4620.6821.2722.2
1284151.113.14681382826.4726.927.0627.45
1288186.993.73308045542.7843.8744.1844.78
384138.882.59027315125.7226.0626.1626.38
384250.533.20215462639.5839.9340.3540.95
384457.693.72193548469.3470.570.7771.09
384862.993.927057357127129.18130.07131.86

BERT-Large FP32

Sequence LengthBatch SizeThroughput-Average(seq/sec)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
128142.2123.6924.825.0225.48
128247.1442.4243.4843.6344.32
128448.0283.2984.3784.6885.14
128850.09159.72161.66161.97162.52
384115.0166.6367.7668.0868.66
384215.78126.78128.21128.58129.08
384415.5258.1261.01261.66262.55
384816.04498.61504.29504.74505.55

BERT-Base FP16

Sequence LengthBatch SizeThroughput-Average(seq/sec)Throughput speedup (FP32 to mixed precision)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281116.561.0398786698.589.5310.8411.74
1282238.621.6759376328.389.099.2712.33
1284402.932.4409644399.9310.0710.1312.17
1288532.563.05261951215.0215.4315.616.52
3841102.122.0350737359.7911.0611.1812.07
3842149.32.91089881113.413.5413.6214.36
3844177.783.56343956722.523.1123.2723.59
3848192.613.75238651941.5342.6742.8143.31

BERT-Base FP32

Sequence LengthBatch SizeThroughput-Average(seq/sec)Latency-Average(ms)Latency-90%(ms)Latency-95%(ms)Latency-99%(ms)
1281112.098.929.129.4910.93
1282142.3814.0514.3414.4815.03
1284165.0724.2324.8624.9225.05
1288174.4645.8646.7146.847.2
384150.1819.9320.5321.0421.73
384251.2938.9939.6839.9340.2
384449.8980.1881.548282.65
384851.33155.85158.11158.5159.17

To achieve these same results, follow the Quick Start Guide outlined above.