class_docstr: Top-level loop where prediction starts.
class_docstr_tok: ["Top-level","loop","where","prediction","starts","."]
code: def run(self) -> Optional[_PREDICT_OUTPUT]:
      self.setup_data()
      if self.skip:
          return None
      self.reset()
      self.on_run_start()
      data_fetcher = self._data_fetcher
      assert data_fetcher is not None
      while True:
          try:
              if isinstance(data_fetcher, _DataLoaderIterDataFetcher):
                  dataloader_iter = next(data_fetcher)
                  # hook's batch_idx and dataloader_idx arguments correctness cannot be guaranteed in this setting
                  batch = data_fetcher._batch
                  batch_idx = data_fetcher._batch_idx
                  dataloader_idx = data_fetcher._dataloader_idx
              else:
                  dataloader_iter = None
                  batch, batch_idx, dataloader_idx = next(data_fetcher)
              self.batch_progress.is_last_batch = data_fetcher.done
              # run step hooks
              self._predict_step(
                  batch, batch_idx, dataloader_idx, dataloader_iter
              )
          except StopIteration:
              # this needs to wrap the `*_step` call too (not just `next`) for `dataloader_iter` support
              break
          finally:
              self._restarting = False
      return self.on_run_end()
  
imports: from collections import OrderedDict
  from typing import Any, Iterator, List, Optional, Union
  import torch
  from lightning_utilities import WarningCache
  import lightning.pytorch
  from lightning.fabric.utilities import move_data_to_device
  from lightning.pytorch.callbacks import BasePredictionWriter
  from lightning.pytorch.loops.fetchers import _DataFetcher, _DataLoaderIterDataFetcher
  from lightning.pytorch.loops.loop import _Loop
  from lightning.pytorch.loops.progress import _Progress
  from lightning.pytorch.loops.utilities import _no_grad_context, _select_data_fetcher, _verify_dataloader_idx_requirement
  from lightning.pytorch.overrides.distributed import _IndexBatchSamplerWrapper
  from lightning.pytorch.strategies.launchers import _MultiProcessingLauncher
  from lightning.pytorch.trainer import call
  from lightning.pytorch.trainer.connectors.data_connector import _check_dataloader_iterable, _DataLoaderSource, _parse_num_batches, _process_dataloader, _request_dataloader
  from lightning.pytorch.trainer.states import RunningStage, TrainerFn
  from lightning.pytorch.utilities.combined_loader import CombinedLoader
  from lightning.pytorch.utilities.data import has_len_all_ranks
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.model_helpers import _ModuleMode
  from lightning.pytorch.utilities.signature_utils import is_param_in_hook_signature
  from lightning.pytorch.utilities.types import _PREDICT_OUTPUT
label_desc: Use image node_id 7 for calling the _PredictionLoop obj's underlying member method code with example usage: obj.run() and returns: self, None