NVIDIA Deep Learning Examples
NVIDIA Deep Learning Examples
QuartzNet for PyTorch
Resource
NVIDIA Deep Learning Examples
NVIDIA Deep Learning Examples
QuartzNet for PyTorch

End-to-end neural acoustic model for automatic speech recognition providing high accuracy at a low memory footprint.

The following sections provide greater details of the dataset, running training and inference, and the training results.

Scripts and sample code

In the root directory, the most important files are:

quartznet
|-- common        # data pre-processing, logging, etc.
|-- configs       # model configurations
|-- Dockerfile    # container with the basic set of dependencies to run QuartzNet
|-- inference.py  # entry point for inference
|-- quartznet     # model-specific code
|-- scripts       # one-click scripts required for running various supported functionalities
   |-- docker                     # contains the scripts for building and launching the container
   |-- download_librispeech.sh    # downloads LibriSpeech dataset
   |-- evaluation.sh              # runs evaluation using the `inference.py` script
   |-- inference_benchmark.sh     # runs the inference benchmark using the `inference_benchmark.py` script
   |-- inference.sh               # runs inference using the `inference.py` script
   |-- preprocess_librispeech.sh  # preprocess LibriSpeech raw data files for training and inference
   |-- train_benchmark.sh         # runs the training performance benchmark using the `train.py` script
   |-- train.sh                   # runs training using the `train.py` script
|-- train.py      # entry point for training
|-- utils         # data downloading and common routines

Parameters

Parameters should be set as environment variables.

The complete list of available parameters for scripts/train.sh script contains:

DATA_DIR: directory of dataset. (default: '/datasets/LibriSpeech')
MODEL_CONFIG: relative path to model configuration. (default: 'configs/quartznet10x5dr_speedp_online_speca.yaml')
OUTPUT_DIR: directory for results, logs, and created checkpoints. (default: '/results')
CHECKPOINT: a specific model checkpoint to continue training from. To resume training from the last checkpoint, see the RESUME option.
RESUME: resume training from the last checkpoint found in OUTPUT_DIR, or from scratch if there are no checkpoints (default: true)
CUDNN_BENCHMARK: boolean that indicates whether to enable cudnn benchmark mode for using more optimized kernels. (default: true)
NUM_GPUS: number of GPUs to use. (default: 8)
AMP: if set to `true`, enables automatic mixed precision (default: false)
GPU_BATCH_SIZE: batch size for every forward/backward pass. The effective batch size might be higher, if gradient accumulation is enabled (default: 72)
GRAD_ACCUMULATION: number of forward/backward passes until the optimizer updates weights. (default: 2)
LEARNING_RATE: initial learning rate. (default: 0.01)
MIN_LEARNING_RATE: minimum learning rate, despite LR scheduling (default: 1e-5)
LR_POLICY: how to decay LR (default: exponential)
LR_EXP_GAMMA: decay factor for the exponential LR schedule (default: 0.981)
EMA: decay factor for exponential averages of checkpoints (default: 0.999)
SEED: seed for random number generator and used for ensuring reproducibility. (default: 0)
EPOCHS: number of training epochs. (default: 440)
WARMUP_EPOCHS: number of initial epoch of linearly increasing LR. (default: 2)
HOLD_EPOCHS:  number of epochs to hold maximum LR after warmup. (default: 140)
SAVE_FREQUENCY: number of epochs between saving the model to disk. (default: 10)
EPOCHS_THIS_JOB: run training for this number of epochs. Does not affect LR schedule like the EPOCHS parameter. (default: 0)
DALI_DEVICE: device to run the DALI pipeline on for calculation of filterbanks. Valid choices: cpu, gpu, none. (default: gpu)
PAD_TO_MAX_DURATION: pad all sequences with zeros to maximum length. (default: false)
EVAL_FREQUENCY: number of steps between evaluations on the validation set. (default: 544)
PREDICTION_FREQUENCY: the number of steps between writing a sample prediction to stdout. (default: 544)
TRAIN_MANIFESTS: lists of .json training set files
VAL_MANIFESTS: lists of .json validation set files

The complete list of available parameters for scripts/inference.sh script contains:

