From 4ac85aac385875cc690ff74782c3024a4777f9ac Mon Sep 17 00:00:00 2001 From: ProgramadorArtificial Date: Tue, 24 Sep 2024 17:31:30 -0300 Subject: [PATCH 1/2] Fix Argument 1 to "join" has incompatible type "Optional[str]"; expected "Union[str, _PathLike[str]]" --- mmengine/utils/package_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mmengine/utils/package_utils.py b/mmengine/utils/package_utils.py index b224625f13..f854272334 100644 --- a/mmengine/utils/package_utils.py +++ b/mmengine/utils/package_utils.py @@ -69,11 +69,12 @@ def get_installed_path(package: str) -> str: else: raise e - possible_path = osp.join(pkg.location, package) + location = '' if pkg.location is None else pkg.location + possible_path = osp.join(location, package) if osp.exists(possible_path): return possible_path else: - return osp.join(pkg.location, package2module(package)) + return osp.join(location, package2module(package)) def package2module(package: str): From c59fe6a0ec57422d2069762ecb1ae3489a1944ea Mon Sep 17 00:00:00 2001 From: ProgramadorArtificial Date: Tue, 24 Sep 2024 17:30:09 -0300 Subject: [PATCH 2/2] Add param to indicate if the model was saved as float16 and to load as half if True --- mmengine/infer/infer.py | 3 +++ mmengine/runner/_flexible_runner.py | 1 + mmengine/runner/runner.py | 1 + 3 files changed, 5 insertions(+) diff --git a/mmengine/infer/infer.py b/mmengine/infer/infer.py index 322d885224..61a6b31e8c 100644 --- a/mmengine/infer/infer.py +++ b/mmengine/infer/infer.py @@ -484,6 +484,9 @@ def _init_model( model.cfg = cfg self._load_weights_to_model(model, checkpoint, cfg) model.to(device) + if 'cuda' in device and checkpoint is not None and checkpoint.get( + 'meta', {}).get('float16', False): + model.half() model.eval() return model diff --git a/mmengine/runner/_flexible_runner.py b/mmengine/runner/_flexible_runner.py index 6d727fb4d5..b588179c99 100644 --- a/mmengine/runner/_flexible_runner.py +++ b/mmengine/runner/_flexible_runner.py @@ -1571,6 +1571,7 @@ def save_checkpoint( elif not isinstance(meta, dict): raise TypeError( f'meta should be a dict or None, but got {type(meta)}') + meta['float16'] = False if by_epoch: # self.epoch increments 1 after diff --git a/mmengine/runner/runner.py b/mmengine/runner/runner.py index 68716ab253..b5fd7f33a6 100644 --- a/mmengine/runner/runner.py +++ b/mmengine/runner/runner.py @@ -2184,6 +2184,7 @@ def save_checkpoint( elif not isinstance(meta, dict): raise TypeError( f'meta should be a dict or None, but got {type(meta)}') + meta['float16'] = False if by_epoch: # self.epoch increments 1 after