-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Create loggers property for Trainer and LightningModule #11683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
awaelchli
merged 63 commits into
Lightning-AI:master
from
akashkw:refactor/create-loggers-property
Feb 9, 2022
Merged
Changes from 57 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
2883fb2
Implement logger property, replace self.logger
akashkw 3ae0a6e
Fix small bugs
akashkw 6d917a4
Fixed initalization bug
akashkw 30d3a57
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 62c9335
Fix for case where creating a LoggerCollection of size 1
akashkw 99a4d98
Better fix for the LoggerCollection of size 1 issue
akashkw 01287ba
Change trainer.loggers from a property to an instance variable
akashkw 41cbab0
Revert all instances of trainer.loggers being used
akashkw d78d98f
Use logger param to initialize trainer.loggers
akashkw 7f809ff
Remove unneeded newlines
akashkw 179f3d4
Implement unit test for loggers property
akashkw 1ad542a
make trainer.loggers by default an empty list
akashkw c5df0ad
Update changelog
akashkw 9d564d8
fix unit test according to suggestions
akashkw 9d7c1bf
Update CHANGELOG.md
akashkw d263659
Remove unnecessary Trainer params
akashkw befad11
Remove tmpdir parameter for unit test
akashkw 4773c26
Write setters for logger and loggers
akashkw 8871c36
Unit test for setters
akashkw 65ae649
Fix bug where logger setter is called twice
akashkw df992de
Fix initialization bug with trainer test
akashkw 5e47ef4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d55f626
Get rid of extra DummyLogger assignment
akashkw 3debee7
Merge branch 'refactor/create-loggers-property' of github.com:akashkw…
akashkw 29778b1
flake and mypy fixes
akashkw 506e5fd
Flake fix did not commit properly
akashkw 144169b
Small changes based on suggestions
akashkw bdcbcfb
Shorten setters and update unit test
akashkw d42ce90
Move unit test to a new file
akashkw 4001efc
flake and mypy fixes
akashkw 9401fb7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e2be787
Refactor setter to handle special case of size 1 LoggerCollection
akashkw 1e71c40
Remove DummyLogger changes
akashkw 4418f10
Merge branch 'master' into refactor/create-loggers-property
akashkw c96534b
Commit suggestion to change None to []
akashkw 6a6e2ef
Merge branch 'master' into refactor/create-loggers-property
akashkw 7fef6fd
Decouple both setters for readability
akashkw f2a598f
Fix merge conflicts
akashkw a669a98
Fix tiny bug in trainer.loggers setter
akashkw b6d6fba
Merge branch 'master' into refactor/create-loggers-property
akashkw 8714857
Add loggers property to lightning.py
akashkw a7a47f1
update changelog
akashkw 15fa585
Add logger property to docs
akashkw 3f195be
Fix typo
akashkw c944f9a
update trainer.rst
akashkw e3312d5
correct spacing
akashkw 88b3c24
remove typing for now
akashkw 89f5037
Merge branch 'master' into refactor/create-loggers-property
akashkw 85256e7
Fix jit unused issue
akashkw 7ab3683
Fix underlines in docs
akashkw c51f336
Updates based on suggestions
akashkw ec99acd
More updates to docs based on suggestions
akashkw ba09e27
Create unit test for lightningmodule loggers property
akashkw bc6fd72
Replace Mock with Trainer
akashkw f5b492d
Update types
akashkw 8800ec8
Remove list cast
akashkw 5852ee2
Remove unit test for unsupported behavior
akashkw 0752fb5
Handle special case for setter
akashkw 46b5ae1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3480c38
Update docs/source/common/lightning_module.rst
akashkw cd90c34
Refactor docs and trainer according to suggestions
akashkw cd43e25
Resolve merge conflicts
akashkw 338ba43
Update unit tests with new behavior
akashkw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright The PyTorch Lightning team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from pytorch_lightning import Trainer | ||
from pytorch_lightning.loggers import LoggerCollection, TensorBoardLogger | ||
from tests.loggers.test_base import CustomLogger | ||
|
||
|
||
def test_trainer_loggers_property(): | ||
"""Test for correct initialization of loggers in Trainer.""" | ||
logger1 = CustomLogger() | ||
logger2 = CustomLogger() | ||
|
||
# trainer.loggers should be a copy of the input list | ||
trainer = Trainer(logger=[logger1, logger2]) | ||
|
||
assert trainer.loggers == [logger1, logger2] | ||
|
||
# trainer.loggers should create a list of size 1 | ||
trainer = Trainer(logger=logger1) | ||
|
||
assert trainer.loggers == [logger1] | ||
|
||
# trainer.loggers should be an empty list | ||
trainer = Trainer(logger=False) | ||
|
||
assert trainer.loggers == [] | ||
|
||
# trainer.loggers should be a list of size 1 holding the default logger | ||
trainer = Trainer(logger=True) | ||
|
||
assert trainer.loggers == [trainer.logger] | ||
assert type(trainer.loggers[0]) == TensorBoardLogger | ||
|
||
|
||
def test_trainer_loggers_setters(): | ||
"""Test the behavior of setters for trainer.logger and trainer.loggers.""" | ||
logger1 = CustomLogger() | ||
logger2 = CustomLogger() | ||
logger_collection = LoggerCollection([logger1, logger2]) | ||
|
||
trainer = Trainer() | ||
assert type(trainer.logger) == TensorBoardLogger | ||
assert trainer.loggers == [trainer.logger] | ||
|
||
# Test setters for trainer.logger | ||
trainer.logger = logger1 | ||
assert trainer.logger == logger1 | ||
assert trainer.loggers == [logger1] | ||
|
||
trainer.logger = logger_collection | ||
assert trainer.logger._logger_iterable == logger_collection._logger_iterable | ||
assert trainer.loggers == [logger1, logger2] | ||
|
||
trainer.logger = None | ||
assert trainer.logger is None | ||
assert trainer.loggers == [] | ||
|
||
# Test setters for trainer.loggers | ||
trainer.loggers = [logger1, logger2] | ||
assert trainer.loggers == [logger1, logger2] | ||
assert trainer.logger._logger_iterable == logger_collection._logger_iterable | ||
|
||
trainer.loggers = [logger1] | ||
assert trainer.loggers == [logger1] | ||
assert trainer.logger == logger1 | ||
|
||
trainer.loggers = [] | ||
assert trainer.loggers == [] | ||
assert trainer.logger is None | ||
|
||
trainer.loggers = None | ||
assert trainer.loggers == [] | ||
assert trainer.logger is None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.