NVIDIA
NVIDIA
Transformer-XL for TensorFlow
Resource
NVIDIA
NVIDIA
Transformer-XL for TensorFlow

Transformer-XL is a transformer-based language model with a segment-level recurrence and a novel relative positional encoding.

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.

Training performance benchmark

To benchmark the training performance on a specific global batch size , with a specific number of GPUs `<#GPUs>` for a specific number of training iterations run:

For the base model:

bash run_wt103_base.sh train <#GPUs> --train_batch_size --train_steps --log_interval 1 [--amp] [--batch_chunk CHUNK]

It's recommended to launch at least 1500 training steps to get a reliable estimate of training performance. For more information about the available options, refer to the Training process section.

The training script prints information in the following format:

(...)
[1,0]:INFO:tensorflow:step 99 | lr 0.000990000 | loss 9.22 | pplx 10069.60, bpc 13.2977, tok/s 136092
[1,0]:I0109 12:18:41.333325 140403024426816 main.py:333] step 99 | lr 0.000990000 | loss 9.22 | pplx 10069.60,
bpc 13.2977, tok/s 136092
[1,0]:INFO:tensorflow:step 100 | lr 0.001000000 | loss 9.21 | pplx 9981.87, bpc 13.2851, tok/s 135309
[1,0]:I0109 12:18:41.696926 140403024426816 main.py:333] step 100 | lr 0.001000000 | loss 9.21 | pplx 9981.87,
bpc 13.2851, tok/s 135309
(...)
[1,0]:INFO:tensorflow:Training throughput: 135959 tok/s

The last two lines contain information on the average training throughput measured in tokens per second.

Inference performance benchmark

The inference performance and accuracy benchmarks require a checkpoint from a trained model.

To benchmark the inference performance on a specific global batch size ``, run:

bash run_wt103_base.sh eval --model_dir --eval_batch_size [--amp]

The inference script prints information in the following format:

I0109 13:02:31.304439 139903273469760 main.py:440] Evaluating with: math fp16
INFO:tensorflow:| loss 3.15 | pplx 23.32, bpc 4.5432, tok/s 9946, ms/batch 102.84

The output contains information on the achieved test loss and test perplexity, average inference throughput (measured in tokens per second), average inference latency (measured in milliseconds).

Results

The following sections provide details on how we achieved our performance and accuracy in training and inference.

Training accuracy results

Training accuracy: NVIDIA DGX A100 (8x A100 40GB)
Base model

Our results were obtained by running the tf/run_wt103_base.sh training script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX A100 with8x A100 40GB GPUs.

GPUsBatch Size / GPUAccuracy - TF32 (perplexity)Accuracy - Mixed precision (perplexity)Time to Train - TF32 (minutes)Time to Train - Mixed precision (minutes)Time to Train Speedup (TF32 to Mixed precision)
11623.5323.509608801.09
81623.4523.481501421.06
Training accuracy: NVIDIA DGX-1 (8x V100 16GB)
Base model

Our results were obtained by running the tf/run_wt103_base.sh training script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX-1 with 8x V100 16G GPUs.

GPUsBatch Size / GPUAccuracy - FP32 (perplexity)Accuracy - Mixed precision (perplexity)Time to Train - FP32 (minutes)Time to Train - Mixed precision (minutes)Time to Train Speedup (FP32 to Mixed precision)
11623.6423.58294920211.46
81623.3523.344593431.34
Training accuracy: NVIDIA DGX-2 (16x V100 32GB)
Base model

Our results were obtained by running the tf/run_wt103_base.sh training script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX-2 with 16x V100 32G GPUs.

GPUsBatch Size / GPUAccuracy - FP32 (perplexity)Accuracy - Mixed precision (perplexity)Time to Train - FP32 (minutes)Time to Train - Mixed precision (minutes)Time to Train Speedup (FP32 to Mixed precision)
161623.3923.372021611.25
83223.3323.403302271.46
Training loss plot
Base model

TrainingLossBase

Training stability test
Base model

The Transformer-XL base model was trained for 40,000 training steps, starting from 20 different initial random seeds. The training was performed in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX-1 with 8x V100 16G GPUs. After training, the models were evaluated on the test dataset. The following table summarizes the final perplexity on the test set.

Average perplexityStandard deviationMinimumMaximumMedian
23.380.087923.2423.5823.39

Training performance results

Training performance: NVIDIA DGX A100 (8x A100 40GB)

Our results were obtained by running the tf/run_wt103_base.sh training script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX A100 with 8x A100 40GB GPUs. Performance numbers (in tokens per second) were averaged over 2000 training iterations.

GPUsBatch Size / GPUThroughput - TF32 (tok/s)Throughput - Mixed precision (tok/s)Throughput speedup (TF32 to Mixed precision)Weak Scaling - TF32Weak Scaling - Mixed precision
11625,12726,1301.0401.0001.000
13230,95833,1171.0701.0001.000
16434,24436,4551.0651.0001.000
816157,538155,6560.9886.2705.957
832224,474227,5021.0137.2516.870

To achieve these same results, follow the steps in the Quick Start Guide.

Training performance: NVIDIA DGX-1 (8x V100 16GB)
Base model

