Skip to content

Commit 1f3fd8f

Browse files
carmoccarohitgr7
authored andcommitted
Add back support for logging in the gradient clipping hooks (#14298)
* Add back support for logging in the gradient clipping hooks * Docs and CHANGELOG * Fix tests
1 parent 654c401 commit 1f3fd8f

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

docs/source-pytorch/visualize/logging_advanced.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ In LightningModule
355355
* - Method
356356
- on_step
357357
- on_epoch
358-
* - on_after_backward, on_before_backward, on_before_optimizer_step, on_before_zero_grad, training_step, training_step_end
358+
* - on_after_backward, on_before_backward, on_before_optimizer_step, optimizer_step, configure_gradient_clipping, on_before_zero_grad, training_step, training_step_end
359359
- True
360360
- False
361361
* - training_epoch_end, test_epoch_end, test_step, test_step_end, validation_epoch_end, validation_step, validation_step_end

src/pytorch_lightning/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66

7-
## [1.7.3] - 2022-08-24
7+
## [1.7.3] - 2022-08-23
88

99
### Fixed
1010

1111
- Fixed an assertion error when using a `ReduceOnPlateau` scheduler with the Horovod strategy ([#14215](https://github.com/Lightning-AI/lightning/pull/14215))
1212
- Fixed an `AttributeError` when accessing `LightningModule.logger` and the Trainer has multiple loggers ([#14234](https://github.com/Lightning-AI/lightning/pull/14234))
1313
- Fixed wrong num padding for `RichProgressBar` ([#14296](https://github.com/Lightning-AI/lightning/pull/14296))
14+
- Added back support for `log`ging in the `configure_gradient_clipping` hook after unintended removal in v1.7.2 ([#14298](https://github.com/Lightning-AI/lightning/issues/14298))
1415

1516

1617
## [1.7.2] - 2022-08-17

src/pytorch_lightning/trainer/connectors/logger_connector/fx_validator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ class _LogOptions(TypedDict):
4444
allowed_on_step=(False, True), allowed_on_epoch=(False, True), default_on_step=True, default_on_epoch=False
4545
),
4646
"lr_scheduler_step": None,
47-
"configure_gradient_clipping": None,
48-
"clip_gradients": None,
47+
# should match `optimizer_step`
48+
"configure_gradient_clipping": _LogOptions(
49+
allowed_on_step=(False, True), allowed_on_epoch=(False, True), default_on_step=True, default_on_epoch=False
50+
),
51+
"clip_gradients": _LogOptions(
52+
allowed_on_step=(False, True), allowed_on_epoch=(False, True), default_on_step=True, default_on_epoch=False
53+
),
4954
"on_before_zero_grad": _LogOptions(
5055
allowed_on_step=(False, True), allowed_on_epoch=(False, True), default_on_step=True, default_on_epoch=False
5156
),

tests/tests_pytorch/trainer/logging_/test_logger_connector.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,7 @@ class HookedModel(BoringModel):
183183
def __init__(self, not_supported):
184184
super().__init__()
185185
pl_module_hooks = get_members(LightningModule)
186-
pl_module_hooks.difference_update(
187-
{
188-
"log",
189-
"log_dict",
190-
}
191-
)
186+
pl_module_hooks.difference_update({"log", "log_dict"})
192187
# remove `nn.Module` hooks
193188
module_hooks = get_members(torch.nn.Module)
194189
pl_module_hooks.difference_update(module_hooks)
@@ -236,8 +231,6 @@ def test_fx_validator_integration(tmpdir):
236231
"on_validation_model_eval": "You can't",
237232
"on_validation_model_train": "You can't",
238233
"lr_scheduler_step": "You can't",
239-
"configure_gradient_clipping": "You can't",
240-
"clip_gradients": "You can't",
241234
"on_save_checkpoint": "You can't",
242235
"on_load_checkpoint": "You can't",
243236
"on_exception": "You can't",

tests/tests_pytorch/trainer/logging_/test_loop_logging.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def _make_assertion(model, hooks, result_mock, on_step, on_epoch, extra_kwargs):
5454
"on_after_backward",
5555
"on_before_optimizer_step",
5656
"optimizer_step",
57+
"configure_gradient_clipping",
58+
"clip_gradients",
5759
"on_before_zero_grad",
5860
"optimizer_zero_grad",
5961
"training_step",

0 commit comments

Comments
 (0)