diff --git a/python/tvm/meta_schedule/task_scheduler/task_scheduler.py b/python/tvm/meta_schedule/task_scheduler/task_scheduler.py index 816d7abd1605..4454078a6f16 100644 --- a/python/tvm/meta_schedule/task_scheduler/task_scheduler.py +++ b/python/tvm/meta_schedule/task_scheduler/task_scheduler.py @@ -20,7 +20,6 @@ from typing import Callable, List, Optional from tvm._ffi import register_object -from tvm.meta_schedule.utils import make_logging_func from tvm.runtime import Object from .. import _ffi_api @@ -30,6 +29,7 @@ from ..measure_callback import MeasureCallback from ..runner import Runner, RunnerResult from ..tune_context import TuneContext +from ..utils import make_logging_func logger = logging.getLogger(__name__) # pylint: disable=invalid-name diff --git a/python/tvm/meta_schedule/tune.py b/python/tvm/meta_schedule/tune.py index 0881d614b93e..65026b73bebc 100644 --- a/python/tvm/meta_schedule/tune.py +++ b/python/tvm/meta_schedule/tune.py @@ -17,8 +17,8 @@ """User-facing Tuning API""" # pylint: disable=import-outside-toplevel import logging -from pathlib import Path -import os.path as osp +import os +from os import path as osp from typing import Any, Callable, Dict, List, NamedTuple, Optional, Union from tvm._ffi.registry import register_func @@ -502,7 +502,7 @@ def tune_extracted_tasks( """ # pylint: disable=protected-access log_dir = osp.join(work_dir, "logs") - Path(log_dir).mkdir(parents=True, exist_ok=True) + os.makedirs(log_dir, exist_ok=True) logger_config = config.create_logger_config( log_dir=log_dir, propagate=False, @@ -545,7 +545,8 @@ def tune_extracted_tasks( mutator_probs=Parse._mutator_probs(mutator_probs, task.target), task_name=task.task_name, logger=Parse._logger( - name="tvm.meta_schedule." + name=__name__ + + "." + "_".join(["task", str(i).zfill(max_width), task.task_name]), **logger_config, ), diff --git a/python/tvm/meta_schedule/utils.py b/python/tvm/meta_schedule/utils.py index e2f910d7ffe1..52284b82b3c7 100644 --- a/python/tvm/meta_schedule/utils.py +++ b/python/tvm/meta_schedule/utils.py @@ -374,7 +374,7 @@ def autotvm_silencer(): autotvm.GLOBAL_SCOPE.silent = silent -def make_logging_func(logger: logging.Logger): +def make_logging_func(logger: logging.Logger) -> Optional[Callable]: """Get the logging function. Parameters ---------- @@ -382,13 +382,14 @@ def make_logging_func(logger: logging.Logger): The logger instance. Returns ------- - result : Callable + result : Optional[Callable] The function to do the specified level of logging. """ if logger is None: return None level2log = { + logging.DEBUG: logger.debug, logging.INFO: logger.info, logging.WARNING: logger.warning, logging.ERROR: logger.error, diff --git a/src/meta_schedule/utils.h b/src/meta_schedule/utils.h index 2fefddba98cf..f6bd8e28674b 100644 --- a/src/meta_schedule/utils.h +++ b/src/meta_schedule/utils.h @@ -53,17 +53,22 @@ #include "../tir/schedule/primitive.h" #include "../tir/schedule/utils.h" -#define TVM_PY_LOG(logging_level, logging_func) \ - PyLogMessage(__FILE__, __LINE__, logging_func, PyLogMessage::Level::logging_level).stream() +#define TVM_PY_LOG(logging_level, logging_func) \ + ::tvm::meta_schedule::PyLogMessage(__FILE__, __LINE__, logging_func, \ + PyLogMessage::Level::logging_level) \ + .stream() + namespace tvm { +namespace meta_schedule { /*! * \brief Class to accumulate an log message on the python side. Do not use directly, instead use - * TVM_PY_LOG(INFO), TVM_PY_LOG(WARNING), TVM_PY_ERROR(INFO). + * TVM_PY_LOG(DEBUG), TVM_PY_LOG(INFO), TVM_PY_LOG(WARNING), TVM_PY_ERROR(ERROR). */ class PyLogMessage { public: enum class Level : int32_t { + DEBUG = 10, INFO = 20, WARNING = 30, ERROR = 40, @@ -96,8 +101,6 @@ class PyLogMessage { Level logging_level; }; -namespace meta_schedule { - /*! \brief The type of the random state */ using TRandState = support::LinearCongruentialEngine::TRandState;