Skip to content
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

Merged
merged 4 commits into from Dec 12, 2022

Conversation

xiexinch
Copy link
Contributor

@xiexinch xiexinch commented Dec 6, 2022

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 of MMLogger.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.

@@ -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()
Copy link
Collaborator

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.

zhouzaida
zhouzaida previously approved these changes Dec 6, 2022
@zhouzaida zhouzaida added the WIP label Dec 6, 2022
@zhouzaida zhouzaida marked this pull request as draft December 6, 2022 08:22
@xiexinch xiexinch marked this pull request as ready for review December 7, 2022 04:44
HAOCHENYE
HAOCHENYE previously approved these changes Dec 7, 2022
Copy link
Collaborator

@HAOCHENYE HAOCHENYE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved!!!
image

MengzhangLI
MengzhangLI previously approved these changes Dec 7, 2022
Comment on lines 110 to 113
elif logger is not None:
logger.warning(err_msg)
else:
print(err_msg)
print_log(err_msg, logger='current', level=logging.WARNING)
Copy link
Member

@zhouzaida zhouzaida Dec 11, 2022

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)

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
load_state_dict(module, state_dict, strict=False)
load_state_dict(module, state_dict, strict=False, logger='current')

load_checkpoint(
module,
self.checkpoint,
map_location=self.map_location,
strict=False,
logger=logger)
strict=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
strict=False)
strict=False,
logger='current')

@xiexinch xiexinch dismissed stale reviews from MengzhangLI and HAOCHENYE via b267a16 December 12, 2022 03:19
@zhouzaida zhouzaida removed the WIP label Dec 12, 2022
@zhouzaida zhouzaida merged commit 504fdc3 into open-mmlab:main Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants