code: def _pad_sequence(
      tensors: List[torch.Tensor],
      padding_value: int,
      padding_side: str = "right",
  ):
      """
      Pad encoded inputs (on left/right and up to max length in the batch)
      """
      max_len = max(tensor.size(0) for tensor in tensors)
      padded_tensors = []
      if padding_side == "right":
          return pad_sequence(
              tensors, batch_first=True, padding_value=padding_value
          )
      elif padding_side == "left":
          for tensor in tensors:
              padding_length = max_len - len(tensor)
              padded_tensor = torch.cat(
                  [
                      torch.full(
                          [padding_length],
                          padding_value,
                          dtype=tensor.dtype,
                      ),
                      tensor,
                  ],
                  dim=-1,
              )
              padded_tensors.append(padded_tensor)
      padded_tensors = torch.stack(padded_tensors, dim=0)
      return padded_tensors
  
imports: from typing import List, Optional
  import itertools, os
  import torch
  from torch.nn.utils.rnn import pad_sequence
label_desc: Use image node_id 2 for calling a global function with example usage: _pad_sequence(tensors, padding_value, padding_side) and returns: padded_tensors, pad_sequence