code: def build_train_valid_datasets(
      model_cfg,
      consumed_samples,
  ):
      data_cfg = model_cfg.data
      condition_cfg = model_cfg.conditioning
  
      if data_cfg.get("synthetic_data", False):
          logging.info(f"Creating Synthetic Datasaet.")
          train_data = ImagenSyntheticDataset(
              res=data_cfg.train.get("target_resolutions", 64),
              conditioning_cfg=condition_cfg,
              fake_len=data_cfg.get("synthetic_data_length", 10000),
              no_embedding=condition_cfg.get("online_encoding", False),
          )
          return train_data, None
      # This function maps data that are tuples to dictionary.
      if condition_cfg.get("online_encoding", False):
          tuple_to_dict, transform_fn = _build_functions_no_pickles(
              data_cfg
          )
      else:
          tuple_to_dict, transform_fn = _build_functions_with_pickles(
              data_cfg, condition_cfg
          )
  
      filter_cfg = data_cfg.train.get("filterings", None)
  
      # For adding corruptions and obtaining image pyramid
      if model_cfg.unet_type.startswith("sr"):
          assert data_cfg.train.get(
              "target_resolutions"
          ), "SR model requires multiple resolution for training"
          logging.info(
              f"Resizing input images into the follow resolutions: {data_cfg.train.target_resolutions}"
          )
          corruption_gen = ImagePyramidNoCorruptions(
              target_resolutions=data_cfg.train.target_resolutions
          )
      else:
          corruption_gen = None
  
      # This function is used for obtaining image pyramid
      # in SR models for Imagen, we need to use low-res image as conditioning.
      def obtain_image_pyramid(inp):
          for data_dict in inp:
              data_pyramid = corruption_gen.obtain_image_pyramid(
                  data_dict["images"]
              )
              data_dict.update(data_pyramid)
              yield data_dict
  
      compose_fn = [tuple_to_dict]
      if corruption_gen:
          compose_fn.append(obtain_image_pyramid)
  
      train_data = WebDatasetCommon(
          dataset_cfg=data_cfg,
          consumed_samples=consumed_samples,
          map_fn=transform_fn,
          compose_fn=compose_fn,
          filter_fn=build_resolution_filter(
              **filter_cfg.resolution, image_idx="jpg"
          )
          if filter_cfg
          else None,
          is_train=True,
      )
      return train_data, None
  
file_path: NeMo/nemo/collections/multimodal/data/imagen/imagen_dataset.py
imports: import torch
  from nemo.collections.multimodal.data.common.webdataset import WebDatasetCommon
  from nemo.collections.multimodal.data.imagen.augmentations.augmentations import PickleTransform, build_resolution_filter
  from nemo.collections.multimodal.data.imagen.augmentations.corruption import ImagePyramidNoCorruptions
  from nemo.collections.multimodal.data.stable_diffusion.augmentation.augmentations import construct_image_augmentations, identical_transform
  from nemo.core.classes import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 3 for calling a global function with example usage: build_train_valid_datasets(model_cfg, consumed_samples) and returns: train_data,  None, train_data,  None