class_docstr: Dataset base class for creating graph datasets which easily fit
  into CPU memory.
  See `here <https://pytorch-geometric.readthedocs.io/en/latest/tutorial/
  create_dataset.html#creating-in-memory-datasets>`__ for the accompanying
  tutorial.
  
  Args:
      root (str, optional): Root directory where the dataset should be saved.
          (optional: :obj:`None`)
      transform (callable, optional): A function/transform that takes in a
          :class:`~torch_geometric.data.Data` or
          :class:`~torch_geometric.data.HeteroData` object and returns a
          transformed version.
          The data object will be transformed before every access.
          (default: :obj:`None`)
      pre_transform (callable, optional): A function/transform that takes in
          a :class:`~torch_geometric.data.Data` or
          :class:`~torch_geometric.data.HeteroData` object and returns a
          transformed version.
          The data object will be transformed before being saved to disk.
          (default: :obj:`None`)
      pre_filter (callable, optional): A function that takes in a
          :class:`~torch_geometric.data.Data` or
          :class:`~torch_geometric.data.HeteroData` object and returns a
          boolean value, indicating whether the data object should be
          included in the final dataset. (default: :obj:`None`)
      log (bool, optional): Whether to print any console output while
          downloading and processing the dataset. (default: :obj:`True`)
      force_reload (bool, optional): Whether to re-process the dataset.
          (default: :obj:`False`)
class_docstr_tok: ["Dataset","base","class","for","creating","graph","datasets","which","easily","fit","into","CPU","memory",".","See","`","here","<","https",":","\/\/pytorch-geometric.readthedocs.io\/en\/latest\/tutorial\/","create_dataset.html","#","creating-in-memory-datasets",">","`","__","for","the","accompanying","tutorial",".","Args",":","root","(","str",",","optional",")",":","Root","directory","where","the","dataset","should","be","saved",".","(","optional",":",":","obj",":","`","None","`",")","transform","(","callable",",","optional",")",":","A","function\/transform","that","takes","in","a",":","class",":","`","~torch_geometric.data.Data","`","or",":","class",":","`","~torch_geometric.data.HeteroData","`","object","and","returns","a","transformed","version",".","The","data","object","will","be","transformed","before","every","access",".","(","default",":",":","obj",":","`","None","`",")","pre_transform","(","callable",",","optional",")",":","A","function\/transform","that","takes","in","a",":","class",":","`","~torch_geometric.data.Data","`","or",":","class",":","`","~torch_geometric.data.HeteroData","`","object","and","returns","a","transformed","version",".","The","data","object","will","be","transformed","before","being","saved","to","disk",".","(","default",":",":","obj",":","`","None","`",")","pre_filter","(","callable",",","optional",")",":","A","function","that","takes","in","a",":","class",":","`","~torch_geometric.data.Data","`","or",":","class",":","`","~torch_geometric.data.HeteroData","`","object","and","returns","a","boolean","value",",","indicating","whether","the","data","object","should","be","included","in","the","final","dataset",".","(","default",":",":","obj",":","`","None","`",")","log","(","bool",",","optional",")",":","Whether","to","print","any","console","output","while","downloading","and","processing","the","dataset",".","(","default",":",":","obj",":","`","True","`",")","force_reload","(","bool",",","optional",")",":","Whether","to","re-process","the","dataset",".","(","default",":",":","obj",":","`","False","`",")"]
docstr: Converts the :class:`InMemoryDataset` to a :class:`OnDiskDataset`
  variant. Useful for distributed training and hardware instances with
  limited amount of shared memory.
  
  root (str, optional): Root directory where the dataset should be saved.
      If set to :obj:`None`, will save the dataset in
      :obj:`root/on_disk`.
      Note that it is important to specify :obj:`root` to account for
      different dataset splits. (optional: :obj:`None`)
  backend (str): The :class:`Database` backend to use.
      (default: :obj:`"sqlite"`)
  log (bool, optional): Whether to print any console output while
      processing the dataset. (default: :obj:`True`)
