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: Primary way of loading a datamodule from a checkpoint. When Lightning saves a checkpoint it stores the
  arguments passed to ``__init__``  in the checkpoint under ``"datamodule_hyper_parameters"``.
  
  Any arguments specified through \*\*kwargs will override args stored in ``"datamodule_hyper_parameters"``.
  
  Args:
      checkpoint_path: Path to checkpoint. This can also be a URL, or file-like object
      map_location:
          If your checkpoint saved a GPU model and you now load on CPUs
          or a different number of GPUs, use this to map to the new setup.
          The behaviour is the same as in :func:`torch.load`.
      hparams_file: Optional path to a ``.yaml`` or ``.csv`` file with hierarchical structure
          as in this example::
  
              dataloader:
                  batch_size: 32
  
          You most likely won't need this since Lightning will always save the hyperparameters
          to the checkpoint.
          However, if your checkpoint weights don't have the hyperparameters saved,
          use this method to pass in a ``.yaml`` file with the hparams you'd like to use.
          These will be converted into a :class:`~dict` and passed into your
          :class:`LightningDataModule` for use.
  
          If your datamodule's ``hparams`` argument is :class:`~argparse.Namespace`
          and ``.yaml`` file has hierarchical structure, you need to refactor your datamodule to treat
          ``hparams`` as :class:`~dict`.
      \**kwargs: Any extra keyword args needed to init the datamodule. Can also be used to override saved
          hyperparameter values.
  
  Return:
      :class:`LightningDataModule` instance with loaded weights and hyperparameters (if available).
  
  Note:
      ``load_from_checkpoint`` is a **class** method. You must use your :class:`LightningDataModule`
      **class** to call it instead of the :class:`LightningDataModule` instance, or a
      ``TypeError`` will be raised.
  
  Example::
  
      # load weights without mapping ...
      datamodule = MyLightningDataModule.load_from_checkpoint('path/to/checkpoint.ckpt')
  
      # or load weights and hyperparameters from separate files.
      datamodule = MyLightningDataModule.load_from_checkpoint(
          'path/to/checkpoint.ckpt',
          hparams_file='/path/to/hparams_file.yaml'
      )
  
      # override some of the params with new values
      datamodule = MyLightningDataModule.load_from_checkpoint(
          PATH,
          batch_size=32,
          num_workers=10,
      )
