lightning/docs/source-pytorch/cli/lightning_cli_advanced.rst

114 lines
2.7 KiB
ReStructuredText
Raw Normal View History

docs refactor 3/n (#12795) * updated titles + css * updated titles + css * levels structure * levels structure * levels structure * adding level indexes * finished intro guide layout * finished intro guide layout * general titles * general titles * added movie * added movie * finished 15 mins * levels * added core levels * added core levels * fixed api reference on the left * gpu guides * gpu guides * gpu guides * gpu guides * precision * hpu guide * added ipu * added ipu * added ipu * added ckpt docs * finished basic logging * intermediate * intermediate * intermediate * fixed * fixed margins * fixed margins * fixed margins * fixed margins * fixed margins * fixed margins * fixed margins * fixed margins * fixed margins * added logger stuff * added logger stuff * added logger stuff * added logger stuff * added logger stuff * ic * added inconsolata * added inconsolata * added inconsolata * added inconsolata * added inconsolata * added inconsolata * added inconsolata * updated menu * added basic cloud docs * added basic cloud docs * added basic cloud docs * added basic cloud docs * ic * ic * ic * ic * ic * ic * ic * ic * ic * ic * ic * ic * added demos folder * added demos folder * added demos folder * added demos folder * added demos folder * added demos folder * twocolumns directive * twocols * twocols * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * registry * cleaning up * cleaning up * cleaning up * cleaning up * cleaning up * cleaning up * cleaning up * cleaning up * cleaning up * updated titles + css * levels structure * adding level indexes * finished intro guide layout * general titles * added movie * finished 15 mins * levels * added core levels * fixed api reference on the left * gpu guides * precision * hpu guide * added ipu * added ckpt docs * finished basic logging * intermediate * fixed margins * added logger stuff * ic * added inconsolata * updated menu * added basic cloud docs * ic * added demos folder * twocolumns directive * registry * cleaning up * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * deconflict * deconflict * deconflict * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add testsetup sections wherever needed; fix errors in building docs * pre-commit fixes * Fix duplicate label * minor nit with pre-commit * Fix labels * More changes... * require * debug & cli * prec & model & visu * fix references * fix references * fix refs * fix refs - model_parallel * fix references * prune testsetup with global * refs in index * Fix duplicate label errors * Update orphan docs * Update orphan docs * Update orphan docs * fix links * Fix genindex and search index * fix refs * fix refs * Fix index rst related issues * fix refs * inc to rst * Fix links ref * fix more references * fix refs * deconflict * errors * errors * errors * fix refs * fix refs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix warnings * Fix LightningCLI errors * Fix LightningCLI errors * Fix LightningCLI errors * Fix LightningCLI errors * fix doc build * Duplicate Label fix (docs) (#12800) Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * ignore typing in demo folder * Ignore demos for mypy Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Kushashwa Ravi Shrimali <kushashwaravishrimali@gmail.com> Co-authored-by: Jirka <jirka.borovec@seznam.cz> Co-authored-by: rohitgr7 <rohitgr1998@gmail.com> Co-authored-by: Kaushik B <kaushikbokka@gmail.com> Co-authored-by: otaj <ota@grid.ai>
2022-04-19 18:15:47 +00:00
:orphan:
#######################################
Eliminate config boilerplate (Advanced)
#######################################
**Audience:** Users looking to modularize their code for a professional project.
**Pre-reqs:** You must have read :doc:`(Control it all from the CLI) <lightning_cli_intermediate>`.
----
***************************
What is a yaml config file?
***************************
A yaml is a standard configuration file that describes parameters for sections of a program. It is a common tool in engineering, and it has recently started to gain popularity in machine learning.
.. code:: yaml
# file.yaml
car:
max_speed:100
max_passengers:2
plane:
fuel_capacity: 50
class_3:
option_1: 'x'
option_2: 'y'
----
*********************
Print the config used
*********************
Before or after you run a training routine, you can print the full training spec in yaml format using ``--print_config``:
.. code:: bash
python main.py fit --print_config
which generates the following config:
.. code:: bash
seed_everything: null
trainer:
logger: true
...
terminate_on_nan: null
model:
out_dim: 10
learning_rate: 0.02
data:
data_dir: ./
ckpt_path: null
----
********************************
Write a config yaml from the CLI
********************************
To have a copy of the configuration that produced this model, save a *yaml* file from the *--print_config* outputs:
.. code:: bash
python main.py fit --model.learning_rate 0.001 --print_config > config.yaml
----
**********************
Run from a single yaml
**********************
To run from a yaml, pass a yaml produced with ``--print_config`` to the ``--config`` argument:
.. code:: bash
python main.py fit --config config.yaml
when using a yaml to run, you can still pass in inline arguments
.. code:: bash
python main.py fit --config config.yaml --trainer.max_epochs 100
----
******************
Compose yaml files
******************
For production or complex research projects it's advisable to have each object in its own config file. To compose all the configs, pass them all inline:
.. code-block:: bash
$ python trainer.py fit --config trainer.yaml --config datamodules.yaml --config models.yaml ...
The configs will be parsed sequentially. Let's say we have two configs with the same args:
.. code:: yaml
# trainer.yaml
trainer:
num_epochs: 10
# trainer_2.yaml
trainer:
num_epochs: 20
the ones from the last config will be used (num_epochs = 20) in this case:
.. code-block:: bash
$ python trainer.py fit --config trainer.yaml --config trainer_2.yaml