class_docstr: Discrete unit Synthesizer related modules for speech-to-speech translation.
  
  This is a module of discrete unit prediction network in discrete-unit described
  in `Direct speech-to-speech translation with discrete units`_,
  which converts the sequence of hidden states into the sequence of
  discrete unit (from SSLs).
  
  .. _`Direct speech-to-speech translation with discrete units`:
     https://arxiv.org/abs/2107.05604
docstr: Transfomer decoder for discrete unit module.
  
  Args:
      vocab_size: output dim
      encoder_output_size: dimension of attention
      attention_heads: the number of heads of multi head attention
      linear_units: the number of units of position-wise feed forward
      num_blocks: the number of decoder blocks
      dropout_rate: dropout rate
      self_attention_dropout_rate: dropout rate for attention
      input_layer: input layer type
      use_output_layer: whether to use output layer
      pos_enc_class: PositionalEncoding or ScaledPositionalEncoding
      normalize_before: whether to use layer_norm before the first block
      concat_after: whether to concat attention layer's input and output
          if True, additional linear will be applied.
          i.e. x -> x + linear(concat(x, att(x)))
          if False, no additional linear will be applied.
          i.e. x -> x + att(x)
      spks (Optional[int]): Number of speakers. If set to > 1, assume that the
          sids will be provided as the input and use sid embedding layer.
      langs (Optional[int]): Number of languages. If set to > 1, assume that the
          lids will be provided as the input and use sid embedding layer.
      spk_embed_dim (Optional[int]): Speaker embedding dimension. If set to > 0,
          assume that spembs will be provided as the input.
      spk_embed_integration_type (str): How to integrate speaker embedding.
