code: def test_mtl_loss(etype):
      args = make_arg(etype=etype)
      ch_model = ch_asr.E2E(10, 5, args)
      th_model = th_asr.E2E(10, 5, args)
  
      const = 1e-4
      init_torch_weight_const(th_model, const)
      init_chainer_weight_const(ch_model, const)
  
      ch_batch = prepare_inputs("chainer")
      th_batch = prepare_inputs("pytorch")
  
      _, ch_ctc, ch_att, ch_acc = ch_model(*ch_batch)
      th_model(*th_batch)
      th_ctc, th_att = th_model.loss_ctc, th_model.loss_att
  
      # test masking
      ch_ench = ch_model.att.pre_compute_enc_h.data
      th_ench = th_model.att[0].pre_compute_enc_h.detach().numpy()
      np.testing.assert_equal(ch_ench == 0.0, th_ench == 0.0)
  
      # test loss with constant weights (1.0) and bias (0.0) except for foget-bias (1.0)
      np.testing.assert_allclose(ch_ctc.data, th_ctc.detach().numpy())
      np.testing.assert_allclose(ch_att.data, th_att.detach().numpy())
  
      # test grads in mtl mode
      ch_loss = ch_ctc * 0.5 + ch_att * 0.5
      th_loss = th_ctc * 0.5 + th_att * 0.5
      ch_model.cleargrads()
      th_model.zero_grad()
      ch_loss.backward()
      th_loss.backward()
      np.testing.assert_allclose(
          ch_model.ctc.ctc_lo.W.grad,
          th_model.ctc.ctc_lo.weight.grad.data.numpy(),
          1e-7,
          1e-8,
      )
      np.testing.assert_allclose(
          ch_model.ctc.ctc_lo.b.grad,
          th_model.ctc.ctc_lo.bias.grad.data.numpy(),
          1e-5,
          1e-6,
      )
      np.testing.assert_allclose(
          ch_model.dec.output.W.grad,
          th_model.dec.output.weight.grad.data.numpy(),
          1e-7,
          1e-8,
      )
      np.testing.assert_allclose(
          ch_model.dec.output.b.grad,
          th_model.dec.output.bias.grad.data.numpy(),
          1e-5,
          1e-6,
      )
  
imports: from __future__ import division
  import argparse
  import importlib
  import os
  import tempfile
  from test.utils_test import make_dummy_json
  import chainer
  import numpy
  import pytest
  import torch
  import espnet.nets.chainer_backend.e2e_asr
  import espnet.nets.pytorch_backend.e2e_asr
  from espnet.asr import asr_utils
  from espnet.nets.pytorch_backend.nets_utils import pad_list
  from espnet.nets.pytorch_backend.streaming.segment import SegmentStreamingE2E
  from espnet.nets.pytorch_backend.streaming.window import WindowStreamingE2E
  from espnet.utils.training.batchfy import make_batchset
label_desc: Use image node_id 14 for calling a global function with example usage: test_mtl_loss(etype) without return types