docstr_tok: ["Primary","way","of","loading","a","datamodule","from","a","checkpoint",".","When","Lightning","saves","a","checkpoint","it","stores","the","arguments","passed","to","``","__init__","``","in","the","checkpoint","under","``","``","datamodule_hyper_parameters","''","``",".","Any","arguments","specified","through","\\","*","\\","*","kwargs","will","override","args","stored","in","``","``","datamodule_hyper_parameters","''","``",".","Args",":","checkpoint_path",":","Path","to","checkpoint",".","This","can","also","be","a","URL",",","or","file-like","object","map_location",":","If","your","checkpoint","saved","a","GPU","model","and","you","now","load","on","CPUs","or","a","different","number","of","GPUs",",","use","this","to","map","to","the","new","setup",".","The","behaviour","is","the","same","as","in",":","func",":","`","torch.load","`",".","hparams_file",":","Optional","path","to","a","``",".yaml","``","or","``",".csv","``","file","with","hierarchical","structure","as","in","this","example",":",":","dataloader",":","batch_size",":","32","You","most","likely","wo","n't","need","this","since","Lightning","will","always","save","the","hyperparameters","to","the","checkpoint",".","However",",","if","your","checkpoint","weights","do","n't","have","the","hyperparameters","saved",",","use","this","method","to","pass","in","a","``",".yaml","``","file","with","the","hparams","you","'d","like","to","use",".","These","will","be","converted","into","a",":","class",":","`","~dict","`","and","passed","into","your",":","class",":","`","LightningDataModule","`","for","use",".","If","your","datamodule","'s","``","hparams","``","argument","is",":","class",":","`","~argparse.Namespace","`","and","``",".yaml","``","file","has","hierarchical","structure",",","you","need","to","refactor","your","datamodule","to","treat","``","hparams","``","as",":","class",":","`","~dict","`",".","\\","*","*","kwargs",":","Any","extra","keyword","args","needed","to","init","the","datamodule",".","Can","also","be","used","to","override","saved","hyperparameter","values",".","Return",":",":","class",":","`","LightningDataModule","`","instance","with","loaded","weights","and","hyperparameters","(","if","available",")",".","Note",":","``","load_from_checkpoint","``","is","a","*","*","class","*","*","method",".","You","must","use","your",":","class",":","`","LightningDataModule","`","*","*","class","*","*","to","call","it","instead","of","the",":","class",":","`","LightningDataModule","`","instance",",","or","a","``","TypeError","``","will","be","raised",".","Example",":",":","#","load","weights","without","mapping","...","datamodule","=","MyLightningDataModule.load_from_checkpoint","(","'path\/to\/checkpoint.ckpt","'",")","#","or","load","weights","and","hyperparameters","from","separate","files",".","datamodule","=","MyLightningDataModule.load_from_checkpoint","(","'path\/to\/checkpoint.ckpt","'",",","hparams_file='\/path\/to\/hparams_file.yaml'",")","#","override","some","of","the","params","with","new","values","datamodule","=","MyLightningDataModule.load_from_checkpoint","(","PATH",",","batch_size=32",",","num_workers=10",",",")"]
code: def load_from_checkpoint(
      cls,
      checkpoint_path: Union[_PATH, IO],
      map_location: _MAP_LOCATION_TYPE = None,
      hparams_file: Optional[_PATH] = None,
      **kwargs: Any,
  ) -> Self:
      r"""Primary way of loading a datamodule from a checkpoint. When Lightning saves a checkpoint it stores the
      arguments passed to ``__init__``  in the checkpoint under ``"datamodule_hyper_parameters"``.
  
      Any arguments specified through \*\*kwargs will override args stored in ``"datamodule_hyper_parameters"``.
  
      Args:
          checkpoint_path: Path to checkpoint. This can also be a URL, or file-like object
          map_location:
              If your checkpoint saved a GPU model and you now load on CPUs
              or a different number of GPUs, use this to map to the new setup.
              The behaviour is the same as in :func:`torch.load`.
          hparams_file: Optional path to a ``.yaml`` or ``.csv`` file with hierarchical structure
              as in this example::
  
                  dataloader:
                      batch_size: 32
  
              You most likely won't need this since Lightning will always save the hyperparameters
              to the checkpoint.
              However, if your checkpoint weights don't have the hyperparameters saved,
              use this method to pass in a ``.yaml`` file with the hparams you'd like to use.
              These will be converted into a :class:`~dict` and passed into your
              :class:`LightningDataModule` for use.
  
              If your datamodule's ``hparams`` argument is :class:`~argparse.Namespace`
              and ``.yaml`` file has hierarchical structure, you need to refactor your datamodule to treat
              ``hparams`` as :class:`~dict`.
          \**kwargs: Any extra keyword args needed to init the datamodule. Can also be used to override saved
              hyperparameter values.
  
      Return:
          :class:`LightningDataModule` instance with loaded weights and hyperparameters (if available).
  
      Note:
          ``load_from_checkpoint`` is a **class** method. You must use your :class:`LightningDataModule`
          **class** to call it instead of the :class:`LightningDataModule` instance, or a
          ``TypeError`` will be raised.
  
      Example::
  
          # load weights without mapping ...
          datamodule = MyLightningDataModule.load_from_checkpoint('path/to/checkpoint.ckpt')
  
          # or load weights and hyperparameters from separate files.
          datamodule = MyLightningDataModule.load_from_checkpoint(
              'path/to/checkpoint.ckpt',
              hparams_file='/path/to/hparams_file.yaml'
          )
  
          # override some of the params with new values
          datamodule = MyLightningDataModule.load_from_checkpoint(
              PATH,
              batch_size=32,
              num_workers=10,
          )
  
      """
      loaded = _load_from_checkpoint(
          cls,  # type: ignore[arg-type]
          checkpoint_path,
          map_location=map_location,
          hparams_file=hparams_file,
          strict=None,
          **kwargs,
      )
      return cast(Self, loaded)
  
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 5 for calling the LightningDataModule obj's underlying member method code with example usage: obj.load_from_checkpoint(cls, checkpoint_path, map_location, hparams_file) and returns: cast