code: def pad_sequence(sequences, len_list, pad_to=None, padding_value=0):
      """pad sequences to a matrix
  
      Args:
          sequences (list): list of variable length sequences.
          len_list (list): the length of the tensors in the sequences
          pad_to (int, optional): if pad_to is not None, the sequences will pad to the length you set,
                                  else the sequence will pad to the max length of the sequences.
          padding_value (int, optional): value for padded elements. Default: 0.
  
      Returns:
          torch.Tensor: [seq_num, max_len] or [seq_num, pad_to]
  
      """
      max_len = np.max(len_list) if pad_to is None else pad_to
      min_len = np.min(len_list)
      device = sequences[0].device
      if max_len == min_len:
          result = torch.cat(sequences, dim=0).view(-1, max_len)
      else:
          extra_len_list = np.subtract(max_len, len_list).tolist()
          padding_nums = max_len * len(len_list) - np.sum(len_list)
          padding_tensor = torch.tensor(
              [-np.inf], device=device
          ).repeat(padding_nums)
          padding_list = torch.split(padding_tensor, extra_len_list)
          result = list(
              itertools.chain.from_iterable(
                  zip(sequences, padding_list)
              )
          )
          result = torch.cat(result)
  
      return result.view(-1, max_len)
  
imports: import itertools
  import numpy
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: pad_sequence(sequences, len_list, pad_to, padding_value) and returns: result