-
Notifications
You must be signed in to change notification settings - Fork 363
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
[Fix] Fix creating a new logger at PretrainedInit #791
Conversation
mmengine/model/weight_init.py
Outdated
@@ -481,7 +481,7 @@ def __call__(self, module): | |||
from mmengine.runner.checkpoint import (_load_checkpoint_with_prefix, | |||
load_checkpoint, | |||
load_state_dict) | |||
logger = MMLogger.get_instance('mmengine') | |||
logger = MMLogger.get_current_instance() |
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.
We can directly call print_log(xxx, logger='current') here, and do not need to get the current logger here.
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.
mmengine/runner/checkpoint.py
Outdated
elif logger is not None: | ||
logger.warning(err_msg) | ||
else: | ||
print(err_msg) | ||
print_log(err_msg, logger='current', level=logging.WARNING) |
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.
elif logger is not None:
logger.warning(err_msg)
else:
print_log(err_msg, logger='current', level=logging.WARNING)
->
else:
print_log(err_msg, logger=logger, level=logging.WARNING)
mmengine/model/weight_init.py
Outdated
state_dict = _load_checkpoint_with_prefix( | ||
self.prefix, self.checkpoint, map_location=self.map_location) | ||
load_state_dict(module, state_dict, strict=False, logger=logger) | ||
load_state_dict(module, state_dict, strict=False) |
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.
load_state_dict(module, state_dict, strict=False) | |
load_state_dict(module, state_dict, strict=False, logger='current') |
mmengine/model/weight_init.py
Outdated
load_checkpoint( | ||
module, | ||
self.checkpoint, | ||
map_location=self.map_location, | ||
strict=False, | ||
logger=logger) | ||
strict=False) |
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.
strict=False) | |
strict=False, | |
logger='current') |
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
When training with a pre-trained model, MMEngine will create a new logger.
Modification
Use
MMLogger.get_current_instance()
instead ofMMLogger.get_instance('mmengine')
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.