Skip to content

Commit aede826

Browse files
committed
[Lint] Fix lint
1 parent fb74214 commit aede826

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

mmengine/optim/optimizer/builder.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
22
import copy
33
import inspect
4+
import warnings
45
from typing import List, Union
56

67
import torch
@@ -115,7 +116,7 @@ def register_sophia_optimizers() -> List[str]:
115116
Returns:
116117
List[str]: A list of registered optimizers' name.
117118
"""
118-
optimizers = []
119+
optimizers = [] # type: ignore
119120
try:
120121
import Sophia
121122
except ImportError:
@@ -128,7 +129,7 @@ def register_sophia_optimizers() -> List[str]:
128129
try:
129130
OPTIMIZERS.register_module(module=_optim)
130131
except Exception as e:
131-
warnings.warn(f"Failed to import {optim_cls.__name__} for {e}")
132+
warnings.warn(f'Failed to import {Sophia} for {e}')
132133
return optimizers
133134

134135

@@ -161,7 +162,7 @@ def register_bitsandbytes_optimizers() -> List[str]:
161162
try:
162163
OPTIMIZERS.register_module(module=optim_cls, name=name)
163164
except Exception as e:
164-
warnings.warn(f"Failed to import {optim_cls.__name__} for {e}")
165+
warnings.warn(f'Failed to import {optim_cls.__name__} for {e}')
165166
dadaptation_optimizers.append(name)
166167
return dadaptation_optimizers
167168

@@ -179,7 +180,7 @@ def register_transformers_optimizers():
179180
try:
180181
OPTIMIZERS.register_module(name='Adafactor', module=Adafactor)
181182
except Exception as e:
182-
warnings.warn(f"Failed to import {optim_cls.__name__} for {e}")
183+
warnings.warn(f'Failed to import Adafactor for {e}')
183184
transformer_optimizers.append('Adafactor')
184185
return transformer_optimizers
185186

mmengine/runner/checkpoint.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ def load_from_local(filename, map_location):
344344
filename = osp.expanduser(filename)
345345
if not osp.isfile(filename):
346346
raise FileNotFoundError(f'{filename} can not be found.')
347-
checkpoint = torch.load(filename, map_location=map_location, weights_only=False)
347+
checkpoint = torch.load(
348+
filename, map_location=map_location, weights_only=False)
348349
return checkpoint
349350

350351

@@ -412,7 +413,8 @@ def load_from_pavi(filename, map_location=None):
412413
with TemporaryDirectory() as tmp_dir:
413414
downloaded_file = osp.join(tmp_dir, model.name)
414415
model.download(downloaded_file)
415-
checkpoint = torch.load(downloaded_file, map_location=map_location, weights_only=False)
416+
checkpoint = torch.load(
417+
downloaded_file, map_location=map_location, weights_only=False)
416418
return checkpoint
417419

418420

@@ -435,7 +437,8 @@ def load_from_ceph(filename, map_location=None, backend='petrel'):
435437
file_backend = get_file_backend(
436438
filename, backend_args={'backend': backend})
437439
with io.BytesIO(file_backend.get(filename)) as buffer:
438-
checkpoint = torch.load(buffer, map_location=map_location, weights_only=False)
440+
checkpoint = torch.load(
441+
buffer, map_location=map_location, weights_only=False)
439442
return checkpoint
440443

441444

@@ -504,7 +507,8 @@ def load_from_openmmlab(filename, map_location=None):
504507
filename = osp.join(_get_mmengine_home(), model_url)
505508
if not osp.isfile(filename):
506509
raise FileNotFoundError(f'{filename} can not be found.')
507-
checkpoint = torch.load(filename, map_location=map_location, weights_only=False)
510+
checkpoint = torch.load(
511+
filename, map_location=map_location, weights_only=False)
508512
return checkpoint
509513

510514

mmengine/utils/package_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def is_installed(package: str) -> bool:
1414
# Therefore, import it in function scope to save time.
1515
import importlib.util
1616

17-
import pkg_resources
17+
import pkg_resources # type: ignore
1818
from pkg_resources import get_distribution
1919

2020
# refresh the pkg_resources

tests/test_utils/test_package_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os.path as osp
33
import sys
44

5-
import pkg_resources
5+
import pkg_resources # type: ignore
66
import pytest
77

88
from mmengine.utils import get_installed_path, is_installed

0 commit comments

Comments
 (0)