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

Method __init__

inspiremusic/transformer/encoder.py:344–387  ·  view source on GitHub ↗

Construct TransformerEncoder See Encoder for the meaning of each parameter.

(
        self,
        input_size: int,
        output_size: int = 256,
        attention_heads: int = 4,
        linear_units: int = 2048,
        num_blocks: int = 6,
        dropout_rate: float = 0.1,
        positional_dropout_rate: float = 0.1,
        attention_dropout_rate: float = 0.0,
        input_layer: str = "conv2d",
        pos_enc_layer_type: str = "abs_pos",
        normalize_before: bool = True,
        static_chunk_size: int = 0,
        use_dynamic_chunk: bool = False,
        global_cmvn: torch.nn.Module = None,
        use_dynamic_left_chunk: bool = False,
        key_bias: bool = True,
        selfattention_layer_type: str = "selfattn",
        activation_type: str = "relu",
        gradient_checkpointing: bool = False,
    )

Source from the content-addressed store, hash-verified

342 """Transformer encoder module."""
343
344 def __init__(
345 self,
346 input_size: int,
347 output_size: int = 256,
348 attention_heads: int = 4,
349 linear_units: int = 2048,
350 num_blocks: int = 6,
351 dropout_rate: float = 0.1,
352 positional_dropout_rate: float = 0.1,
353 attention_dropout_rate: float = 0.0,
354 input_layer: str = "conv2d",
355 pos_enc_layer_type: str = "abs_pos",
356 normalize_before: bool = True,
357 static_chunk_size: int = 0,
358 use_dynamic_chunk: bool = False,
359 global_cmvn: torch.nn.Module = None,
360 use_dynamic_left_chunk: bool = False,
361 key_bias: bool = True,
362 selfattention_layer_type: str = "selfattn",
363 activation_type: str = "relu",
364 gradient_checkpointing: bool = False,
365 ):
366 """ Construct TransformerEncoder
367
368 See Encoder for the meaning of each parameter.
369 """
370 super().__init__(input_size, output_size, attention_heads,
371 linear_units, num_blocks, dropout_rate,
372 positional_dropout_rate, attention_dropout_rate,
373 input_layer, pos_enc_layer_type, normalize_before,
374 static_chunk_size, use_dynamic_chunk, global_cmvn,
375 use_dynamic_left_chunk, gradient_checkpointing)
376 activation = INSPIREMUSIC_ACTIVATION_CLASSES[activation_type]()
377 self.encoders = torch.nn.ModuleList([
378 TransformerEncoderLayer(
379 output_size,
380 INSPIREMUSIC_ATTENTION_CLASSES[selfattention_layer_type](attention_heads,
381 output_size,
382 attention_dropout_rate,
383 key_bias),
384 PositionwiseFeedForward(output_size, linear_units,
385 dropout_rate, activation),
386 dropout_rate, normalize_before) for _ in range(num_blocks)
387 ])
388
389
390class ConformerEncoder(BaseEncoder):

Callers

nothing calls this directly

Calls 3

__init__Method · 0.45

Tested by

no test coverage detected