Decoder: 6 layers

yny_n [B, T, 512], zz [B, S, 512], MM [B, 1, 1, S]to yn+1y_{n+1} [B, T, 512]

Parameters4,204,032 × 6 layers

4,204,032 parameters per layer, across its learned components

ComponentCalculationParameters
Masked multi-head self-attention1,050,624
LayerNorm512 + 5121,024
Encoder–decoder attention1,050,624
LayerNorm512 + 5121,024
Position-wise feed-forward network2,099,712
LayerNorm512 + 5121,024
Per-instance total4,204,032

One of 6 independent layers.

No trained weights were published to check against.

Explanation

In addition to the two sublayers of an encoder layer, the decoder inserts a third, which performs multi-head attention over the output of the encoder stack (§3.1).

Sources

In codetransformer_decoder(decoder_input, encoder_output, residual_fn, …) · transformer.py 170–226

Open pinned code ↗

Direct evidence

Each decoder layer: masked self-attention, attention over the encoder output with the encoder padding bias, then the feed-forward network, each through residual_fn.

transformer.py 170–226 ↗ · tensorflow/tensor2tensor @ 0c66117d4297

Excerpt
def transformer_decoder(decoder_input,
                        encoder_output,
                        residual_fn,
                        decoder_self_attention_bias,
                        encoder_decoder_attention_bias,
                        hparams,
                        name="decoder"):
  """A stack of transformer layers.

  Args:
    decoder_input: a Tensor
    encoder_output: a Tensor
    residual_fn: a function from (layer_input, layer_output) -> combined_output
    decoder_self_attention_bias: bias Tensor for self-attention
      (see common_attention.attention_bias())
    encoder_decoder_attention_bias: bias Tensor for encoder-decoder attention
      (see common_attention.attention_bias())
    hparams: hyperparameters for model
    name: a string

  Returns:
    y: a Tensors
  """
  x = decoder_input
  # Summaries don't work in multi-problem setting yet.
  summaries = "problems" not in hparams.values() or len(hparams.problems) == 1
  with tf.variable_scope(name):
    for layer in xrange(hparams.num_hidden_layers):
      with tf.variable_scope("layer_%d" % layer):
        x = residual_fn(
            x,
            common_attention.multihead_attention(
                x,
                None,
                decoder_self_attention_bias,
                hparams.attention_key_channels or hparams.hidden_size,
                hparams.attention_value_channels or hparams.hidden_size,
                hparams.hidden_size,
                hparams.num_heads,
                hparams.attention_dropout,
                summaries=summaries,
                name="decoder_self_attention"))
        x = residual_fn(
            x,
            common_attention.multihead_attention(
                x,
                encoder_output,
                encoder_decoder_attention_bias,
                hparams.attention_key_channels or hparams.hidden_size,
                hparams.attention_value_channels or hparams.hidden_size,
                hparams.hidden_size,
                hparams.num_heads,
                hparams.attention_dropout,
                summaries=summaries,
                name="encdec_attention"))
        x = residual_fn(x, transformer_ffn_layer(x, hparams))
  return x

Post-norm: each sublayer output is dropped out, added to its input and layer-normalized.

transformer.py 59–61 ↗ · tensorflow/tensor2tensor @ 0c66117d4297

Excerpt
    def residual_fn(x, y):
      return common_layers.layer_norm(x + tf.nn.dropout(
          y, 1.0 - hparams.residual_dropout))