code: def build_blocks(
      net_part: str,
      idim: int,
      input_layer_type: str,
      blocks: List[Dict[str, Any]],
      repeat_block: int = 0,
      self_attn_type: str = "self_attn",
      positional_encoding_type: str = "abs_pos",
      positionwise_layer_type: str = "linear",
      positionwise_activation_type: str = "relu",
      conv_mod_activation_type: str = "relu",
      input_layer_dropout_rate: float = 0.0,
      input_layer_pos_enc_dropout_rate: float = 0.0,
      padding_idx: int = -1,
  ) -> Tuple[
      Union[Conv2dSubsampling, VGG2L, torch.nn.Sequential],
      MultiSequential,
      int,
      int,
  ]:
      """Build custom model blocks.
  
      Args:
          net_part: Network part, either 'encoder' or 'decoder'.
          idim: Input dimension.
          input_layer: Input layer type.
          blocks: Blocks parameters for network part.
          repeat_block: Number of times provided blocks are repeated.
          positional_encoding_type: Positional encoding layer type.
          positionwise_layer_type: Positionwise layer type.
          positionwise_activation_type: Positionwise activation type.
          conv_mod_activation_type: Convolutional module activation type.
          input_layer_dropout_rate: Dropout rate for input layer.
          input_layer_pos_enc_dropout_rate: Dropout rate for input layer pos. enc.
          padding_idx: Padding symbol ID for embedding layer.
  
      Returns:
          in_layer: Input layer
          all_blocks: Encoder/Decoder network.
          out_dim: Network output dimension.
          conv_subsampling_factor: Subsampling factor in frontend CNN.
  
      """
      fn_modules = []
  
      pos_enc_class, self_attn_class = get_pos_enc_and_att_class(
          net_part, positional_encoding_type, self_attn_type
      )
  
      input_block = prepare_input_layer(
          input_layer_type,
          idim,
          blocks,
          input_layer_dropout_rate,
          input_layer_pos_enc_dropout_rate,
      )
  
      out_dim = prepare_body_model(net_part, blocks)
  
      input_layer, conv_subsampling_factor = build_input_layer(
          input_block,
          pos_enc_class,
          padding_idx,
      )
  
      for i in range(len(blocks)):
          block_type = blocks[i]["type"]
  
          if block_type in ("causal-conv1d", "conv1d"):
              module = build_conv1d_block(blocks[i], block_type)
          elif block_type == "conformer":
              module = build_conformer_block(
                  blocks[i],
                  self_attn_class,
                  positionwise_layer_type,
                  positionwise_activation_type,
                  conv_mod_activation_type,
              )
          elif block_type == "transformer":
              module = build_transformer_block(
                  net_part,
                  blocks[i],
                  positionwise_layer_type,
                  positionwise_activation_type,
              )
  
          fn_modules.append(module)
  
      if repeat_block > 1:
          fn_modules = fn_modules * repeat_block
  
      return (
          input_layer,
          MultiSequential(*[fn() for fn in fn_modules]),
          out_dim,
          conv_subsampling_factor,
      )
  
imports: from typing import Any, Dict, List, Tuple, Union
  import torch
  from espnet.nets.pytorch_backend.conformer.convolution import ConvolutionModule
  from espnet.nets.pytorch_backend.conformer.encoder_layer import EncoderLayer
  from espnet.nets.pytorch_backend.nets_utils import get_activation
  from espnet.nets.pytorch_backend.transducer.conv1d_nets import CausalConv1d, Conv1d
  from espnet.nets.pytorch_backend.transducer.transformer_decoder_layer import TransformerDecoderLayer
  from espnet.nets.pytorch_backend.transducer.vgg2l import VGG2L
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention, RelPositionMultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding, RelPositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder_layer import EncoderLayer
  from espnet.nets.pytorch_backend.transformer.positionwise_feed_forward import PositionwiseFeedForward
  from espnet.nets.pytorch_backend.transformer.repeat import MultiSequential
  from espnet.nets.pytorch_backend.transformer.subsampling import Conv2dSubsampling
label_desc: Use image node_id 9 for calling a global function with example usage: build_blocks(net_part, idim, input_layer_type, blocks, repeat_block, _attn_type, positional_encoding_type, positionwise_layer_type, positionwise_activation_type, conv_mod_activation_type, input_layer_dropout_rate, input_layer_pos_enc_dropout_rate, padding_idx) and returns: input_layer,  MultiSequential,  out_dim,  conv_subsampling_factor