mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
cleaned docs, fixed argparse generator (#1075)
* Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Test deprecated API for 0.8.0 and 0.9.0 (#1071) * till 0.8 * refactor * fix tests * fix tests * deprx till 0.9 * Update trainer.py * Apply suggestions from code review Co-authored-by: William Falcon <waf2107@columbia.edu> * updated test * updated test * updated test * updated test * updated test * updated test * updated test * updated test * updated test * updated test * updated test * updated test * updated test Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
This commit is contained in:
committed by
J. Borovec
co-authored by
Jirka Borovec
parent
9f140b7698
commit
be89eb07c8
@@ -19,6 +19,10 @@ modify the network. The `Trainer` can add all the available options to an Argume
|
||||
parser.add_argument('--layer_1_dim', type=int, default=128)
|
||||
parser.add_argument('--layer_2_dim', type=int, default=256)
|
||||
parser.add_argument('--batch_size', type=int, default=64)
|
||||
|
||||
# add all the available options to the trainer
|
||||
parser = pl.Trainer.add_argparse_args(parser)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
Now we can parametrize the LightningModule.
|
||||
|
||||
@@ -588,8 +588,12 @@ modify the network. The `Trainer` can add all the available options to an Argume
|
||||
|
||||
# parametrize the network
|
||||
parser.add_argument('--layer_1_dim', type=int, default=128)
|
||||
parser.add_argument('--layer_1_dim', type=int, default=256)
|
||||
parser.add_argument('--layer_2_dim', type=int, default=256)
|
||||
parser.add_argument('--batch_size', type=int, default=64)
|
||||
|
||||
# add all the available options to the trainer
|
||||
parser = pl.Trainer.add_argparse_args(parser)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
Now we can parametrize the LightningModule.
|
||||
|
||||
@@ -75,13 +75,15 @@ class TrainerDeprecatedAPITillVer0_8(ABC):
|
||||
@property
|
||||
def nb_sanity_val_steps(self):
|
||||
"""Back compatibility, will be removed in v0.8.0"""
|
||||
warnings.warn("Attribute `nb_sanity_val_steps` has renamed to `num_sanity_val_steps` since v0.5.0"
|
||||
warnings.warn("Attribute `nb_sanity_val_steps` has renamed to "
|
||||
"`num_sanity_val_steps` since v0.5.0"
|
||||
" and this method will be removed in v0.8.0", DeprecationWarning)
|
||||
return self.num_sanity_val_steps
|
||||
|
||||
@nb_sanity_val_steps.setter
|
||||
def nb_sanity_val_steps(self, nb):
|
||||
"""Back compatibility, will be removed in v0.8.0"""
|
||||
warnings.warn("Attribute `nb_sanity_val_steps` has renamed to `num_sanity_val_steps` since v0.5.0"
|
||||
warnings.warn("Attribute `nb_sanity_val_steps` has renamed to "
|
||||
"`num_sanity_val_steps` since v0.5.0"
|
||||
" and this method will be removed in v0.8.0", DeprecationWarning)
|
||||
self.num_sanity_val_steps = nb
|
||||
|
||||
@@ -293,7 +293,8 @@ class Trainer(
|
||||
self.num_sanity_val_steps = num_sanity_val_steps
|
||||
# Backward compatibility, TODO: remove in v0.8.0
|
||||
if nb_sanity_val_steps is not None:
|
||||
warnings.warn("Argument `nb_sanity_val_steps` has renamed to `num_sanity_val_steps` since v0.5.0"
|
||||
warnings.warn("Argument `nb_sanity_val_steps` has renamed to "
|
||||
"`num_sanity_val_steps` since v0.5.0"
|
||||
" and this method will be removed in v0.8.0", DeprecationWarning)
|
||||
self.nb_sanity_val_steps = nb_sanity_val_steps
|
||||
self.print_nan_grads = print_nan_grads
|
||||
@@ -437,17 +438,32 @@ class Trainer(
|
||||
|
||||
@classmethod
|
||||
def default_attributes(cls):
|
||||
return vars(cls())
|
||||
import inspect
|
||||
|
||||
init_signature = inspect.signature(Trainer)
|
||||
|
||||
args = {}
|
||||
for param_name in init_signature.parameters:
|
||||
value = init_signature.parameters[param_name].default
|
||||
args[param_name] = value
|
||||
|
||||
return args
|
||||
|
||||
@classmethod
|
||||
def add_argparse_args(cls, parent_parser: ArgumentParser) -> ArgumentParser:
|
||||
"""Extend existing argparse by default `Trainer` attributes."""
|
||||
parser = ArgumentParser(parents=[parent_parser])
|
||||
parser = ArgumentParser(parents=[parent_parser], add_help=False)
|
||||
|
||||
trainer_default_params = Trainer.default_attributes()
|
||||
|
||||
# TODO: get "help" from docstring :)
|
||||
for arg in trainer_default_params:
|
||||
parser.add_argument('--{0}'.format(arg), default=trainer_default_params[arg], dest=arg)
|
||||
parser.add_argument(
|
||||
f'--{arg}',
|
||||
default=trainer_default_params[arg],
|
||||
dest=arg,
|
||||
help='autogenerated by pl.Trainer'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
Reference in New Issue
Block a user