Our results were obtained by running the tf/run_wt103_base.sh training script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX-1 with 8x V100 16G GPUs. Performance numbers (in tokens per second) were averaged over 2000 training iterations.

GPUsBatch Size / GPUThroughput - FP32 (tok/s)Throughput - Mixed precision (tok/s)Throughput speedup (FP32 to Mixed precision)Weak Scaling - FP32Weak Scaling - Mixed precision
1169,10413,0041.4281.0001.000
21618,16923,8561.3131.9961.835
41638,87650,3101.2944.2703.869
81678,626101,9541.2978.6367.840

To achieve these same results, follow the steps in the Quick Start Guide.

Training performance: NVIDIA DGX-2 (16x V100 32GB)
Base model

Our results were obtained by running the tf/run_wt103_base.sh training script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX-2 with 16x V100 32G GPUs. Performance numbers (in tokens per second) were averaged over 2000 training iterations.

GPUsBatch Size / GPUThroughput - FP32 (tok/s)Throughput - Mixed precision (tok/s)Throughput speedup (FP32 to Mixed precision)Weak Scaling - FP32Weak Scaling - Mixed precision
1169,89113,7911.3941.0001.000
21621,55028,3061.3142.1792.052
41642,61655,4301.3014.3094.019
81683,932107,9991.2878.4867.831
1616164,675206,9061.25616.64915.003

To achieve these same results, follow the steps in the Quick Start Guide.

Inference performance results

Inference performance: NVIDIA DGX A100 (1x A100 40GB)
Base model

Our results were obtained by running the tf/scripts/inference_benchmark.sh inferencing benchmarking script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX A100 (1x A100 40GB) GPU.

The command to launch the inference performance benchmark is provided in the Inference performance benchmark section.

FP16

Batch sizeSequence lengthMemory lengthThroughput Avg (tok/s)Latency Avg (ms)Latency 90% (ms)Latency 95% (ms)Latency 99% (ms)
1646402592.824.7125.7226.1226.68
2646405060.425.3226.5826.9327.71
4646408910.228.7329.7430.0630.58
86464013844.136.9637.6237.8038.34
166464018313.155.9256.4656.6957.39
326464021854.793.6394.3794.7494.92

TF32

Batch sizeSequence lengthMemory lengthThroughput Avg (tok/s)Latency Avg (ms)Latency 90% (ms)Latency 95% (ms)Latency 99% (ms)
1646402587.624.7525.6325.9226.44
2646405177.824.7325.7126.0326.56
4646409113.628.0929.4029.7130.07
86464013371.738.2738.9539.3440.07
166464016971.060.2960.8861.1361.73
326464019434.5105.29106.00106.19106.79

To achieve these same results, follow the steps in the Quick Start Guide.

Inference performance: NVIDIA DGX-1 (1x V100 16GB)
Base model

Our results were obtained by running the tf/scripts/inference_benchmark.sh inferencing benchmarking script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA DGX-1 with 1x V100 16G GPU.

The command to launch the inference performance benchmark is provided in the Inference performance benchmark section.

FP16

Batch sizeSequence lengthMemory lengthThroughput Avg (tok/s)Latency Avg (ms)Latency 90% (ms)Latency 95% (ms)Latency 99% (ms)
1646401823.835.1737.2738.2241.28
2646403337.638.4641.0941.9443.91
4646405354.047.8349.7450.5453.08
8646407779.765.7967.7168.3769.71
16646409796.5104.46107.22108.07108.69
326464011215.5182.45184.11184.49186.92

FP32

Batch sizeSequence lengthMemory lengthThroughput Avg (tok/s)Latency Avg (ms)Latency 90% (ms)Latency 95% (ms)Latency 99% (ms)
1646401912.733.5635.9836.8438.96
2646403497.036.6639.0739.8541.28
4646404732.954.1056.3257.1058.14
8646406303.781.1983.3284.0288.12
16646407676.3133.29134.84135.33136.70
32646408555.6239.15240.02240.20240.48

To achieve these same results, follow the steps in the Quick Start Guide.

Inference performance: NVIDIA T4
Base model

Our results were obtained by running the tf/scripts/inference_benchmark.sh inferencing benchmarking script in the tensorflow:20.06-tf1-py3 NGC container on NVIDIA T4.

The command to launch the inference performance benchmark is provided in the Inference performance benchmark section.

FP16

Batch sizeSequence lengthMemory lengthThroughput Avg (tok/s)Latency Avg (ms)Latency 90% (ms)Latency 95% (ms)Latency 99% (ms)
1646401228.652.2155.1456.3259.77
2646402108.560.7863.6264.6867.07
4646403376.775.8378.7779.6382.80
8646404666.3109.69112.58113.88117.35
16646405557.0184.14186.51187.20189.64
32646406174.3331.41333.67334.94336.90

FP32

Batch sizeSequence lengthMemory lengthThroughput Avg (tok/s)Latency Avg (ms)Latency 90% (ms)Latency 95% (ms)Latency 99% (ms)
1646401029.762.2865.8266.9370.22
2646401667.776.8179.8080.7184.35
4646402302.3111.13113.75114.85118.57
8646402756.9185.58188.16189.38192.68
16646403188.8320.86324.24325.63327.76
32646403439.1594.96599.13599.89602.59

To achieve these same results, follow the steps in the Quick Start Guide.