code: def random_splits_mask(
      dataset: InMemoryDataset,
      train_ratio: float = 0.2,
      val_ratio: float = 0.4,
      seed: _typing.Optional[int] = None,
  ) -> InMemoryDataset:
      r"""If the data has masks for train/val/test, return the splits with specific ratio.
  
      Parameters
      ----------
      dataset : InMemoryDataset
          graph set
      train_ratio : float
          the portion of data that used for training.
  
      val_ratio : float
          the portion of data that used for validation.
  
      seed : int
          random seed for splitting dataset.
      """
      if not train_ratio + val_ratio <= 1:
          raise ValueError(
              "the sum of provided train_ratio and val_ratio is larger than 1"
          )
  
      def __random_split_masks(
          data, num_nodes: int
      ) -> _typing.Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
          _rng_state: torch.Tensor = torch.get_rng_state()
          if seed is not None and isinstance(seed, int):
              torch.manual_seed(seed)
          perm = torch.randperm(num_nodes)
          train_index = perm[: int(num_nodes * train_ratio)]
          val_index = perm[
              int(num_nodes * train_ratio) : int(
                  num_nodes * (train_ratio + val_ratio)
              )
          ]
          test_index = perm[
              int(num_nodes * (train_ratio + val_ratio)) :
          ]
          torch.set_rng_state(_rng_state)
          data.train_mask = index_to_mask(train_index, num_nodes)
          data.val_mask = index_to_mask(val_index, num_nodes)
          data.test_mask = index_to_mask(test_index, num_nodes)
          return data
  
      if _backend.DependentBackend.is_pyg():
          dataset = [
              __random_split_masks(data, data.num_nodes)
              for data in dataset
          ]
      else:
          pass
      return dataset
  
file_path: AutoGL/autogl/datasets/utils/_general.py
imports: import numpy
  import random
  import torch
  import torch.utils.data
  import typing
  from sklearn.model_selection import StratifiedKFold, KFold
  from autogl import backend
  from autogl.data import InMemoryDataset
label_desc: Use image node_id 2 for calling a global function with example usage: random_splits_mask(dataset, train_ratio, val_ratio, seed) and returns: dataset, data