code: def test_joint_model_is_trainable_and_decodable(
      t2m_dict, voc_dict, dis_dict, loss_dict
  ):
      idim = 10
      odim = 5
      t2m_args = make_text2mel_args(**t2m_dict)
      voc_args = make_vocoder_args(**voc_dict)
      dis_args = make_discriminator_args(**dis_dict)
      loss_args = make_loss_args(**loss_dict)
      model = JointText2Wav(
          idim=idim,
          odim=odim,
          segment_size=4,
          **t2m_args,
          **voc_args,
          **dis_args,
          **loss_args,
      )
      model.train()
      upsample_factor = model.generator["vocoder"].upsample_factor
      inputs = dict(
          text=torch.randint(0, idim, (2, 8)),
          text_lengths=torch.tensor([8, 5], dtype=torch.long),
          feats=torch.randn(2, 16, odim),
          feats_lengths=torch.tensor([16, 13], dtype=torch.long),
          speech=torch.randn(2, 16 * upsample_factor),
          speech_lengths=torch.tensor(
              [16, 13] * upsample_factor, dtype=torch.long
          ),
      )
      if t2m_args["text2mel_type"] in ["fastspeech", "fastspeech2"]:
          inputs.update(
              durations=torch.tensor(
                  [
                      # +1 element for <eos>
                      [2, 2, 2, 2, 2, 2, 2, 2, 0],
                      [3, 3, 3, 3, 1, 0, 0, 0, 0],
                  ],
                  dtype=torch.long,
              ),
              # +1 element for <eos>
              durations_lengths=torch.tensor(
                  [8 + 1, 5 + 1], dtype=torch.long
              ),
          )
      if t2m_args["text2mel_type"] in ["fastspeech2"]:
          inputs.update(
              pitch=torch.randn(2, 9, 1),
              pitch_lengths=torch.tensor([9, 7], dtype=torch.long),
              energy=torch.randn(2, 9, 1),
              energy_lengths=torch.tensor([9, 7], dtype=torch.long),
          )
      gen_loss = model(forward_generator=True, **inputs)["loss"]
      gen_loss.backward()
      dis_loss = model(forward_generator=False, **inputs)["loss"]
      dis_loss.backward()
  
      with torch.no_grad():
          model.eval()
  
          # check inference
          inputs = dict(
              text=torch.randint(
                  0,
                  idim,
                  (10,),
              )
          )
          output_dict = model.inference(**inputs)
          assert (
              len(output_dict["wav"])
              == len(output_dict["feat_gen"]) * upsample_factor
          )
  
file_path: espnet/test/espnet2/gan_tts/joint/test_joint_text2wav.py
imports: import pytest
  import torch
  from packaging.version import parse
  from espnet2.gan_tts.joint import JointText2Wav
label_desc: Use image node_id 5 for calling a global function with example usage: test_joint_model_is_trainable_and_decodable(t2m_dict, voc_dict, dis_dict, loss_dict) without return types