AI Logic

Architectures

LightSpeech

Updated:

LightSpeech's architecture and search procedure. The left side shows the discovered architecture (phoneme sequence → phoneme embedding → encoder (depthwise separable convolutions with k = 5, 25, 13, 9) → variance adaptor (duration and pitch predictors switched to depthwise separable convolutions, energy predictor removed) → decoder (depthwise separable convolutions with k = 17, 21, 9, 13) → linear layer → mel spectrogram → Parallel WaveGAN → speech waveform). The right side shows the search procedure (search space of 11 candidates per layer × 8 layers → train a weight-sharing supernet → measure the validation loss of 1,000 architectures → predict loss with a GBDT → re-measure the top 300 → select the architecture with the lowest validation loss)

Background and Overview

LightSpeech is a lightweight, fast text-to-speech (TTS) model based on FastSpeech 2 whose encoder and decoder shapes were determined automatically by neural architecture search (NAS) over a search space containing only lightweight operations. Luo et al. of the University of Science and Technology of China and Microsoft presented it at ICASSP 2021.

Non-autoregressive models such as FastSpeech and FastSpeech 2 can generate speech much faster than autoregressive models. Even so, they were still large and slow for running on smartphones, embedded devices, or low-cost services with only CPUs. For example, FastSpeech 2 has 27M parameters, uses more than 100 MB of memory, and is about 10 times slower on a CPU than on a GPU.

Ways to lighten a model include reducing layers or narrowing widths, quantization, and pruning. However, making layers shallower and narrower by hand degraded audio quality considerably. LightSpeech therefore builds the model in three steps.

  1. Find the heavy parts: Measure the number of parameters and the CPU inference time of each FastSpeech 2 component.
  2. Design the search space: Make the heavy parts (the encoder and decoder) replaceable by combinations of lightweight operations.
  3. Search with NAS: Use an accuracy-prediction-based NAS (GBDT-NAS) to select the combination with the lowest loss on validation data.

The results on LJ Speech are as follows.

  • Audio quality: On par with FastSpeech 2 (CMOS +0.04)
  • Size: Parameters reduced from 27.0M to 1.8M, about 1/15
  • Computation: Multiply-accumulate operations (MACs) reduced from 12.50G to 0.76G, about 1/16
  • Speed: About 6.5 times faster inference on a CPU

Finding the Heavy Parts

LightSpeech first measures the size and speed of each FastSpeech 2 component to decide what to lighten. Measurements were made on a CPU (Intel Xeon E5-2690 v4) with 1 thread, 1 core, and batch size 1. RTF is the number of seconds needed to generate 1 second of audio.

ComponentStructureParametersRTF
FastSpeech 2 overall-27.02M6.1×10−26.1 \times 10^{-2}
Encoder4 Transformer blocks11.56M8.1×10−38.1 \times 10^{-3}
Decoder4 Transformer blocks11.54M4.1×10−24.1 \times 10^{-2}
Duration predictor2 convolutional layers0.40M4.2×10−44.2 \times 10^{-4}
Pitch predictor5 convolutional layers1.64M4.8×10−34.8 \times 10^{-3}
Energy predictor5 convolutional layers1.64M4.6×10−34.6 \times 10^{-3}

From this table, two policies were set.

  • Lighten the encoder and decoder by search: They account for most of the size and time. The decoder in particular processes a sequence whose length is the number of frames rather than phonemes, so it takes longer.
  • Lighten the predictors by hand: The predictors account for about a third of the total, but their structure is simple, so their operations are replaced without search.

The predictor structure in this table (pitch and energy predictors with 5 convolutional layers of kernel width 5) is that of the FastSpeech 2 measured in the LightSpeech paper. It differs from the predictors described in the appendix of the FastSpeech 2 paper (2 convolutional layers of kernel width 3).

Search Space and Search Procedure

LightSpeech's search space selects one of 11 operations for each of the 4 encoder layers and 4 decoder layers. The right side of the figure at the top of the article shows the search space and the search procedure.

The 11 candidates for each layer are as follows.

  • Multi-head self-attention: 3 variants with 2, 4, or 8 heads
  • Depthwise separable convolution (SepConv): 7 variants with kernel widths 1, 5, 9, 13, 17, 21, or 25
  • Feed-forward: 1 variant made of a 1D convolution and a fully connected layer

The Transformer block is split into self-attention and feed-forward, which become separate candidates. LSTM is not included because its inference is slow.

