mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-11 12:31:23 +08:00
Fix typo (#1750)
This commit is contained in:
@@ -11,7 +11,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ammaraskar/sphinx-action@master
|
||||
with:
|
||||
# git is requried to clone the docs theme
|
||||
# git is required to clone the docs theme
|
||||
pre-build-command: "apt-get update -y && apt-get install -y git"
|
||||
docs-folder: "docs/"
|
||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
|
||||
@@ -15,7 +15,7 @@ To reduce the amount of guesswork concerning choosing a good initial learning
|
||||
rate, a `learning rate finder` can be used. As described in this `paper <https://arxiv.org/abs/1506.01186>`_
|
||||
a learning rate finder does a small run where the learning rate is increased
|
||||
after each processed batch and the corresponding loss is logged. The result of
|
||||
this is a `lr` vs. `loss` plot that can be used as guidence for choosing a optimal
|
||||
this is a `lr` vs. `loss` plot that can be used as guidance for choosing a optimal
|
||||
initial lr.
|
||||
|
||||
.. warning:: For the moment, this feature only works with models having a single optimizer.
|
||||
|
||||
@@ -257,7 +257,7 @@ class DQNLightning(pl.LightningModule):
|
||||
def training_step(self, batch: Tuple[torch.Tensor, torch.Tensor], nb_batch) -> OrderedDict:
|
||||
"""
|
||||
Carries out a single step through the environment to update the replay buffer.
|
||||
Then calculates loss based on the minibatch recieved
|
||||
Then calculates loss based on the minibatch received
|
||||
|
||||
Args:
|
||||
batch: current mini batch of replay data
|
||||
|
||||
@@ -875,7 +875,7 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
|
||||
def _init_slurm_connection(self) -> None:
|
||||
"""
|
||||
Sets up environemnt variables necessary for pytorch distributed communications
|
||||
Sets up environment variables necessary for pytorch distributed communications
|
||||
based on slurm environment.
|
||||
"""
|
||||
# use slurm job id for the port number
|
||||
|
||||
@@ -31,7 +31,7 @@ class NeptuneLogger(LightningLoggerBase):
|
||||
pip install neptune-client
|
||||
|
||||
The Neptune logger can be used in the online mode or offline (silent) mode.
|
||||
To log experiment data in online mode, :class:`NeptuneLogger` requries an API key.
|
||||
To log experiment data in online mode, :class:`NeptuneLogger` requires an API key.
|
||||
In offline mode, Neptune will log to a local directory.
|
||||
|
||||
**ONLINE MODE**
|
||||
|
||||
@@ -61,7 +61,7 @@ class TrainerCallbackConfigMixin(ABC):
|
||||
ckpt_path = os.path.join(self.default_root_dir, "checkpoints")
|
||||
|
||||
# when no val step is defined, use 'loss' otherwise 'val_loss'
|
||||
train_step_only = not self.is_overriden('validation_step')
|
||||
train_step_only = not self.is_overridden('validation_step')
|
||||
monitor_key = 'loss' if train_step_only else 'val_loss'
|
||||
|
||||
if self.checkpoint_callback is True:
|
||||
|
||||
@@ -78,7 +78,7 @@ class TrainerDataLoadingMixin(ABC):
|
||||
replace_sampler_ddp: bool
|
||||
|
||||
@abstractmethod
|
||||
def is_overriden(self, *args):
|
||||
def is_overridden(self, *args):
|
||||
"""Warning: this is just empty shell for code implemented in other class."""
|
||||
|
||||
def _percent_range_check(self, name: str) -> None:
|
||||
@@ -251,7 +251,7 @@ class TrainerDataLoadingMixin(ABC):
|
||||
Args:
|
||||
model: The current `LightningModule`
|
||||
"""
|
||||
if self.is_overriden('validation_step'):
|
||||
if self.is_overridden('validation_step'):
|
||||
self.num_val_batches, self.val_dataloaders = \
|
||||
self._reset_eval_dataloader(model, 'val')
|
||||
|
||||
@@ -261,7 +261,7 @@ class TrainerDataLoadingMixin(ABC):
|
||||
Args:
|
||||
model: The current `LightningModule`
|
||||
"""
|
||||
if self.is_overriden('test_step'):
|
||||
if self.is_overridden('test_step'):
|
||||
self.num_test_batches, self.test_dataloaders =\
|
||||
self._reset_eval_dataloader(model, 'test')
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ class TrainerEvaluationLoopMixin(ABC):
|
||||
"""Warning: this is just empty shell for code implemented in other class."""
|
||||
|
||||
@abstractmethod
|
||||
def is_overriden(self, *args):
|
||||
def is_overridden(self, *args):
|
||||
"""Warning: this is just empty shell for code implemented in other class."""
|
||||
|
||||
@abstractmethod
|
||||
@@ -279,13 +279,13 @@ class TrainerEvaluationLoopMixin(ABC):
|
||||
|
||||
# on dp / ddp2 might still want to do something with the batch parts
|
||||
if test_mode:
|
||||
if self.is_overriden('test_step_end'):
|
||||
if self.is_overridden('test_step_end'):
|
||||
model_ref = self.get_model()
|
||||
with self.profiler.profile('test_step_end'):
|
||||
output = model_ref.test_step_end(output)
|
||||
self.on_test_batch_end()
|
||||
else:
|
||||
if self.is_overriden('validation_step_end'):
|
||||
if self.is_overridden('validation_step_end'):
|
||||
model_ref = self.get_model()
|
||||
with self.profiler.profile('validation_step_end'):
|
||||
output = model_ref.validation_step_end(output)
|
||||
@@ -307,23 +307,23 @@ class TrainerEvaluationLoopMixin(ABC):
|
||||
model = model.module
|
||||
|
||||
if test_mode:
|
||||
if self.is_overriden('test_end', model=model):
|
||||
if self.is_overridden('test_end', model=model):
|
||||
# TODO: remove in v1.0.0
|
||||
eval_results = model.test_end(outputs)
|
||||
rank_zero_warn('Method `test_end` was deprecated in v0.7 and will be removed v1.0.'
|
||||
' Use `test_epoch_end` instead.', DeprecationWarning)
|
||||
|
||||
elif self.is_overriden('test_epoch_end', model=model):
|
||||
elif self.is_overridden('test_epoch_end', model=model):
|
||||
eval_results = model.test_epoch_end(outputs)
|
||||
|
||||
else:
|
||||
if self.is_overriden('validation_end', model=model):
|
||||
if self.is_overridden('validation_end', model=model):
|
||||
# TODO: remove in v1.0.0
|
||||
eval_results = model.validation_end(outputs)
|
||||
rank_zero_warn('Method `validation_end` was deprecated in v0.7 and will be removed v1.0.'
|
||||
' Use `validation_epoch_end` instead.', DeprecationWarning)
|
||||
|
||||
elif self.is_overriden('validation_epoch_end', model=model):
|
||||
elif self.is_overridden('validation_epoch_end', model=model):
|
||||
eval_results = model.validation_epoch_end(outputs)
|
||||
|
||||
# enable train mode again
|
||||
@@ -336,7 +336,7 @@ class TrainerEvaluationLoopMixin(ABC):
|
||||
|
||||
def run_evaluation(self, test_mode: bool = False):
|
||||
# when testing make sure user defined a test step
|
||||
if test_mode and not self.is_overriden('test_step'):
|
||||
if test_mode and not self.is_overridden('test_step'):
|
||||
raise MisconfigurationException(
|
||||
"You called `.test()` without defining model's `.test_step()`."
|
||||
" Please define and try again")
|
||||
|
||||
@@ -214,7 +214,7 @@ class _LRFinder(object):
|
||||
|
||||
lr_min: lr to start search from
|
||||
|
||||
lr_max: lr to stop seach
|
||||
lr_max: lr to stop search
|
||||
|
||||
num_training: number of steps to take between lr_min and lr_max
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class TrainerModelHooksMixin(ABC):
|
||||
f_op = getattr(model, f_name, None)
|
||||
return callable(f_op)
|
||||
|
||||
def is_overriden(self, method_name: str, model: LightningModule = None) -> bool:
|
||||
def is_overridden(self, method_name: str, model: LightningModule = None) -> bool:
|
||||
if model is None:
|
||||
model = self.get_model()
|
||||
super_object = LightningModule
|
||||
@@ -30,10 +30,10 @@ class TrainerModelHooksMixin(ABC):
|
||||
# cannot pickle __code__ so cannot verify if PatchDataloader
|
||||
# exists which shows dataloader methods have been overwritten.
|
||||
# so, we hack it by using the string representation
|
||||
is_overriden = instance_attr.patch_loader_code != str(super_attr.__code__)
|
||||
is_overridden = instance_attr.patch_loader_code != str(super_attr.__code__)
|
||||
else:
|
||||
is_overriden = instance_attr.__code__ is not super_attr.__code__
|
||||
return is_overriden
|
||||
is_overridden = instance_attr.__code__ is not super_attr.__code__
|
||||
return is_overridden
|
||||
|
||||
def has_arg(self, f_name, arg_name):
|
||||
model = self.get_model()
|
||||
|
||||
@@ -81,7 +81,7 @@ class TrainerOptimizersMixin(ABC):
|
||||
' * multiple outputs, dictionaries as described with an optional `frequency` key (int)')
|
||||
|
||||
def configure_schedulers(self, schedulers: list):
|
||||
# Convert each scheduler into dict sturcture with relevant information
|
||||
# Convert each scheduler into dict structure with relevant information
|
||||
lr_schedulers = []
|
||||
default_config = {'interval': 'epoch', # default every epoch
|
||||
'frequency': 1, # default every epoch/batch
|
||||
|
||||
@@ -193,7 +193,7 @@ class Trainer(
|
||||
show_progress_bar:
|
||||
.. warning:: .. deprecated:: 0.7.2
|
||||
|
||||
Set `progress_bar_refresh_rate` to postive integer to enable. Will remove 0.9.0.
|
||||
Set `progress_bar_refresh_rate` to positive integer to enable. Will remove 0.9.0.
|
||||
|
||||
progress_bar_refresh_rate: How often to refresh progress bar (in steps). Value ``0`` disables progress bar.
|
||||
Ignored when a custom callback is passed to :paramref:`~Trainer.callbacks`.
|
||||
@@ -893,7 +893,7 @@ class Trainer(
|
||||
return
|
||||
|
||||
# check if we should run validation during training
|
||||
self.disable_validation = not (self.is_overriden('validation_step') and self.val_percent_check > 0) \
|
||||
self.disable_validation = not (self.is_overridden('validation_step') and self.val_percent_check > 0) \
|
||||
and not self.fast_dev_run
|
||||
|
||||
# run tiny validation (if validation defined)
|
||||
@@ -994,45 +994,45 @@ class Trainer(
|
||||
|
||||
"""
|
||||
# Check training_step, train_dataloader, configure_optimizer methods
|
||||
if not self.is_overriden('training_step', model):
|
||||
if not self.is_overridden('training_step', model):
|
||||
raise MisconfigurationException(
|
||||
'No `training_step()` method defined. Lightning `Trainer` expects as minimum a'
|
||||
' `training_step()`, `training_dataloader()` and `configure_optimizers()` to be defined.')
|
||||
|
||||
if not self.is_overriden('train_dataloader', model):
|
||||
if not self.is_overridden('train_dataloader', model):
|
||||
raise MisconfigurationException(
|
||||
'No `train_dataloader()` method defined. Lightning `Trainer` expects as minimum a'
|
||||
' `training_step()`, `training_dataloader()` and `configure_optimizers()` to be defined.')
|
||||
|
||||
if not self.is_overriden('configure_optimizers', model):
|
||||
if not self.is_overridden('configure_optimizers', model):
|
||||
raise MisconfigurationException(
|
||||
'No `configure_optimizers()` method defined. Lightning `Trainer` expects as minimum a'
|
||||
' `training_step()`, `training_dataloader()` and `configure_optimizers()` to be defined.')
|
||||
|
||||
# Check val_dataloader, validation_step and validation_epoch_end
|
||||
if self.is_overriden('val_dataloader', model):
|
||||
if not self.is_overriden('validation_step', model):
|
||||
if self.is_overridden('val_dataloader', model):
|
||||
if not self.is_overridden('validation_step', model):
|
||||
raise MisconfigurationException('You have passed in a `val_dataloader()`'
|
||||
' but have not defined `validation_step()`.')
|
||||
else:
|
||||
if not self.is_overriden('validation_epoch_end', model):
|
||||
if not self.is_overridden('validation_epoch_end', model):
|
||||
rank_zero_warn(
|
||||
'You have defined a `val_dataloader()` and have defined a `validation_step()`,'
|
||||
' you may also want to define `validation_epoch_end()` for accumulating stats.',
|
||||
RuntimeWarning
|
||||
)
|
||||
else:
|
||||
if self.is_overriden('validation_step', model):
|
||||
if self.is_overridden('validation_step', model):
|
||||
raise MisconfigurationException('You have defined `validation_step()`,'
|
||||
' but have not passed in a val_dataloader().')
|
||||
|
||||
# Check test_dataloader, test_step and test_epoch_end
|
||||
if self.is_overriden('test_dataloader', model):
|
||||
if not self.is_overriden('test_step', model):
|
||||
if self.is_overridden('test_dataloader', model):
|
||||
if not self.is_overridden('test_step', model):
|
||||
raise MisconfigurationException('You have passed in a `test_dataloader()`'
|
||||
' but have not defined `test_step()`.')
|
||||
else:
|
||||
if not self.is_overriden('test_epoch_end', model):
|
||||
if not self.is_overridden('test_epoch_end', model):
|
||||
rank_zero_warn(
|
||||
'You have defined a `test_dataloader()` and have defined a `test_step()`, you may also want to'
|
||||
' define `test_epoch_end()` for accumulating stats.', RuntimeWarning
|
||||
@@ -1040,8 +1040,8 @@ class Trainer(
|
||||
|
||||
def check_testing_model_configuration(self, model: LightningModule):
|
||||
|
||||
has_test_step = self.is_overriden('test_step', model)
|
||||
has_test_epoch_end = self.is_overriden('test_epoch_end', model)
|
||||
has_test_step = self.is_overridden('test_step', model)
|
||||
has_test_epoch_end = self.is_overridden('test_epoch_end', model)
|
||||
gave_test_loader = hasattr(model, 'test_dataloader') and model.test_dataloader()
|
||||
|
||||
if gave_test_loader and not has_test_step:
|
||||
|
||||
@@ -271,7 +271,7 @@ class TrainerTrainLoopMixin(ABC):
|
||||
"""Warning: this is just empty shell for code implemented in other class."""
|
||||
|
||||
@abstractmethod
|
||||
def is_overriden(self, *args):
|
||||
def is_overridden(self, *args):
|
||||
"""Warning: this is just empty shell for code implemented in other class."""
|
||||
|
||||
@abstractmethod
|
||||
@@ -419,9 +419,9 @@ class TrainerTrainLoopMixin(ABC):
|
||||
_outputs = self.run_training_batch(batch, batch_idx)
|
||||
batch_result, grad_norm_dic, batch_step_metrics, batch_output = _outputs
|
||||
|
||||
# only track outputs when user implementes training_epoch_end
|
||||
# otherwise we will build up unecessary memory
|
||||
if self.is_overriden('training_epoch_end', model=self.get_model()):
|
||||
# only track outputs when user implements training_epoch_end
|
||||
# otherwise we will build up unnecessary memory
|
||||
if self.is_overridden('training_epoch_end', model=self.get_model()):
|
||||
outputs.append(batch_output)
|
||||
|
||||
# when returning -1 from train_step, we end epoch early
|
||||
@@ -484,7 +484,7 @@ class TrainerTrainLoopMixin(ABC):
|
||||
|
||||
# process epoch outputs
|
||||
model = self.get_model()
|
||||
if self.is_overriden('training_epoch_end', model=model):
|
||||
if self.is_overridden('training_epoch_end', model=model):
|
||||
epoch_output = model.training_epoch_end(outputs)
|
||||
_processed_outputs = self.process_output(epoch_output)
|
||||
log_epoch_metrics = _processed_outputs[2]
|
||||
@@ -493,7 +493,7 @@ class TrainerTrainLoopMixin(ABC):
|
||||
self.callback_metrics.update(callback_epoch_metrics)
|
||||
|
||||
# when no val loop is present or fast-dev-run still need to call checkpoints
|
||||
if not self.is_overriden('validation_step') and not (self.fast_dev_run or should_check_val):
|
||||
if not self.is_overridden('validation_step') and not (self.fast_dev_run or should_check_val):
|
||||
self.call_checkpoint_callback()
|
||||
self.call_early_stop_callback()
|
||||
|
||||
@@ -539,7 +539,7 @@ class TrainerTrainLoopMixin(ABC):
|
||||
self.split_idx = split_idx
|
||||
|
||||
for opt_idx, optimizer in self._get_optimizers_iterable():
|
||||
# make sure only the gradients of the current optimizer's paramaters are calculated
|
||||
# make sure only the gradients of the current optimizer's parameters are calculated
|
||||
# in the training step to prevent dangling gradients in multiple-optimizer setup.
|
||||
if len(self.optimizers) > 1:
|
||||
for param in self.get_model().parameters():
|
||||
@@ -737,14 +737,14 @@ class TrainerTrainLoopMixin(ABC):
|
||||
|
||||
# allow any mode to define training_step_end
|
||||
# do something will all the dp outputs (like softmax)
|
||||
if self.is_overriden('training_step_end'):
|
||||
if self.is_overridden('training_step_end'):
|
||||
model_ref = self.get_model()
|
||||
with self.profiler.profile('training_step_end'):
|
||||
output = model_ref.training_step_end(output)
|
||||
|
||||
# allow any mode to define training_end
|
||||
# TODO: remove in 1.0.0
|
||||
if self.is_overriden('training_end'):
|
||||
if self.is_overridden('training_end'):
|
||||
model_ref = self.get_model()
|
||||
with self.profiler.profile('training_end'):
|
||||
output = model_ref.training_end(output)
|
||||
|
||||
@@ -32,7 +32,7 @@ def load_requirements(path_dir=PATH_ROOT, comment_char='#'):
|
||||
return reqs
|
||||
|
||||
|
||||
def load_long_describtion():
|
||||
def load_long_description():
|
||||
# https://github.com/PyTorchLightning/pytorch-lightning/raw/master/docs/source/_images/lightning_module/pt_to_pl.png
|
||||
url = os.path.join(pytorch_lightning.__homepage__, 'raw', pytorch_lightning.__version__, 'docs')
|
||||
text = open('README.md', encoding='utf-8').read()
|
||||
@@ -59,7 +59,7 @@ setup(
|
||||
license=pytorch_lightning.__license__,
|
||||
packages=find_packages(exclude=['tests', 'tests/*', 'benchmarks']),
|
||||
|
||||
long_description=load_long_describtion(),
|
||||
long_description=load_long_description(),
|
||||
long_description_content_type='text/markdown',
|
||||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
|
||||
@@ -273,13 +273,13 @@ def test_parse_gpu_fail_on_unsupported_inputs(mocked_device_count, gpus):
|
||||
|
||||
@pytest.mark.gpus_param_tests
|
||||
@pytest.mark.parametrize("gpus", [[1, 2, 19], -1, '-1'])
|
||||
def test_parse_gpu_fail_on_non_existant_id(mocked_device_count_0, gpus):
|
||||
def test_parse_gpu_fail_on_non_existent_id(mocked_device_count_0, gpus):
|
||||
with pytest.raises(MisconfigurationException):
|
||||
parse_gpu_ids(gpus)
|
||||
|
||||
|
||||
@pytest.mark.gpus_param_tests
|
||||
def test_parse_gpu_fail_on_non_existant_id_2(mocked_device_count):
|
||||
def test_parse_gpu_fail_on_non_existent_id_2(mocked_device_count):
|
||||
with pytest.raises(MisconfigurationException):
|
||||
parse_gpu_ids([1, 2, 19])
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@ def test_wrong_configure_optimizers(tmpdir):
|
||||
|
||||
def test_wrong_validation_settings(tmpdir):
|
||||
""" Test the following cases related to validation configuration of model:
|
||||
* error if `val_dataloader()` is overriden but `validation_step()` is not
|
||||
* if both `val_dataloader()` and `validation_step()` is overriden,
|
||||
* error if `val_dataloader()` is overridden but `validation_step()` is not
|
||||
* if both `val_dataloader()` and `validation_step()` is overridden,
|
||||
throw warning if `val_epoch_end()` is not defined
|
||||
* error if `validation_step()` is overriden but `val_dataloader()` is not
|
||||
* error if `validation_step()` is overridden but `val_dataloader()` is not
|
||||
"""
|
||||
tutils.reset_seed()
|
||||
hparams = tutils.get_default_hparams()
|
||||
@@ -71,10 +71,10 @@ def test_wrong_validation_settings(tmpdir):
|
||||
|
||||
def test_wrong_test_settigs(tmpdir):
|
||||
""" Test the following cases related to test configuration of model:
|
||||
* error if `test_dataloader()` is overriden but `test_step()` is not
|
||||
* if both `test_dataloader()` and `test_step()` is overriden,
|
||||
* error if `test_dataloader()` is overridden but `test_step()` is not
|
||||
* if both `test_dataloader()` and `test_step()` is overridden,
|
||||
throw warning if `test_epoch_end()` is not defined
|
||||
* error if `test_step()` is overriden but `test_dataloader()` is not
|
||||
* error if `test_step()` is overridden but `test_dataloader()` is not
|
||||
"""
|
||||
hparams = tutils.get_default_hparams()
|
||||
trainer = Trainer(default_root_dir=tmpdir, max_epochs=1)
|
||||
|
||||
Reference in New Issue
Block a user