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
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions mmengine/model/weight_init.py
Expand Up @@ -8,7 +8,7 @@
import torch.nn as nn
from torch import Tensor

from mmengine.logging import MMLogger, print_log
from mmengine.logging import print_log
from mmengine.registry import WEIGHT_INITIALIZERS, build_from_cfg


Expand Down Expand Up @@ -481,22 +481,21 @@ def __call__(self, module):
from mmengine.runner.checkpoint import (_load_checkpoint_with_prefix,
load_checkpoint,
load_state_dict)
logger = MMLogger.get_instance('mmengine')
if self.prefix is None:
print_log(f'load model from: {self.checkpoint}', logger=logger)
print_log(f'load model from: {self.checkpoint}', logger='current')
load_checkpoint(
module,
self.checkpoint,
map_location=self.map_location,
strict=False,
logger=logger)
logger='current')
else:
print_log(
f'load {self.prefix} in model from: {self.checkpoint}',
logger=logger)
logger='current')
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, logger='current')

if hasattr(module, '_params_init_info'):
update_init_info(module, init_info=self._get_init_info())
Expand Down