class_docstr: A DataModule standardizes the training, val, test splits, data preparation and transforms. The main advantage is
  consistent data splits, data preparation and transforms across models.
  
  Example::
  
      import lightning as L
      import torch.utils.data as data
      from lightning.pytorch.demos.boring_classes import RandomDataset
  
      class MyDataModule(L.LightningDataModule):
          def prepare_data(self):
              # download, IO, etc. Useful with shared filesystems
              # only called on 1 GPU/TPU in distributed
              ...
  
          def setup(self, stage):
              # make assignments here (val/train/test split)
              # called on every process in DDP
              dataset = RandomDataset(1, 100)
              self.train, self.val, self.test = data.random_split(
                  dataset, [80, 10, 10], generator=torch.Generator().manual_seed(42)
              )
  
          def train_dataloader(self):
              return data.DataLoader(self.train)
  
          def val_dataloader(self):
              return data.DataLoader(self.val)
  
          def test_dataloader(self):
              return data.DataLoader(self.test)
  
          def teardown(self):
              # clean up state after the trainer stops, delete files...
              # called on every process in DDP
              ...
class_docstr_tok: ["A","DataModule","standardizes","the","training",",","val",",","test","splits",",","data","preparation","and","transforms",".","The","main","advantage","is","consistent","data","splits",",","data","preparation","and","transforms","across","models",".","Example",":",":","import","lightning","as","L","import","torch.utils.data","as","data","from","lightning.pytorch.demos.boring_classes","import","RandomDataset","class","MyDataModule","(","L.LightningDataModule",")",":","def","prepare_data","(","self",")",":","#","download",",","IO",",","etc",".","Useful","with","shared","filesystems","#","only","called","on","1","GPU\/TPU","in","distributed","...","def","setup","(","self",",","stage",")",":","#","make","assignments","here","(","val\/train\/test","split",")","#","called","on","every","process","in","DDP","dataset","=","RandomDataset","(","1",",","100",")","self.train",",","self.val",",","self.test","=","data.random_split","(","dataset",",","[","80",",","10",",","10","]",",","generator=torch.Generator","(",")",".manual_seed","(","42",")",")","def","train_dataloader","(","self",")",":","return","data.DataLoader","(","self.train",")","def","val_dataloader","(","self",")",":","return","data.DataLoader","(","self.val",")","def","test_dataloader","(","self",")",":","return","data.DataLoader","(","self.test",")","def","teardown","(","self",")",":","#","clean","up","state","after","the","trainer","stops",",","delete","files","...","#","called","on","every","process","in","DDP","..."]
docstr: Called when saving a checkpoint, implement to generate and save datamodule state.
  
  Returns:
      A dictionary containing datamodule state.
docstr_tok: ["Called","when","saving","a","checkpoint",",","implement","to","generate","and","save","datamodule","state",".","Returns",":","A","dictionary","containing","datamodule","state","."]
code: def state_dict(self) -> Dict[str, Any]:
      """Called when saving a checkpoint, implement to generate and save datamodule state.
  
      Returns:
          A dictionary containing datamodule state.
  
      """
      return {}
  
file_path: pytorch-lightning/src/lightning/pytorch/core/datamodule.py
imports: import inspect
  from typing import IO, Any, Dict, Iterable, Optional, Union, cast
  from lightning_utilities import apply_to_collection
  from torch.utils.data import DataLoader, Dataset, IterableDataset
  from typing_extensions import Self
  import lightning.pytorch
  from lightning.fabric.utilities.types import _MAP_LOCATION_TYPE, _PATH
  from lightning.pytorch.core.hooks import DataHooks
  from lightning.pytorch.core.mixins import HyperparametersMixin
  from lightning.pytorch.core.saving import _load_from_checkpoint
  from lightning.pytorch.utilities.model_helpers import _restricted_classmethod
  from lightning.pytorch.utilities.types import EVAL_DATALOADERS, TRAIN_DATALOADERS
label_desc: Use image node_id 3 for calling the LightningDataModule obj's underlying member method code with example usage: obj.state_dict() and returns: dict