-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Remove LoggerConnector.on_trainer_init
#11121
Closed
ananthsub
wants to merge
4
commits into
Lightning-AI:master
from
ananthsub:refactor/rm-logger-connector-trainer-init
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -569,9 +569,9 @@ def __init__( | |
# configure profiler | ||
self.__init_profiler(profiler) | ||
|
||
# init logger flags | ||
# configure logger flags | ||
self.logger: Optional[LightningLoggerBase] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I played a bit with this and this definition needs to be in the |
||
self.logger_connector.on_trainer_init(logger, flush_logs_every_n_steps, log_every_n_steps, move_metrics_to_cpu) | ||
self.__init_logger_flags(logger, flush_logs_every_n_steps, log_every_n_steps, move_metrics_to_cpu) | ||
|
||
# init debugging flags | ||
self._init_debugging_flags( | ||
|
@@ -1632,6 +1632,37 @@ def __setup_profiler(self) -> None: | |
self.profiler._lightning_module = proxy(self.lightning_module) | ||
self.profiler.setup(stage=self.state.fn._setup_fn, local_rank=local_rank, log_dir=self.log_dir) | ||
|
||
def __init_logger_flags( | ||
self, | ||
logger: Union[bool, LightningLoggerBase, Iterable[LightningLoggerBase]], | ||
flush_logs_every_n_steps: Optional[int], | ||
log_every_n_steps: int, | ||
move_metrics_to_cpu: bool, | ||
) -> None: | ||
if flush_logs_every_n_steps is not None: | ||
rank_zero_deprecation( | ||
f"Setting `Trainer(flush_logs_every_n_steps={flush_logs_every_n_steps})` is deprecated in v1.5 " | ||
"and will be removed in v1.7. Please configure flushing in the logger instead." | ||
) | ||
else: | ||
flush_logs_every_n_steps = 100 # original default parameter | ||
|
||
self.flush_logs_every_n_steps = flush_logs_every_n_steps | ||
self.log_every_n_steps = log_every_n_steps | ||
self.move_metrics_to_cpu = move_metrics_to_cpu | ||
|
||
if logger is True: | ||
# default logger | ||
self.logger = TensorBoardLogger( | ||
save_dir=self.default_root_dir, version=SLURMEnvironment.job_id(), name="lightning_logs" | ||
) | ||
elif logger is False: | ||
self.logger = None | ||
elif isinstance(logger, Iterable): | ||
self.logger = LoggerCollection(logger) | ||
else: | ||
self.logger = logger | ||
|
||
def _log_device_info(self) -> None: | ||
rank_zero_info(f"GPU available: {torch.cuda.is_available()}, used: {self._device_type == _AcceleratorType.GPU}") | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #10417 we propose to make the logger owned by the connector. The two methods
on_trainer_init
andconfigure_logger
would then essentially become part of the LoggerConnector init without reference to the trainer. What are your thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would definitely prefer this approach. Right now, the Trainer is starting to become a bigger class and it is getting harder for users to parse it.