code: def test_sortagrad_trainable_with_batch_bins(module):
      args = make_arg(sortagrad=1)
      idim = 10
      odim = 5
      dummy_json = make_dummy_json(
          2, [3, 5], [3, 5], idim=idim, odim=odim
      )
      if module == "pytorch":
          import espnet.nets.pytorch_backend.e2e_asr as m
      else:
          import espnet.nets.chainer_backend.e2e_asr as m
      batch_elems = 2000
      batchset = make_batchset(
          dummy_json, batch_bins=batch_elems, shortest_first=True
      )
      for batch in batchset:
          n = 0
          for uttid, info in batch:
              ilen = int(info["input"][0]["shape"][0])
              olen = int(info["output"][0]["shape"][0])
              n += ilen * idim + olen * odim
          assert olen < batch_elems
  
      model = m.E2E(idim, odim, args)
      for batch in batchset:
          loss = model(
              *convert_batch(batch, module, idim=idim, odim=odim)
          )
          if isinstance(loss, tuple):
              # chainer return several values as tuple
              loss[0].backward()  # trainable
          else:
              loss.backward()  # trainable
      with torch.no_grad(), chainer.no_backprop_mode():
          in_data = np.random.randn(10, idim)
          model.recognize(in_data, args, args.char_list)
  
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 9 for calling a global function with example usage: test_sortagrad_trainable_with_batch_bins(module) without return types