mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-12 12:40:20 +08:00
@@ -27,9 +27,9 @@ Argparser Best Practices
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
It is best practice to layer your arguments in three sections.
|
||||
|
||||
1. Trainer args (gpus, num_nodes, etc...)
|
||||
2. Model specific arguments (layer_dim, num_layers, learning_rate, etc...)
|
||||
3. Program arguments (data_path, cluster_email, etc...)
|
||||
1. Trainer args (gpus, num_nodes, etc...)
|
||||
2. Model specific arguments (layer_dim, num_layers, learning_rate, etc...)
|
||||
3. Program arguments (data_path, cluster_email, etc...)
|
||||
|
||||
We can do this as follows. First, in your LightningModule, define the arguments
|
||||
specific to that module. Remember that data splits or data paths may also be specific to
|
||||
@@ -84,15 +84,11 @@ Finally, make sure to start the training like so:
|
||||
|
||||
# YES
|
||||
model = LitModel(hparams)
|
||||
|
||||
# NO
|
||||
# model = LitModel(learning_rate=hparams.learning_rate, ...)
|
||||
|
||||
# YES
|
||||
trainer = Trainer.from_argparse_args(hparams, early_stopping_callback=...)
|
||||
|
||||
# NO
|
||||
trainer = Trainer(gpus=hparams.gpus, ...)
|
||||
# model = LitModel(learning_rate=hparams.learning_rate, ...)
|
||||
#trainer = Trainer(gpus=hparams.gpus, ...)
|
||||
|
||||
|
||||
LightiningModule hparams
|
||||
@@ -144,8 +140,8 @@ Now pass in the params when you init your model
|
||||
The line `self.hparams = hparams` is very special. This line assigns your hparams to the LightningModule.
|
||||
This does two things:
|
||||
|
||||
1. It adds them automatically to tensorboard logs under the hparams tab.
|
||||
2. Lightning will save those hparams to the checkpoint and use them to restore the module correctly.
|
||||
1. It adds them automatically to tensorboard logs under the hparams tab.
|
||||
2. Lightning will save those hparams to the checkpoint and use them to restore the module correctly.
|
||||
|
||||
Trainer args
|
||||
^^^^^^^^^^^^
|
||||
|
||||
Reference in New Issue
Block a user