docstr_tok: ["Converts","the",":","class",":","`","InMemoryDataset","`","to","a",":","class",":","`","OnDiskDataset","`","variant",".","Useful","for","distributed","training","and","hardware","instances","with","limited","amount","of","shared","memory",".","root","(","str",",","optional",")",":","Root","directory","where","the","dataset","should","be","saved",".","If","set","to",":","obj",":","`","None","`",",","will","save","the","dataset","in",":","obj",":","`","root\/on_disk","`",".","Note","that","it","is","important","to","specify",":","obj",":","`","root","`","to","account","for","different","dataset","splits",".","(","optional",":",":","obj",":","`","None","`",")","backend","(","str",")",":","The",":","class",":","`","Database","`","backend","to","use",".","(","default",":",":","obj",":","`","``","sqlite","''","`",")","log","(","bool",",","optional",")",":","Whether","to","print","any","console","output","while","processing","the","dataset",".","(","default",":",":","obj",":","`","True","`",")"]
code: def to_on_disk_dataset(
      self,
      root: Optional[str] = None,
      backend: str = "sqlite",
      log: bool = True,
  ) -> "torch_geometric.data.OnDiskDataset":
      r"""Converts the :class:`InMemoryDataset` to a :class:`OnDiskDataset`
      variant. Useful for distributed training and hardware instances with
      limited amount of shared memory.
  
      root (str, optional): Root directory where the dataset should be saved.
          If set to :obj:`None`, will save the dataset in
          :obj:`root/on_disk`.
          Note that it is important to specify :obj:`root` to account for
          different dataset splits. (optional: :obj:`None`)
      backend (str): The :class:`Database` backend to use.
          (default: :obj:`"sqlite"`)
      log (bool, optional): Whether to print any console output while
          processing the dataset. (default: :obj:`True`)
      """
      if root is None and (
          self.root is None or not osp.exists(self.root)
      ):
          raise ValueError(
              f"The root directory of "
              f"'{self.__class__.__name__}' is not specified. "
              f"Please pass in 'root' when creating on-disk "
              f"datasets from it."
          )
  
      root = root or osp.join(self.root, "on_disk")
  
      in_memory_dataset = self
      ref_data = in_memory_dataset.get(0)
      if not isinstance(ref_data, Data):
          raise NotImplementedError(
              f"`{self.__class__.__name__}.to_on_disk_dataset()` is "
              f"currently only supported on homogeneous graphs"
          )
  
      # Parse the schema ====================================================
  
      schema: Dict[str, Any] = {}
      for key, value in ref_data.to_dict().items():
          if isinstance(value, (int, float, str)):
              schema[key] = value.__class__
          elif isinstance(value, Tensor) and value.dim() == 0:
              schema[key] = dict(dtype=value.dtype, size=(-1,))
          elif isinstance(value, Tensor):
              size = list(value.size())
              size[ref_data.__cat_dim__(key, value)] = -1
              schema[key] = dict(dtype=value.dtype, size=tuple(size))
          else:
              schema[key] = object
  
      # Create the on-disk dataset ==========================================
  
      class OnDiskDataset(torch_geometric.data.OnDiskDataset):
          def __init__(
              self,
              root: str,
              transform: Optional[Callable] = None,
          ):
              super().__init__(
                  root=root,
                  transform=transform,
                  backend=backend,
                  schema=schema,
              )
  
          def process(self):
              _iter = [
                  in_memory_dataset.get(i)
                  for i in in_memory_dataset.indices()
              ]
              if log:  # pragma: no cover
                  _iter = tqdm(
                      _iter, desc="Converting to OnDiskDataset"
                  )
  
              data_list: List[Data] = []
              for i, data in enumerate(_iter):
                  data_list.append(data)
                  if (
                      i + 1 == len(in_memory_dataset)
                      or (i + 1) % 1000 == 0
                  ):
                      self.extend(data_list)
                      data_list = []
  
          def serialize(self, data: Data) -> Dict[str, Any]:
              return data.to_dict()
  
          def deserialize(self, data: Dict[str, Any]) -> Data:
              return Data.from_dict(data)
  
          def __repr__(self) -> str:
              arg_repr = str(len(self)) if len(self) > 1 else ""
              return (
                  f"OnDisk{in_memory_dataset.__class__.__name__}("
                  f"{arg_repr})"
              )
  
      return OnDiskDataset(root, transform=in_memory_dataset.transform)
  
imports: import copy
  import os.path
  import warnings
  from abc import ABC
  from typing import Any, Callable, Dict, Iterable, List, Mapping, MutableSequence, Optional, Sequence, Tuple, Type, Union
  import torch
  from torch import Tensor
  from tqdm import tqdm
  import torch_geometric
  from torch_geometric.data import Batch, Data
  from torch_geometric.data.collate import collate
  from torch_geometric.data.data import BaseData
  from torch_geometric.data.dataset import Dataset, IndexType
  from torch_geometric.data.separate import separate
  from torch_geometric.io import fs
label_desc: Use image node_id 11 for calling the InMemoryDataset obj's underlying member method code with example usage: obj.to_on_disk_dataset(root, backend, log) and returns: OnDiskDataset, data, Data, str, in_memory_dataset, str, arg_repr, str