DATA_DIR: directory of dataset. (default: '/datasets/LibriSpeech')
MODEL_CONFIG: model configuration. (default: 'configs/quartznet10x5dr_speedp-online_speca.yaml')
OUTPUT_DIR: directory for results and logs. (default: '/results')
CHECKPOINT: model checkpoint path. (required)
DATASET: name of the LibriSpeech subset to use. (default: 'dev-clean')
LOG_FILE: path to the DLLogger .json logfile. (default: '')
CUDNN_BENCHMARK: enable cudnn benchmark mode for using more optimized kernels. (default: false)
MAX_DURATION: filter out recordings shorter then MAX_DURATION seconds. (default: "")
PAD_TO_MAX_DURATION: pad all sequences with zeros to maximum length. (default: false)
NUM_GPUS: number of GPUs to use. Note that with > 1 GPUs WER results might be inaccurate due to the batching policy. (default: 1)
NUM_STEPS: number of batches to evaluate, loop the dataset if necessary. (default: 0)
NUM_WARMUP_STEPS: number of initial steps before measuring performance. (default: 0)
AMP: enable FP16 inference with AMP. (default: false)
BATCH_SIZE: data batch size. (default: 64)
EMA: Attempt to load exponentially averaged weights from a checkpoint. (default: true)
SEED: seed for random number generator and used for ensuring reproducibility. (default: 0)
DALI_DEVICE: device to run the DALI pipeline on for calculation of filterbanks. Valid choices: cpu, gpu, none. (default: gpu)
CPU: run inference on CPU. (default: false)
LOGITS_FILE: dump logit matrices to a file. (default: "")
PREDICTION_FILE: save predictions to a file. (default: "${OUTPUT_DIR}/${DATASET}.predictions")

The complete list of available parameters for scripts/evaluation.sh is the same as scripts/inference.sh. Only the defaults have changed.

PREDICTION_FILE: (default: "")
DATASET: (default: "test-other")

The scripts/inference_benchmark.sh script pads all input to a fixed duration and computes the mean, 90%, 95%, 99% percentile of latency for the specified number of inference steps. Latency is measured in milliseconds per batch. The scripts/inference_benchmark.sh measures latency for a single GPU and loops over a number of batch sizes and durations. It extends scripts/inference.sh and changes the defaults with:

BATCH_SIZE_SEQ: batch sizes to measure with. (default: "1 2 4 8 16")
MAX_DURATION_SEQ: input durations (in seconds) to measure with (default: "2 7 16.7")
CUDNN_BENCHMARK: (default: true)
PAD_TO_MAX_DURATION: (default: true)
NUM_WARMUP_STEPS: (default: 10)
NUM_STEPS: (default: 500)
DALI_DEVICE: (default: "cpu")

The scripts/train_benchmark.sh script pads all input to the same length according to the input argument MAX_DURATION and measures average training latency and throughput performance. Latency is measured in seconds per batch, throughput in sequences per second. Training performance is measured with online speed perturbation and NVIDIA cuDNN benchmark mode enabled. The script scripts/train_benchmark.sh loops over a number of batch sizes and GPU counts. It extends scripts/train.sh, the complete list of available parameters for scripts/train_benchmark.sh script contains:

ACC_BATCH_SIZE: accumulated (effective) batch size to measure with. (default: "144")
GRAD_ACC_SEQ: the sequence of gradient accumulation settings to measure with. (default: "4 2")
NUM_GPUS_SEQ: number of GPUs to run the training on. (default: "1 4 8")
MODEL_CONFIG: (default: "configs/quartznet10x5dr_speedp-online_train-benchmark.yaml")
TRAIN_MANIFESTS: (default: "$DATA_DIR/librispeech-train-clean-100-wav.json")
RESUME: (default: false)
EPOCHS_THIS_JOB: (default: 2)
EPOCHS: (default: 100000)
SAVE_FREQUENCY: (default: 100000)
EVAL_FREQUENCY: (default: 100000)
GRAD_ACCUMULATION_STEPS: (default: 1)
PAD_TO_MAX_DURATION: (default: true)
EMA: (default: 0)

Command-line options

To see the full list of available options and their descriptions, use the -h or --help command-line option, for example:

python train.py --help
python inference.py --help

Getting the data

QuartzNet is trained on the LibriSpeech dataset. We use the concatenation of train-clean-100, train-clean-360, and train-other-500 for training and dev-clean for validation.

This repository contains the scripts/download_librispeech.sh and scripts/preprocess_librispeech.sh scripts that automatically downloads and preprocesses the training, test, and development datasets. By default, data is downloaded to the /datasets/LibriSpeech directory. A minimum of 250GB free space is required for download and preprocessing; the final preprocessed dataset is approximately 100GB.