docstr_tok: ["Transfomer","decoder","for","discrete","unit","module",".","Args",":","vocab_size",":","output","dim","encoder_output_size",":","dimension","of","attention","attention_heads",":","the","number","of","heads","of","multi","head","attention","linear_units",":","the","number","of","units","of","position-wise","feed","forward","num_blocks",":","the","number","of","decoder","blocks","dropout_rate",":","dropout","rate","self_attention_dropout_rate",":","dropout","rate","for","attention","input_layer",":","input","layer","type","use_output_layer",":","whether","to","use","output","layer","pos_enc_class",":","PositionalEncoding","or","ScaledPositionalEncoding","normalize_before",":","whether","to","use","layer_norm","before","the","first","block","concat_after",":","whether","to","concat","attention","layer","'s","input","and","output","if","True",",","additional","linear","will","be","applied",".","i.e",".","x","-",">","x","+","linear","(","concat","(","x",",","att","(","x",")",")",")","if","False",",","no","additional","linear","will","be","applied",".","i.e",".","x","-",">","x","+","att","(","x",")","spks","(","Optional","[","int","]",")",":","Number","of","speakers",".","If","set","to",">","1",",","assume","that","the","sids","will","be","provided","as","the","input","and","use","sid","embedding","layer",".","langs","(","Optional","[","int","]",")",":","Number","of","languages",".","If","set","to",">","1",",","assume","that","the","lids","will","be","provided","as","the","input","and","use","sid","embedding","layer",".","spk_embed_dim","(","Optional","[","int","]",")",":","Speaker","embedding","dimension",".","If","set","to",">","0",",","assume","that","spembs","will","be","provided","as","the","input",".","spk_embed_integration_type","(","str",")",":","How","to","integrate","speaker","embedding","."]
code: def __init__(
      self,
      # decoder related
      odim: int,
      idim: int,
      attention_heads: int = 4,
      linear_units: int = 2048,
      num_blocks: int = 6,
      dropout_rate: float = 0.1,
      positional_dropout_rate: float = 0.1,
      self_attention_dropout_rate: float = 0.0,
      src_attention_dropout_rate: float = 0.0,
      input_layer: str = "embed",
      use_output_layer: bool = True,
      pos_enc_class=PositionalEncoding,
      normalize_before: bool = True,
      concat_after: bool = False,
      layer_drop_rate: float = 0.0,
      # extra embedding related
      spks: Optional[int] = None,
      langs: Optional[int] = None,
      spk_embed_dim: Optional[int] = None,
      spk_embed_integration_type: str = "concat",
  ):
      """Transfomer decoder for discrete unit module.
  
      Args:
          vocab_size: output dim
          encoder_output_size: dimension of attention
          attention_heads: the number of heads of multi head attention
          linear_units: the number of units of position-wise feed forward
          num_blocks: the number of decoder blocks
          dropout_rate: dropout rate
          self_attention_dropout_rate: dropout rate for attention
          input_layer: input layer type
          use_output_layer: whether to use output layer
          pos_enc_class: PositionalEncoding or ScaledPositionalEncoding
          normalize_before: whether to use layer_norm before the first block
          concat_after: whether to concat attention layer's input and output
              if True, additional linear will be applied.
              i.e. x -> x + linear(concat(x, att(x)))
              if False, no additional linear will be applied.
              i.e. x -> x + att(x)
          spks (Optional[int]): Number of speakers. If set to > 1, assume that the
              sids will be provided as the input and use sid embedding layer.
          langs (Optional[int]): Number of languages. If set to > 1, assume that the
              lids will be provided as the input and use sid embedding layer.
          spk_embed_dim (Optional[int]): Speaker embedding dimension. If set to > 0,
              assume that spembs will be provided as the input.
          spk_embed_integration_type (str): How to integrate speaker embedding.
      """
      assert check_argument_types()
      super().__init__()
  
      self.spks = None
      if spks is not None and spks > 1:
          self.spks = spks
          self.sid_emb = torch.nn.Embedding(spks, encoder_output_size)
      self.langs = None
      if langs is not None and langs > 1:
          self.langs = langs
          self.lid_emb = torch.nn.Embedding(langs, encoder_output_size)
  
      self.spk_embed_dim = None
      if spk_embed_dim is not None and spk_embed_dim > 0:
          self.spk_embed_dim = spk_embed_dim
          self.spk_embed_integration_type = spk_embed_integration_type
      if self.spk_embed_dim is None:
          dec_idim = idim
      elif self.spk_embed_integration_type == "concat":
          dec_idim = idim + spk_embed_dim
      elif self.spk_embed_integration_type == "add":
          dec_idim = idim
          self.projection = torch.nn.Linear(
              self.spk_embed_dim, encoder_output_size
          )
      else:
          raise ValueError(
              f"{spk_embed_integration_type} is not supported."
          )
  
      self.decoder = TransformerDecoder(
          vocab_size=odim,
          encoder_output_size=dec_idim,
          attention_heads=attention_heads,
          linear_units=linear_units,
          num_blocks=num_blocks,
          dropout_rate=dropout_rate,
          positional_dropout_rate=positional_dropout_rate,
          self_attention_dropout_rate=self_attention_dropout_rate,
          src_attention_dropout_rate=src_attention_dropout_rate,
          input_layer=input_layer,
          use_output_layer=use_output_layer,
          pos_enc_class=pos_enc_class,
          normalize_before=normalize_before,
          concat_after=concat_after,
          layer_drop_rate=layer_drop_rate,
      )
  
imports: import logging
  from typing import Any, Dict, List, Optional, Sequence, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.asr.decoder.transformer_decoder import TransformerDecoder
  from espnet2.s2st.synthesizer.abs_synthesizer import AbsSynthesizer
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask
  from espnet.nets.scorer_interface import BatchScorerInterface
label_desc: Use image node_id 1 to create a new TransformerDiscreteSynthesizer object from inherited base classes: AbsSynthesizer, BatchScorerInterface with example: obj = TransformerDiscreteSynthesizer(odim, idim, attention_heads, linear_units, num_blocks, dropout_rate, positional_dropout_rate, _attention_dropout_rate, src_attention_dropout_rate, input_layer, use_output_layer, pos_enc_class, normalize_before, concat_after, layer_drop_rate, spks, langs, spk_embed_dim, spk_embed_integration_type)