code: def test_beam_search_timesync(
      model_class,
      args,
      mtlalpha,
      ctc_weight,
      lm_weight,
      bonus,
      device,
      dtype,
  ):
      if device == "cuda" and not torch.cuda.is_available():
          pytest.skip("no cuda device is available")
      if device == "cpu" and dtype == "float16":
          pytest.skip(
              "cpu float16 implementation is not available in pytorch yet"
          )
      if mtlalpha == 0.0 or ctc_weight == 0:
          pytest.skip("no CTC.")
      if mtlalpha == 1.0 and ctc_weight < 1.0:
          pytest.skip("pure CTC + attention decoding")
  
      # seed setting
      torch.manual_seed(123)
      torch.backends.cudnn.deterministic = True
      torch.backends.cudnn.benchmark = (
          False  # https://github.com/pytorch/pytorch/issues/6351
      )
  
      dtype = getattr(torch, dtype)
      model, x, ilens, y, data, train_args = prepare(
          model_class, args, mtlalpha=mtlalpha
      )
      model.eval()
      char_list = train_args.char_list
      lm_args = Namespace(
          type="lstm", layer=1, unit=2, embed_unit=2, dropout_rate=0.0
      )
      lm = dynamic_import_lm("default", backend="pytorch")(
          len(char_list), lm_args
      )
      lm.eval()
  
      # test previous beam search
      args = Namespace(
          beam_size=3,
          penalty=bonus,
          ctc_weight=ctc_weight,
          maxlenratio=0,
          lm_weight=lm_weight,
          minlenratio=0,
          nbest=3,
      )
  
      feat = x[0, : ilens[0]].numpy()
  
      # new beam search
      scorers = model.scorers()
      scorers["ctc"] = model.ctc
      if lm_weight != 0:
          scorers["lm"] = lm
      scorers["length_bonus"] = LengthBonus(len(char_list))
      weights = dict(
          decoder=1.0 - ctc_weight,
          ctc=ctc_weight,
          lm=args.lm_weight,
          length_bonus=args.penalty,
      )
      model.to(device, dtype=dtype)
      model.eval()
      beam = BeamSearchTimeSync(
          beam_size=args.beam_size,
          weights=weights,
          scorers=scorers,
          sos=model.sos,
          token_list=train_args.char_list,
      )
      beam.to(device, dtype=dtype)
      beam.eval()
      with torch.no_grad():
          enc = model.encode(
              torch.as_tensor(feat).to(device, dtype=dtype)
          )
          beam(
              x=enc,
              maxlenratio=args.maxlenratio,
              minlenratio=args.minlenratio,
          )
  
      # just checking it is decodable
      return
  
file_path: espnet/test/test_beam_search_timesync.py
imports: from argparse import Namespace
  import pytest
  import torch
  from espnet.nets.asr_interface import dynamic_import_asr
  from espnet.nets.beam_search_timesync import BeamSearchTimeSync
  from espnet.nets.lm_interface import dynamic_import_lm
  from espnet.nets.scorers.length_bonus import LengthBonus
label_desc: Use image node_id 2 for calling a global function with example usage: test_beam_search_timesync(model_class, args, mtlalpha, ctc_weight, lm_weight, bonus, device, dtype) without return types