code: def test_encoder(input_conf, body_conf, main_conf):
      input_size = 8
  
      encoder = Encoder(
          input_size,
          body_conf,
          input_conf=input_conf,
          main_conf=main_conf,
      )
  
      sequence = torch.randn(2, 30, input_size, requires_grad=True)
      sequence_len = torch.tensor([30, 18], dtype=torch.long)
  
      _ = encoder(sequence, sequence_len)
  
      # Note (b-flo): For each test with Conformer blocks, we do the same testing with
      # Branchformer and E-Branchformer blocks instead.
      # The tests will be redesigned, for now we avoid writing too many configs.
      _swap = False
  
      branchformer_conf = body_conf[:]
      ebranchformer_conf = body_conf[:]
  
      for i, b in enumerate(body_conf):
          if b["block_type"] == "conformer":
              branchformer_conf[i]["block_type"] = "branchformer"
              ebranchformer_conf[i]["block_type"] = "ebranchformer"
  
              if _swap is False:
                  _swap = True
  
      if _swap:
          branchformer_encoder = Encoder(
              input_size,
              branchformer_conf,
              input_conf=input_conf,
              main_conf=main_conf,
          )
          _ = branchformer_encoder(sequence, sequence_len)
  
          ebranchformer_encoder = Encoder(
              input_size,
              ebranchformer_conf,
              input_conf=input_conf,
              main_conf=main_conf,
          )
          _ = ebranchformer_encoder(sequence, sequence_len)
  
file_path: espnet/test/espnet2/asr_transducer/test_encoder.py
imports: import pytest
  import torch
  from espnet2.asr_transducer.encoder.encoder import Encoder
  from espnet2.asr_transducer.utils import TooShortUttError
label_desc: Use image node_id 1 for calling a global function with example usage: test_encoder(input_conf, body_conf, main_conf) without return types