class_docstr: Hooks to be used for data related stuff.
class_docstr_tok: ["Hooks","to","be","used","for","data","related","stuff","."]
docstr: Use this to download and prepare data. Downloading and saving data with multiple processes (distributed
  settings) will result in corrupted data. Lightning ensures this method is called only within a single process,
  so you can safely add your downloading logic within.
  
  .. warning:: DO NOT set state to the model (use ``setup`` instead)
      since this is NOT called on every device
  
  Example::
  
      def prepare_data(self):
          # good
          download_data()
          tokenize()
          etc()
  
          # bad
          self.split = data_split
          self.some_state = some_other_state()
  
  In a distributed environment, ``prepare_data`` can be called in two ways
  (using :ref:`prepare_data_per_node<common/lightning_module:prepare_data_per_node>`)
  
  1. Once per node. This is the default and is only called on LOCAL_RANK=0.
  2. Once in total. Only called on GLOBAL_RANK=0.
  
  Example::
  
      # DEFAULT
      # called once per node on LOCAL_RANK=0 of that node
      class LitDataModule(LightningDataModule):
          def __init__(self):
              super().__init__()
              self.prepare_data_per_node = True
  
  
      # call on GLOBAL_RANK=0 (great for shared file systems)
      class LitDataModule(LightningDataModule):
          def __init__(self):
              super().__init__()
              self.prepare_data_per_node = False
  
  This is called before requesting the dataloaders:
  
  .. code-block:: python
  
      model.prepare_data()
      initialize_distributed()
      model.setup(stage)
      model.train_dataloader()
      model.val_dataloader()
      model.test_dataloader()
      model.predict_dataloader()
code: def prepare_data(self) -> None:
      """Use this to download and prepare data. Downloading and saving data with multiple processes (distributed
      settings) will result in corrupted data. Lightning ensures this method is called only within a single process,
      so you can safely add your downloading logic within.
  
      .. warning:: DO NOT set state to the model (use ``setup`` instead)
          since this is NOT called on every device
  
      Example::
  
          def prepare_data(self):
              # good
              download_data()
              tokenize()
              etc()
  
              # bad
              self.split = data_split
              self.some_state = some_other_state()
  
      In a distributed environment, ``prepare_data`` can be called in two ways
      (using :ref:`prepare_data_per_node<common/lightning_module:prepare_data_per_node>`)
  
      1. Once per node. This is the default and is only called on LOCAL_RANK=0.
      2. Once in total. Only called on GLOBAL_RANK=0.
  
      Example::
  
          # DEFAULT
          # called once per node on LOCAL_RANK=0 of that node
          class LitDataModule(LightningDataModule):
              def __init__(self):
                  super().__init__()
                  self.prepare_data_per_node = True
  
  
          # call on GLOBAL_RANK=0 (great for shared file systems)
          class LitDataModule(LightningDataModule):
              def __init__(self):
                  super().__init__()
                  self.prepare_data_per_node = False
  
      This is called before requesting the dataloaders:
  
      .. code-block:: python
  
          model.prepare_data()
          initialize_distributed()
          model.setup(stage)
          model.train_dataloader()
          model.val_dataloader()
          model.test_dataloader()
          model.predict_dataloader()
  
      """
  
imports: from typing import Any, Dict, Optional
  import torch
  from torch import Tensor
  from torch.optim.optimizer import Optimizer
  from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_0
  from lightning.pytorch.utilities import move_data_to_device
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.types import EVAL_DATALOADERS, STEP_OUTPUT, TRAIN_DATALOADERS
label_desc: Use image node_id 2 for calling the DataHooks obj's underlying member method code with example usage: obj.prepare_data() without return types