code: def collate_2d(
      values, pad_idx=0, left_pad=False, shift_right=False, max_len=None
  ):
      """Convert a list of 2d tensors into a padded 3d tensor."""
      size = (
          max(v.size(0) for v in values) if max_len is None else max_len
      )
      res = (
          values[0]
          .new(len(values), size, values[0].shape[1])
          .fill_(pad_idx)
      )
  
      def copy_tensor(src, dst):
          assert dst.numel() == src.numel()
          if shift_right:
              dst[1:] = src[:-1]
          else:
              dst.copy_(src)
  
      for i, v in enumerate(values):
          copy_tensor(
              v,
              res[i][size - len(v) :] if left_pad else res[i][: len(v)],
          )
      return res
  
file_path: PaddleHub/modules/audio/svs/diffsinger/utils/__init__.py
imports: import sys
  import time
  import types
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: collate_2d(values, pad_idx, left_pad, shift_right, max_len) and returns: res