| 35 | |
| 36 | |
| 37 | class BaseEncoder(torch.nn.Module): |
| 38 | |
| 39 | def __init__( |
| 40 | self, |
| 41 | input_size: int, |
| 42 | output_size: int = 256, |
| 43 | attention_heads: int = 4, |
| 44 | linear_units: int = 2048, |
| 45 | num_blocks: int = 6, |
| 46 | dropout_rate: float = 0.1, |
| 47 | positional_dropout_rate: float = 0.1, |
| 48 | attention_dropout_rate: float = 0.0, |
| 49 | input_layer: str = "conv2d", |
| 50 | pos_enc_layer_type: str = "abs_pos", |
| 51 | normalize_before: bool = True, |
| 52 | static_chunk_size: int = 0, |
| 53 | use_dynamic_chunk: bool = False, |
| 54 | global_cmvn: torch.nn.Module = None, |
| 55 | use_dynamic_left_chunk: bool = False, |
| 56 | gradient_checkpointing: bool = False, |
| 57 | ): |
| 58 | """ |
| 59 | Args: |
| 60 | input_size (int): input dim |
| 61 | output_size (int): dimension of attention |
| 62 | attention_heads (int): the number of heads of multi head attention |
| 63 | linear_units (int): the hidden units number of position-wise feed |
| 64 | forward |
| 65 | num_blocks (int): the number of decoder blocks |
| 66 | dropout_rate (float): dropout rate |
| 67 | attention_dropout_rate (float): dropout rate in attention |
| 68 | positional_dropout_rate (float): dropout rate after adding |
| 69 | positional encoding |
| 70 | input_layer (str): input layer type. |
| 71 | optional [linear, conv2d, conv2d6, conv2d8] |
| 72 | pos_enc_layer_type (str): Encoder positional encoding layer type. |
| 73 | opitonal [abs_pos, scaled_abs_pos, rel_pos, no_pos] |
| 74 | normalize_before (bool): |
| 75 | True: use layer_norm before each sub-block of a layer. |
| 76 | False: use layer_norm after each sub-block of a layer. |
| 77 | static_chunk_size (int): chunk size for static chunk training and |
| 78 | decoding |
| 79 | use_dynamic_chunk (bool): whether use dynamic chunk size for |
| 80 | training or not, You can only use fixed chunk(chunk_size > 0) |
| 81 | or dyanmic chunk size(use_dynamic_chunk = True) |
| 82 | global_cmvn (Optional[torch.nn.Module]): Optional GlobalCMVN module |
| 83 | use_dynamic_left_chunk (bool): whether use dynamic left chunk in |
| 84 | dynamic chunk training |
| 85 | key_bias: whether use bias in attention.linear_k, False for whisper models. |
| 86 | gradient_checkpointing: rerunning a forward-pass segment for each |
| 87 | checkpointed segment during backward. |
| 88 | """ |
| 89 | super().__init__() |
| 90 | self._output_size = output_size |
| 91 | |
| 92 | self.global_cmvn = global_cmvn |
| 93 | self.embed = INSPIREMUSIC_SUBSAMPLE_CLASSES[input_layer]( |
| 94 | input_size, |
nothing calls this directly
no outgoing calls
no test coverage detected