Dataset guidelines

The scripts/preprocess_librispeech.sh script converts the input audio files to WAV format with a sample rate of 16kHz. The target transcripts are stripped from whitespace characters, then lower-cased. No offline augmentations are stored on the disk - these are computed online with the DALI library without any impact on training time.

After preprocessing, the script creates JSON metadata files with output file paths, sample rate, target transcript and other metadata. These JSON files are used by the training script to identify training and validation datasets.

The QuartzNet model was tuned on audio signals with a sample rate of 16kHz. If you wish to use a different sampling rate, then some hyperparameters might need to be changed - specifically, the window size and step size.

Multi-dataset

Training scripts in this repository treat the training subsets of LibriSpeech (train-clean-100, train-clean-360, train-other-500) as three independent training datasets. In order to add more datasets, follow the format of LibriSpeech, adjust the provided pre-processing scripts to generate metadata JSON files, and point them with the TRAIN_MANIFESTS variable to the scripts/train.sh script.

Training process

Training is performed using the train.py script along with parameters defined in scripts/train.sh. The scripts/train.sh script runs a job on a single node that trains the QuartzNet model from scratch using LibriSpeech as training data. To make training more efficient, we discard audio samples longer than 16.7 seconds from the training dataset, the total number of these samples is less than 1%. Such filtering does not degrade accuracy, but it allows us to decrease the number of time steps in a batch, which requires less GPU memory and increases training speed. Apart from the default arguments as listed in the Parameters section, by default the training script:

  • Runs on 8 GPUs with at least 32GB of memory and training/evaluation batch size 48, split over three gradient accumulation steps
  • Uses TF32 precision (A100 GPU) or FP32 (other GPUs)
  • Trains on the concatenation of all 3 LibriSpeech training datasets and evaluates on the LibriSpeech dev-clean dataset
  • Maintains an exponential moving average of parameters for evaluation
  • Has cuDNN benchmark enabled
  • Runs for 260 epochs
  • Uses an initial learning rate of 0.02 and an exponential learning rate decay
  • Saves a checkpoint every 10 epochs
  • Automatically removes old checkpoints and preserves milestone checkpoints
  • Runs evaluation on the development dataset every epoch and at the end of training
  • Maintains a separate checkpoint with the lowest WER on development set
  • Prints out training progress every iteration to stdout
  • Creates a DLLogger log file and a TensorBoard log
  • Calculates speed perturbation online during training
  • Uses SpecAugment in data pre-processing
  • Filters out audio samples longer than 16.7 seconds
  • Pads each batch so its length is divisible by 16
  • Uses time-channel separable convolutions as described in the paper
  • Uses weight decay of 0.001
  • Uses Novograd as optimizer with betas=(0.95, 0)

Enabling AMP permits batch size 144 with one gradient accumulation step. Since each batch has to be padded to the longest sequence, all GPUs have to wait for the slowest one, and two accumulation steps are slightly faster.

The current training setup improves upon the greedy WER Results of the QuartzNet paper.

Inference process

Inference is performed using the inference.py script along with parameters defined in scripts/inference.sh. The scripts/inference.sh script runs the job on a single GPU, taking a pre-trained QuartzNet model checkpoint and running it on the specified dataset. Apart from the default arguments as listed in the Parameters section, by default, the inference script:

  • Evaluates on the LibriSpeech dev-clean dataset and prints out the final word error rate
  • Uses a batch size of 64
  • Creates a log file with progress and results which will be stored in the results folder
  • Pads each batch so its length would be divisible by 16
  • Does not use data augmentation
  • Does greedy decoding and optionally saves the transcriptions in the results folder
  • Has the option to save the model output tensors for more complex decoding, for example, beam search
  • Has cuDNN benchmark disabled

To view all available options for inference, run python inference.py --help.

NVIDIA uses cookies to improve your experience on our web site. We and our third-party partners also use cookies and other tools to collect and record information you provide as well as information about your interactions with our websites for performance improvement, analytics, and to assist in marketing efforts. By clicking "Accept All", you consent to our use of cookies and other tools as described in our Cookie Policy. You can manage your cookie settings by clicking on "Manage Settings." By continuing to use this site or by clicking one of the buttons below, you agree to our Terms of Service (which contains important waivers). Please see our Privacy Policy for more information on our privacy practices.