---
title: SaveConfigCallback
description: Saves a LightningCLI config to the log_dir when training starts.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.cli.SaveConfigCallback
---
# SaveConfigCallback {#saveconfigcallback}

### `class lightning.pytorch.cli.SaveConfigCallback(parser, config, config_filename='config.yaml', overwrite=False, multifile=False, save_to_log_dir=True)` {#lightning.pytorch.cli.SaveConfigCallback}

Bases: [`Callback`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.callbacks.Callback.md#lightning.pytorch.callbacks.Callback "lightning.pytorch.callbacks.callback.Callback")

Saves a LightningCLI config to the log\_dir when training starts.

Parameters:

*   **parser** ([`LightningArgumentParser`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.cli.LightningArgumentParser.md#lightning.pytorch.cli.LightningArgumentParser "lightning.pytorch.cli.LightningArgumentParser")) – The parser object used to parse the configuration.
    
*   **config** ([`object`](https://docs.python.org/3/builtins/functions.html#object "(in Python v3.15)")) – The parsed configuration that will be saved.
    
*   **config\_filename** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Filename for the config file.
    
*   **overwrite** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether to overwrite an existing config file.
    
*   **multifile** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – When input is multiple config files, saved config preserves this structure.
    
*   **save\_to\_log\_dir** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether to save the config to the log\_dir.
    

Raises:

[**RuntimeError**](https://docs.python.org/3/builtins/exceptions.html#RuntimeError "(in Python v3.15)") – If the config file already exists in the directory to avoid overwriting a previous run

#### `save_config(trainer, pl_module, stage)` {#lightning.pytorch.cli.SaveConfigCallback.save_config}

Implement to save the config in some other place additional to the standard log\_dir.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

Example

def save\_config(self, trainer, pl\_module, stage):

if isinstance(trainer.logger, Logger):

config = self.parser.dump(self.config, skip\_none=False) # Required for proper reproducibility trainer.logger.log\_hyperparams({“config”: config})

Note

This method is only called on rank zero. This allows to implement a custom save config without having to worry about ranks or race conditions. Since it only runs on rank zero, any collective call will make the process hang waiting for a broadcast. If you need to make collective calls, implement the setup method instead.

#### `setup(trainer, pl_module, stage)` {#lightning.pytorch.cli.SaveConfigCallback.setup}

Called when fit, validate, test, predict, or tune begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

---

**Navigation**

- Parent: [Api](/docs/pytorch/2.6.6/optional-api/api.md)
