code: def __init__(
      self,
      data_file: str,
      tokenizer: AutoTokenizer,
      max_length=512,
      is_group_texts=True,
  ) -> None:
      super().__init__()
      # read the data_file line by line
      with open(data_file, "r", encoding="UTF-8") as f:
          # encode the text data line by line and put raw python list input_ids only to raw_input_ids list
          raw_input_ids = []
          for line in f:
              encoded_ids = tokenizer.encode(line)
              # if the encoded_ids is longer than max_length, then split it into several parts
              if len(encoded_ids) > max_length:
                  for i in range(0, len(encoded_ids), max_length):
                      raw_input_ids.append(
                          encoded_ids[i : i + max_length]
                      )
              else:
                  raw_input_ids.append(encoded_ids)
  
      grouped_input_ids = []
      current_input_ids = []
      attention_mask = []
      if tokenizer.pad_token_id is None:
          tokenizer.pad_token_id = tokenizer.eos_token_id
      if is_group_texts:
          for input_ids in raw_input_ids:
              if len(current_input_ids) + len(input_ids) > max_length:
                  # pad the current_input_ids to max_length with tokenizer.pad_token_id
                  padded_length = max_length - len(current_input_ids)
                  current_input_ids.extend(
                      [tokenizer.pad_token_id] * padded_length
                  )
                  grouped_input_ids.append(
                      torch.tensor(current_input_ids, dtype=torch.long)
                  )
                  attention_mask.append(
                      torch.tensor(
                          [1] * (max_length - padded_length)
                          + [0] * padded_length,
                          dtype=torch.long,
                      )
                  )
                  current_input_ids = []
              else:
                  current_input_ids.extend(input_ids)
          if len(current_input_ids) > 0:
              padded_length = max_length - len(current_input_ids)
              current_input_ids.extend(
                  [tokenizer.pad_token_id] * padded_length
              )
              grouped_input_ids.append(
                  torch.tensor(current_input_ids, dtype=torch.long)
              )
              attention_mask.append(
                  torch.tensor(
                      [1] * (max_length - padded_length)
                      + [0] * padded_length,
                      dtype=torch.long,
                  )
              )
      else:
          # just append the raw_input_ids to max_length
          for input_ids in raw_input_ids:
              padded_length = max_length - len(input_ids)
              input_ids.extend([tokenizer.pad_token_id] * padded_length)
              attention_mask.append(
                  torch.tensor(
                      [1] * (max_length - padded_length)
                      + [0] * padded_length,
                      dtype=torch.long,
                  )
              )
              grouped_input_ids.append(
                  torch.tensor(input_ids, dtype=torch.long)
              )
      self.input_ids = grouped_input_ids
      self.labels = copy.deepcopy(self.input_ids)
      self.file_name = data_file
      self.attention_mask = attention_mask
  
imports: import copy
  import json
  from typing import Dict, Sequence
  import torch
  from torch.utils.data import Dataset
  from tqdm import tqdm
  from transformers import AutoTokenizer
label_desc: Use image node_id 1 to create a new EasySFTDataset object from inherited base classes: Dataset with example: obj = EasySFTDataset(data_file, tokenizer, max_length, is_group_texts)