class_docstr: Dataset for supervised fine-tuning.
code: def __getitem__(self, i) -> Dict[str, torch.Tensor]:
      sources = self.list_data_dict[i]
      processor = self.processor
      if isinstance(i, int):
          sources = [sources]
      assert (
          len(sources) == 1
      ), "Don't know why it is wrapped to a list"  # FIXME
      if "image" in sources[0]:
          if not isinstance(self.list_data_dict[i]["image"], list):
              self.list_data_dict[i]["image"] = [
                  self.list_data_dict[i]["image"]
              ]
  
          images = []
          for image_file in self.list_data_dict[i]["image"]:
              image = self.image_loader.open_image(image_file)
              if image is None:
                  logging.warning(
                      f"Image {image_file} could not be found!"
                  )
              if self.multimodal_cfg["image_aspect_ratio"] == "keep":
                  max_hw, min_hw = max(image.size), min(image.size)
                  aspect_ratio = max_hw / min_hw
                  max_len, min_len = 448, 224
                  shortest_edge = int(
                      min(max_len / aspect_ratio, min_len)
                  )
                  image = processor.preprocess(
                      image,
                      return_tensors="pt",
                      do_center_crop=False,
                      size={"shortest_edge": shortest_edge},
                  )["pixel_values"][0]
              elif self.multimodal_cfg["image_aspect_ratio"] == "pad":
  
                  def expand2square(pil_img, background_color):
                      width, height = pil_img.size
                      if width == height:
                          return pil_img
                      elif width > height:
                          result = Image.new(
                              pil_img.mode,
                              (width, width),
                              background_color,
                          )
                          result.paste(
                              pil_img, (0, (width - height) // 2)
                          )
                          return result
                      else:
                          result = Image.new(
                              pil_img.mode,
                              (height, height),
                              background_color,
                          )
                          result.paste(
                              pil_img, ((height - width) // 2, 0)
                          )
                          return result
  
                  image = expand2square(
                      image,
                      tuple(int(x * 255) for x in processor.image_mean),
                  )
                  image = processor.preprocess(
                      image, return_tensors="pt"
                  )["pixel_values"][0]
              else:
                  image = processor.preprocess(
                      image, return_tensors="pt"
                  )["pixel_values"][0]
              images.append(image)
          images_tensors = torch.tensor([])
          if images:
              images_tensors = torch.stack(images)
              cur_token_len = (images_tensors[0].shape[1] // 14) * (
                  images_tensors[0].shape[2] // 14
              )  # FIXME: 14 is hardcoded patch size
              sources = preprocess_multimodal(
                  copy.deepcopy(sources),
                  self.multimodal_cfg,
                  cur_token_len,
              )
      else:
          images_tensors = torch.tensor([])
          sources = copy.deepcopy(sources)
  
      if self.conv_template == "nvgpt":
          data_dict = preprocess_nvgpt(
              sources,
              self.tokenizer,
              self.multimodal_cfg,
          )
      elif self.conv_template == "v1":
          data_dict = preprocess_v1(
              sources,
              self.tokenizer,
              self.multimodal_cfg,
          )
      elif self.conv_template == "llama_2":
          data_dict = preprocess_llama_2(
              sources,
              self.tokenizer,
              self.multimodal_cfg,
          )
      else:
          raise ValueError(
              f"Conversation template `{self.conv_template}` is not supported in Neva now."
          )
  
      if isinstance(i, int):
          data_dict = dict(
              tokens=data_dict["tokens"][0],
              labels=data_dict["labels"][0],
          )
  
      # image exist in the data
      if self.multimodal_cfg["is_multimodal"]:
          crop_size = self.processor.crop_size
          # image does not exist in the data, but the model is multimodal
          zero_padding = torch.zeros(
              (
                  MAX_NUM_IMAGES - len(images_tensors),
                  3,
                  crop_size["height"],
                  crop_size["width"],
              ),
              dtype=torch.float,
          )
          images_tensors = torch.cat(
              (images_tensors, zero_padding), dim=0
          )
          data_dict["image"] = images_tensors
      return data_dict
  
imports: import copy
  import json
  import logging
  import os
  import re
  import tarfile
  from dataclasses import dataclass
  from typing import Any, Dict, List, Sequence, Union
  import torch
  import torch.nn.functional
  import transformers
  from einops import rearrange
  from omegaconf import DictConfig
  from PIL import Image
  from torch.utils.data import Dataset, default_collate
  from transformers import CLIPImageProcessor
  import nemo.collections.multimodal.data.neva.conversation
  from nemo.collections.nlp.modules.common.megatron.utils import get_ltor_masks_and_position_ids
label_desc: Use image node_id 3 for calling the LazySupervisedDataset obj's underlying member method code with example usage: obj.__getitem__(i) and returns: data_dict, pil_img, result, result