Depthwise separable convolution is a much lighter operation than standard convolution. With kernel width KK, input dimension IdI_d, and output dimension OdO_d, the numbers of parameters are as follows.

Standard convolution: K×Id×Od,SepConv: K×Id+Id×Od\text{Standard convolution: } K \times I_d \times O_d, \qquad \text{SepConv: } K \times I_d + I_d \times O_d

With hidden dimension 256 and kernel width 9, a standard convolution has 9×256×256≈5909 \times 256 \times 256 \approx 590 thousand parameters and SepConv has 9×256+256×256≈689 \times 256 + 256 \times 256 \approx 68 thousand, about 1/9.

Choosing from 11 operations for each of 8 layers gives 118=214,358,88111^8 = 214{,}358{,}881 (about 210 million) architectures. Training and comparing all of them is impossible, so GBDT-NAS is used. It trains a GBDT (gradient boosting decision tree) on "architecture → accuracy" pairs and predicts the accuracy of the remaining vast number of architectures. Since MOS, a human rating of audio quality, cannot be measured during search, validation loss is used in place of accuracy. For non-autoregressive models, validation loss correlates highly with final audio quality.

The search proceeds as follows.

  1. Train the supernet: One large network containing all candidates (the supernet) is trained for 20,000 steps with weights shared among candidates. Weight sharing follows the same idea as ENAS.
  2. Measure 1,000 architectures: Sample 1,000 architectures from the supernet and measure their validation loss.
  3. Train the GBDT: Train a GBDT with 100 trees and 31 leaves on the 1,000 "architecture → validation loss" pairs.
  4. Predict all architectures: Because the search space is not that large, the GBDT predicts the loss of all ~210 million architectures, and the top 300 are selected.
  5. Re-select: Re-measure the top 300 with the supernet and pick the architecture with the lowest validation loss.

The search finished in 4 hours on 4 NVIDIA P40 GPUs.

The predictors (duration and pitch) are not searched; their convolutions are simply replaced by SepConv with the same kernel width. The energy predictor is removed from the start, since a preliminary experiment showed that removing it barely affected audio quality.

The Discovered Architecture

The architecture found by NAS uses depthwise separable convolutions throughout both the encoder and the decoder. Not a single one of the self-attention or feed-forward candidates was selected.

Part4 layers (from input side)
EncoderSepConv (k=5k = 5) → SepConv (k=25k = 25) → SepConv (k=13k = 13) → SepConv (k=9k = 9)
DecoderSepConv (k=17k = 17) → SepConv (k=21k = 21) → SepConv (k=9k = 9) → SepConv (k=13k = 13)
Variance adaptorDuration and pitch predictors (convolutions replaced with SepConv); no energy predictor

The hidden dimension is 256, the same as FastSpeech 2. kk is the kernel width.

Convolutions with wide kernels of 13 to 25 were selected. Widening a convolution lets it see a broad range of context even without self-attention. Because SepConv's parameter count grows little as the width increases, it achieves both lightness and a wide view.

Experimental Results

Audio quality (LJ Speech test set, CMOS, with FastSpeech 2 as 0)

ModelParametersCMOS
FastSpeech 227.0M0
FastSpeech 2* (lightened by hand)1.8M−0.230-0.230
LightSpeech1.8M+0.04+0.04

FastSpeech 2* is a model made the same size as LightSpeech by using 2 Transformer blocks each for the encoder and decoder, hidden dimension 128, feed-forward dimension 256, removing the energy predictor, and using SepConv in the predictors. The paper considers a CMOS within ±0.05\pm 0.05 to be on par. At the same size, making the model shallower and narrower by hand degrades audio quality considerably, but the architecture found by NAS did not.

Size and speed (CPU with 1 thread and 1 core; MACs measured for an example with input length 128 and output length 740)

ModelParametersMACsRTF on CPU
FastSpeech 227.0M12.50G6.1×10−26.1 \times 10^{-2}
LightSpeech1.8M (1/15)0.76G (1/16)9.3×10−39.3 \times 10^{-3} (6.5x faster)

Effect of each idea

What was examinedWhat was comparedResult
Using SepConv in the predictorsDuration and pitch lossesBoth unchanged (0.12 and 0.85)
Quality of the search spaceMel-spectrogram validation lossThe mean of 10 architectures randomly drawn from the search space, 0.2753, is lower than FastSpeech 2*'s 0.2956
Quality of NASMel-spectrogram validation lossLightSpeech at 0.2561, on par with FastSpeech 2 (0.2575)

