MCPcopy Create free account
hub / github.com/FunAudioLLM/FunMusic / BiTransformerDecoder

Class BiTransformerDecoder

inspiremusic/transformer/decoder.py:256–396  ·  view source on GitHub ↗

Base class of Transfomer decoder 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 hidden units number of position-wise feedforward num_blocks: th

Source from the content-addressed store, hash-verified

254
255
256class BiTransformerDecoder(torch.nn.Module):
257 """Base class of Transfomer decoder module.
258 Args:
259 vocab_size: output dim
260 encoder_output_size: dimension of attention
261 attention_heads: the number of heads of multi head attention
262 linear_units: the hidden units number of position-wise feedforward
263 num_blocks: the number of decoder blocks
264 r_num_blocks: the number of right to left decoder blocks
265 dropout_rate: dropout rate
266 self_attention_dropout_rate: dropout rate for attention
267 input_layer: input layer type
268 use_output_layer: whether to use output layer
269 pos_enc_class: PositionalEncoding or ScaledPositionalEncoding
270 normalize_before:
271 True: use layer_norm before each sub-block of a layer.
272 False: use layer_norm after each sub-block of a layer.
273 key_bias: whether use bias in attention.linear_k, False for whisper models.
274 """
275
276 def __init__(
277 self,
278 vocab_size: int,
279 encoder_output_size: int,
280 attention_heads: int = 4,
281 linear_units: int = 2048,
282 num_blocks: int = 6,
283 r_num_blocks: int = 0,
284 dropout_rate: float = 0.1,
285 positional_dropout_rate: float = 0.1,
286 self_attention_dropout_rate: float = 0.0,
287 src_attention_dropout_rate: float = 0.0,
288 input_layer: str = "embed",
289 use_output_layer: bool = True,
290 normalize_before: bool = True,
291 key_bias: bool = True,
292 gradient_checkpointing: bool = False,
293 tie_word_embedding: bool = False,
294 ):
295
296 super().__init__()
297 self.tie_word_embedding = tie_word_embedding
298 self.left_decoder = TransformerDecoder(
299 vocab_size,
300 encoder_output_size,
301 attention_heads,
302 linear_units,
303 num_blocks,
304 dropout_rate,
305 positional_dropout_rate,
306 self_attention_dropout_rate,
307 src_attention_dropout_rate,
308 input_layer,
309 use_output_layer,
310 normalize_before,
311 key_bias=key_bias,
312 gradient_checkpointing=gradient_checkpointing,
313 tie_word_embedding=tie_word_embedding)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected