code: def load_train_valid_data(cfg) -> Tuple[pd.DataFrame, pd.DataFrame]:
      if cfg.dataset.validation_strategy == "custom":
          if cfg.dataset.validation_dataframe == "None":
              raise LLMDataException(
                  "No validation dataframe provided. "
                  "Please provide a validation dataframe or "
                  "choose a different validation strategy."
              )
          train_df = read_dataframe_drop_missing_labels(
              cfg.dataset.train_dataframe, cfg
          )
          val_df = read_dataframe_drop_missing_labels(
              cfg.dataset.validation_dataframe, cfg
          )
      elif cfg.dataset.validation_strategy == "automatic":
          if cfg.environment._local_rank == 0:
              logger.info("Setting up automatic validation split...")
          df = read_dataframe_drop_missing_labels(
              cfg.dataset.train_dataframe, cfg
          )
          if (
              cfg.dataset.parent_id_column != "None"
              and "id" in df.columns
          ):
              # split based on conversation_chain_ids
              # this ensures that all samples from the
              # same conversation are in the same fold
              with PatchedAttribute(
                  cfg.dataset, "limit_chained_samples", True
              ):
                  conversation_chain_ids = ConversationChainHandler(
                      df=df, cfg=cfg
                  ).conversation_chain_ids
              # Some conversations may have the same parent id, e.g. for OASST
              # 6aa548c6-65ad-4531-9411-76173ae060a3 and
              # 2a164c2a-4f0e-45aa-8990-e7dd3b51c06b
              # have the same parent a8df94e3-cfc7-4736-9587-0ec943d0fec3
              # We need to merge those into a single group
              conversation_chain_ids = merge_on_common_items(
                  conversation_chain_ids
              )
              conversation_chain_labels = [
                  i
                  for i, conversation_chain_id in enumerate(
                      conversation_chain_ids
                  )
                  for _ in conversation_chain_id
              ]
              group_shuffle_split = GroupShuffleSplit(
                  test_size=cfg.dataset.validation_size,
                  n_splits=1,
                  random_state=1337,
              )
              train_idx, val_idx = next(
                  group_shuffle_split.split(
                      df, groups=conversation_chain_labels
                  )
              )
              # flatten conversation_chain_ids
              flattened_conversation_chain_ids = np.array(
                  [
                      idx
                      for conversation_chain_id in conversation_chain_ids
                      for idx in conversation_chain_id
                  ]
              )
              train_df = df.iloc[
                  flattened_conversation_chain_ids[train_idx]
              ].reset_index(drop=True)
              val_df = df.iloc[
                  flattened_conversation_chain_ids[val_idx]
              ].reset_index(drop=True)
          else:
              train_df, val_df = train_test_split(
                  df,
                  test_size=cfg.dataset.validation_size,
                  random_state=1337,
              )
      else:
          raise LLMDataException(
              "No valid validation strategy provided."
          )
      return train_df, val_df
  
imports: import logging
  import math
  import os
  from typing import Any, DefaultDict, Dict, List, Optional, Tuple, Union, no_type_check
  import networkx
  import numpy
  import pandas
  import pyarrow.parquet
  import torch
  from sklearn.model_selection import GroupShuffleSplit, train_test_split
  from torch import distributed
  from torch.utils.data import DataLoader, Sampler, SequentialSampler
  from llm_studio.src.datasets.conversation_chain_handler import ConversationChainHandler
  from llm_studio.src.utils.exceptions import LLMDataException
  from llm_studio.src.utils.utils import PatchedAttribute, set_seed
label_desc: Use image node_id 9 for calling a global function with example usage: load_train_valid_data(cfg) and returns: train_df,  val_df