Since even randomly chosen architectures beat the hand-lightened one, the design of the search space itself clearly contributes.

Practical Considerations

Keep the following points in mind when using LightSpeech.

  • Evaluated on a single English speaker only: The paper's experiments use only LJ Speech. The same architecture is not necessarily best for many speakers or other languages.
  • Audio quality was compared only by CMOS: Absolute MOS values are not reported, and the only comparison is with FastSpeech 2.
  • The search objective is validation loss: The search minimizes validation loss as a proxy for audio quality. Speed and memory are not directly part of the search objective; lightness is ensured by limiting candidates to lightweight operations.
  • CPU speed figures are server values: RTF was measured on one core of a server CPU. The paper notes that on devices with less computing power, FastSpeech 2 inference becomes even slower.
  • Architectural details follow FastSpeech 2: The paper describes only each layer's operation and kernel width. For details such as residual connections and normalization, it only says they follow FastSpeech 2.
  • A separate vocoder is needed: The output is a mel spectrogram. In the paper, a pretrained Parallel WaveGAN turns it into a waveform.

The discovered architecture (all SepConv) was selected by validation loss on LJ Speech. When using it for other data or purposes, it is safer to search again over the same search space. The paper's conclusion also lists combining NAS with pruning and quantization as future work.

Comparison with Other Methods

Comparing ways to lighten FastSpeech 2 from the same angles gives the following.

MethodHow the architecture is decidedParametersAudio quality (CMOS vs. FastSpeech 2)
FastSpeech 2Human design (4 Transformer blocks each)27.0M0
FastSpeech 2* (shallower and narrower)Human design (2 blocks each, dimension 128)1.8M−0.230-0.230
LightSpeechNAS (GBDT-NAS) choosing from 11 options × 8 layers1.8M+0.04+0.04

As NAS methods, they compare as follows.

NAS methodHow architectures are searchedHow candidates are evaluated
NAS with reinforcement learningAn RNN outputs architectures and is trained with accuracy as the rewardEach candidate is trained from scratch
ENASArchitectures are chosen by reinforcement learningEvaluated with a weight-sharing network
DARTSThe choice of operations is made continuous and optimized by gradientsA single network is trained
GBDT-NAS (used by LightSpeech)A GBDT predicts accuracy and top architectures are selectedEvaluated with a weight-sharing supernet

Rough guidelines for choosing are as follows.

  • To run speech synthesis on CPUs or small devices: LightSpeech's architecture (an encoder and decoder of SepConv only) is a starting point.
  • When audio quality comes first and GPUs are available: FastSpeech 2 has a clearer configuration and many implementations.
  • To lighten image models: There are MobileNet, lightened with depthwise separable convolutions, and MnasNet, found by NAS.

PyTorch example

Show code
python
import torch
import torch.nn as nn

"""
A small implementation of LightSpeech's search space and discovered architecture (Sections 2.2 and 3.4 of the paper)
PyTorch has no built-in LightSpeech
1. 11 candidates per layer: self-attention (2, 4, 8 heads), SepConv (widths 1, 5, 9, 13, 17, 21, 25), feed-forward
2. Discovered architecture: encoder SepConv k = 5, 25, 13, 9; decoder SepConv k = 17, 21, 9, 13 (hidden size 256)
3. The paper does not specify how residual connections and layer normalization are applied, so this example follows FastSpeech's FFT block
"""


