class_docstr: Saves a LightningCLI config to the log_dir when training starts.
  
  Raises:
      RuntimeError: If the config file already exists in the directory to avoid overwriting a previous run
class_docstr_tok: ["Saves","a","LightningCLI","config","to","the","log_dir","when","training","starts",".","Raises",":","RuntimeError",":","If","the","config","file","already","exists","in","the","directory","to","avoid","overwriting","a","previous","run"]
code: def setup(
      self,
      trainer: Trainer,
      pl_module: LightningModule,
      stage: Optional[str] = None,
  ) -> None:
      # save the config in `setup` because (1) we want it to save regardless of the trainer function run
      # and we want to save before processes are spawned
      log_dir = trainer.log_dir
      assert log_dir is not None
      config_path = os.path.join(log_dir, self.config_filename)
      if not self.overwrite and os.path.isfile(config_path):
          raise RuntimeError(
              f"{self.__class__.__name__} expected {config_path} to NOT exist. Aborting to avoid overwriting"
              " results of a previous run. You can delete the previous config file,"
              " set `LightningCLI(save_config_callback=None)` to disable config saving,"
              " or set `LightningCLI(save_config_overwrite=True)` to overwrite the config file."
          )
      if trainer.is_global_zero:
          # save only on rank zero to avoid race conditions on DDP.
          # the `log_dir` needs to be created as we rely on the logger to do it usually
          # but it hasn't logged anything at this point
          get_filesystem(log_dir).makedirs(log_dir, exist_ok=True)
          self.parser.save(
              self.config,
              config_path,
              skip_none=False,
              overwrite=self.overwrite,
          )
  
imports: import inspect
  import os
  import warnings
  from argparse import Namespace
  from types import MethodType
  from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union, cast
  import torch
  from jsonargparse import ActionConfigFile, ArgumentParser, class_from_function, set_config_read_mode
  from pytorch_lightning import LightningDataModule, LightningModule, Trainer
  from pytorch_lightning.callbacks import Callback
  from pytorch_lightning.utilities.cloud_io import get_filesystem
  from pytorch_lightning.utilities.model_helpers import is_overridden
  from pytorch_lightning.utilities.seed import seed_everything
  from torch.optim import Optimizer
label_desc: Use image node_id 2 for calling the SaveConfigCallback obj's underlying member method code with example usage: obj.setup(trainer, pl_module, stage) without return types