Skip to content

Commit 02233fb

Browse files
committed
Revert "Unify the logger usage (#1581)"
This reverts commit f50baf2.
1 parent f50baf2 commit 02233fb

File tree

26 files changed

+111
-95
lines changed

26 files changed

+111
-95
lines changed

.azure-pipelines/scripts/ut/3x/collect_log_3x.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source /neural-compressor/.azure-pipelines/scripts/change_color.sh
22

3-
set -e
3+
set -xe
44
pip install coverage
55
export COVERAGE_RCFILE=/neural-compressor/.azure-pipelines/scripts/ut/3x/coverage.${1}
66
coverage_log="/neural-compressor/log_dir/coverage_log"

neural_compressor/common/__init__.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,38 @@
1313
# limitations under the License.
1414

1515
from neural_compressor.common.utils import (
16+
level,
1617
log,
1718
info,
19+
DEBUG,
1820
debug,
21+
warn,
1922
warning,
2023
error,
2124
fatal,
22-
level,
23-
logger,
24-
Logger,
2525
set_random_seed,
2626
set_workspace,
2727
set_resume_from,
2828
set_tensorboard,
29+
Logger,
30+
logger,
2931
)
3032
from neural_compressor.common.base_config import options
3133

3234

3335
__all__ = [
34-
"debug",
35-
"error",
36-
"fatal",
37-
"info",
3836
"level",
39-
"logger",
4037
"log",
38+
"info",
39+
"DEBUG",
40+
"debug",
41+
"warn",
4142
"warning",
42-
"Logger",
43+
"error",
44+
"fatal",
4345
"options",
46+
"Logger",
47+
"logger",
4448
"set_workspace",
4549
"set_random_seed",
4650
"set_resume_from",

neural_compressor/common/base_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from itertools import product
2525
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
2626

27-
from neural_compressor.common import logger
27+
from neural_compressor.common import Logger
2828
from neural_compressor.common.utils import (
2929
BASE_CONFIG,
3030
COMPOSABLE_CONFIG,
@@ -36,6 +36,8 @@
3636
OP_NAME_OR_MODULE_TYPE,
3737
)
3838

39+
logger = Logger().get_logger()
40+
3941
__all__ = [
4042
"options",
4143
"register_config",

neural_compressor/common/base_tuning.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
import uuid
1919
from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, Union
2020

21-
from neural_compressor.common import logger
21+
from neural_compressor.common import Logger
2222
from neural_compressor.common.base_config import BaseConfig, ComposableConfig
2323

24+
logger = Logger().get_logger()
25+
2426
__all__ = [
2527
"Evaluator",
2628
"TuningConfig",

neural_compressor/common/utils/logger.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@
1919
import logging
2020
import os
2121

22-
__all__ = [
23-
"debug",
24-
"error",
25-
"fatal",
26-
"info",
27-
"level",
28-
"logger",
29-
"log",
30-
"warning",
31-
"Logger",
32-
]
33-
3422

3523
class Logger(object):
3624
"""Logger class."""
@@ -79,60 +67,68 @@ def _pretty_dict(value, indent=0):
7967
return repr(value)
8068

8169

70+
level = Logger().get_logger().level
71+
DEBUG = logging.DEBUG
72+
73+
8274
def log(level, msg, *args, **kwargs):
8375
"""Output log with the level as a parameter."""
8476
if isinstance(msg, dict):
8577
for _, line in enumerate(_pretty_dict(msg).split("\n")):
86-
Logger().get_logger().log(level, line, *args, **kwargs, stacklevel=2)
78+
Logger().get_logger().log(level, line, *args, **kwargs)
8779
else:
88-
Logger().get_logger().log(level, msg, *args, **kwargs, stacklevel=2)
80+
Logger().get_logger().log(level, msg, *args, **kwargs)
8981

9082

9183
def debug(msg, *args, **kwargs):
9284
"""Output log with the debug level."""
9385
if isinstance(msg, dict):
9486
for _, line in enumerate(_pretty_dict(msg).split("\n")):
95-
Logger().get_logger().debug(line, *args, **kwargs, stacklevel=2)
87+
Logger().get_logger().debug(line, *args, **kwargs)
9688
else:
97-
Logger().get_logger().debug(msg, *args, **kwargs, stacklevel=2)
89+
Logger().get_logger().debug(msg, *args, **kwargs)
9890

9991

10092
def error(msg, *args, **kwargs):
10193
"""Output log with the error level."""
10294
if isinstance(msg, dict):
10395
for _, line in enumerate(_pretty_dict(msg).split("\n")):
104-
Logger().get_logger().error(line, *args, **kwargs, stacklevel=2)
96+
Logger().get_logger().error(line, *args, **kwargs)
10597
else:
106-
Logger().get_logger().error(msg, *args, **kwargs, stacklevel=2)
98+
Logger().get_logger().error(msg, *args, **kwargs)
10799

108100

109101
def fatal(msg, *args, **kwargs):
110102
"""Output log with the fatal level."""
111103
if isinstance(msg, dict):
112104
for _, line in enumerate(_pretty_dict(msg).split("\n")):
113-
Logger().get_logger().fatal(line, *args, **kwargs, stacklevel=2)
105+
Logger().get_logger().fatal(line, *args, **kwargs)
114106
else:
115-
Logger().get_logger().fatal(msg, *args, **kwargs, stacklevel=2)
107+
Logger().get_logger().fatal(msg, *args, **kwargs)
116108

117109

118110
def info(msg, *args, **kwargs):
119111
"""Output log with the info level."""
120112
if isinstance(msg, dict):
121113
for _, line in enumerate(_pretty_dict(msg).split("\n")):
122-
Logger().get_logger().info(line, *args, **kwargs, stacklevel=2)
114+
Logger().get_logger().info(line, *args, **kwargs)
123115
else:
124-
Logger().get_logger().info(msg, *args, **kwargs, stacklevel=2)
116+
Logger().get_logger().info(msg, *args, **kwargs)
125117

126118

127-
def warning(msg, *args, **kwargs):
128-
"""Output log with the warning level (Alias of the method warn)."""
119+
def warn(msg, *args, **kwargs):
120+
"""Output log with the warning level."""
129121
if isinstance(msg, dict):
130122
for _, line in enumerate(_pretty_dict(msg).split("\n")):
131-
Logger().get_logger().warning(line, *args, **kwargs, stacklevel=2)
123+
Logger().get_logger().warning(line, *args, **kwargs)
132124
else:
133-
Logger().get_logger().warning(msg, *args, **kwargs, stacklevel=2)
125+
Logger().get_logger().warning(msg, *args, **kwargs)
134126

135127

136-
level = Logger().get_logger().level
137-
138-
logger = Logger().get_logger()
128+
def warning(msg, *args, **kwargs):
129+
"""Output log with the warning level (Alias of the method warn)."""
130+
if isinstance(msg, dict):
131+
for _, line in enumerate(_pretty_dict(msg).split("\n")):
132+
Logger().get_logger().warning(line, *args, **kwargs)
133+
else:
134+
Logger().get_logger().warning(msg, *args, **kwargs)

neural_compressor/onnxrt/algorithms/weight_only/algo_entry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import onnx
2020

21-
from neural_compressor.common import logger
21+
from neural_compressor.common import Logger
2222
from neural_compressor.common.utils import RTN
2323
from neural_compressor.onnxrt.quantization.config import RTNConfig
2424
from neural_compressor.onnxrt.utils.utility import register_algo
2525

26+
logger = Logger().get_logger()
27+
2628

2729
###################### RTN Algo Entry ##################################
2830
@register_algo(name=RTN)

neural_compressor/onnxrt/quantization/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323

2424
import onnx
2525

26-
from neural_compressor.common import logger
26+
from neural_compressor.common import Logger
2727
from neural_compressor.common.base_config import BaseConfig, register_config, register_supported_configs_for_fwk
2828
from neural_compressor.common.utils import DEFAULT_WHITE_LIST, OP_NAME_OR_MODULE_TYPE, RTN
2929

30+
logger = Logger().get_logger()
31+
3032
FRAMEWORK_NAME = "onnxrt"
3133

3234

neural_compressor/onnxrt/quantization/quantize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import onnx
1919
from onnxruntime.quantization import CalibrationDataReader
2020

21-
from neural_compressor.common import logger
21+
from neural_compressor.common import Logger
2222
from neural_compressor.common.base_config import BaseConfig, ComposableConfig, config_registry
2323
from neural_compressor.onnxrt.quantization.config import FRAMEWORK_NAME
2424
from neural_compressor.onnxrt.utils.utility import algos_mapping
2525

26+
logger = Logger().get_logger()
27+
2628

2729
def need_apply(quant_config: BaseConfig, algo_name):
2830
return quant_config.name == algo_name if hasattr(quant_config, "name") else False

neural_compressor/onnxrt/utils/onnx_model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
import onnx
2424

25-
from neural_compressor.common import logger
25+
from neural_compressor.common import Logger
2626
from neural_compressor.onnxrt.utils.utility import MAXIMUM_PROTOBUF, find_by_name
2727

28+
logger = Logger().get_logger()
29+
2830

2931
class ONNXModel:
3032
"""Build ONNX model."""

neural_compressor/onnxrt/utils/utility.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import onnx
1919
from packaging.version import Version
2020

21-
from neural_compressor.common import logger
21+
from neural_compressor.common import Logger
22+
23+
logger = Logger().get_logger()
2224

2325
ONNXRT116_VERSION = Version("1.16.0")
2426
ONNXRT1161_VERSION = Version("1.16.1")

0 commit comments

Comments
 (0)