class SepConv(nn.Module):
    """Depthwise convolution (per channel) → 1x1 pointwise convolution. Parameters: K*d + d*d (excluding bias)"""
    def __init__(self, d, k):
        super().__init__()
        self.depthwise = nn.Conv1d(d, d, k, padding=k // 2, groups=d, bias=False)
        self.pointwise = nn.Conv1d(d, d, 1)

    def forward(self, x):                        # x: [B, T, d]
        return self.pointwise(self.depthwise(x.transpose(1, 2))).transpose(1, 2)


class MHSA(nn.Module):
    def __init__(self, d, heads):
        super().__init__()
        self.attn = nn.MultiheadAttention(d, heads, batch_first=True)

    def forward(self, x):
        return self.attn(x, x, x, need_weights=False)[0]


class FFN(nn.Module):
    """The TTS FFN: one 1D convolutional layer and one fully connected layer (footnote 2 of the paper)"""
    def __init__(self, d, d_ff=1024, k=9):
        super().__init__()
        self.conv = nn.Conv1d(d, d_ff, k, padding=k // 2)
        self.fc = nn.Linear(d_ff, d)

    def forward(self, x):
        return self.fc(torch.relu(self.conv(x.transpose(1, 2))).transpose(1, 2))


CANDIDATES = [("mhsa", h) for h in (2, 4, 8)] + [("sepconv", k) for k in (1, 5, 9, 13, 17, 21, 25)] + [("ffn", None)]
print(len(CANDIDATES), len(CANDIDATES) ** 8)     # 11 214358881


def make_op(name, arg, d=256):
    return {"mhsa": lambda: MHSA(d, arg), "sepconv": lambda: SepConv(d, arg), "ffn": lambda: FFN(d)}[name]()


class Layer(nn.Module):
    def __init__(self, op, d=256, p=0.1):
        super().__init__()
        self.op, self.norm, self.drop = op, nn.LayerNorm(d), nn.Dropout(p)

    def forward(self, x):
        return self.norm(x + self.drop(self.op(x)))


def build(arch, d=256):
    return nn.Sequential(*[Layer(make_op(n, a, d), d) for n, a in arch])


# The architecture discovered in Section 3.4 of the paper
encoder = build([("sepconv", 5), ("sepconv", 25), ("sepconv", 13), ("sepconv", 9)])
decoder = build([("sepconv", 17), ("sepconv", 21), ("sepconv", 9), ("sepconv", 13)])

# Compare parameter counts with a standard convolution (d = 256, k = 9)
conv = nn.Conv1d(256, 256, 9, bias=False)
sep = SepConv(256, 9)
print(sum(p.numel() for p in conv.parameters()))                 # 589824
print(sum(p.numel() for p in sep.parameters()))                  # 2304 + 65536 + 256 (bias) = 68096

x = torch.randn(2, 50, 256)                      # phoneme embeddings (50 phonemes)
encoder.eval()                                   # turn off dropout
with torch.no_grad():
    h = encoder(x)                               # next: duration/pitch predictors (SepConv) and the length regulator, then the decoder
print(h.shape)

FAQ

Q. How does LightSpeech differ from FastSpeech 2?
A.

The overall flow (encoder → variance adaptor → decoder) is the same as FastSpeech 2. The differences are that each encoder and decoder layer is a depthwise separable convolution chosen by NAS rather than a Transformer block, that the predictors' convolutions are also SepConv, and that the energy predictor is removed.

Q. Why was self-attention not selected by the search?
A.

The paper does not analyze the reason. As it turned out, the combination of SepConvs with wide kernels (13 to 25) had the lowest validation loss. Wide convolutions can see a broad range of context even without self-attention, and SepConv needs only K×Id+Id×OdK \times I_d + I_d \times O_d parameters.

Q. How much computation does the search require?
A.

In the paper, it took 4 hours on 4 NVIDIA P40 GPUs. A weight-sharing supernet is trained for 20,000 steps, a GBDT is trained on the validation losses of 1,000 architectures, and the losses of about 210 million architectures are predicted. This requires far less computation than NAS with reinforcement learning, which trains each candidate from scratch.

References

  1. Luo, R., Tan, X., Wang, R., Qin, T., Li, J., Zhao, S., Chen, E., & Liu, T.-Y. (2021). LightSpeech: Lightweight and Fast Text to Speech with Neural Architecture Search. ICASSP 2021. arXiv:2102.04040.
  2. LightSpeech audio samples (by the paper's authors)
  3. Ren, Y., Hu, C., Tan, X., Qin, T., Zhao, S., Zhao, Z., & Liu, T.-Y. (2021). FastSpeech 2: Fast and High-Quality End-to-End Text to Speech. ICLR 2021. arXiv:2006.04558.
  4. Luo, R., Tan, X., Wang, R., Qin, T., Chen, E., & Liu, T.-Y. (2020). Accuracy Prediction with Non-neural Model for Neural Architecture Search (GBDT-NAS; the first version was titled Neural Architecture Search with GBDT). arXiv:2007.04785.
  5. Kaiser, L., Gomez, A. N., & Chollet, F. (2018). Depthwise Separable Convolutions for Neural Machine Translation. ICLR 2018. arXiv:1706.03059.