class_docstr: Dataset for Causal Language modeling.
code: def pad_tokens(
      input_ids,
      attention_mask,
      max_length,
      pad_token_id,
      direction="left",
      prefix="",
  ):
      sample = {}
  
      if max_length < len(input_ids):
          input_ids = input_ids[-max_length:]
          attention_mask = attention_mask[-max_length:]
  
      if len(input_ids) > 0:
          if direction == "left":
              sample[f"{prefix}input_ids"] = torch.full(
                  (max_length,), pad_token_id
              )
              sample[f"{prefix}input_ids"][
                  -len(input_ids) :
              ] = input_ids
              sample[f"{prefix}attention_mask"] = torch.zeros(
                  max_length
              )
              sample[f"{prefix}attention_mask"][
                  -len(input_ids) :
              ] = attention_mask
          else:
              sample[f"{prefix}input_ids"] = torch.full(
                  (max_length,), pad_token_id
              )
              sample[f"{prefix}input_ids"][: len(input_ids)] = input_ids
              sample[f"{prefix}attention_mask"] = torch.zeros(
                  max_length
              )
              sample[f"{prefix}attention_mask"][
                  : len(input_ids)
              ] = attention_mask
      else:
          # Pad everything if empty (continued pretraining)
          sample[f"{prefix}input_ids"] = torch.full(
              (max_length,), pad_token_id
          )
          sample[f"{prefix}attention_mask"] = torch.zeros(max_length)
  
      return sample
  
imports: import codecs
  import collections.abc
  import logging
  from typing import Any, Dict, List, Tuple, Union
  import numpy
  import pandas
  import torch
  from torch.utils.data import Dataset
  from llm_studio.src.datasets.conversation_chain_handler import ConversationChainHandler
  from llm_studio.src.datasets.text_utils import get_tokenizer
label_desc: Use image node_id 19 for calling the CustomDataset obj's underlying member method code with example usage: obj.pad_tokens(input_ids, attention_mask, max_length, pad_token_id, direction, prefix) and returns: sample