Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions python/tvm/contrib/msc/core/gym/agent/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class BaseAgent(object):
The extra options for the agent.
debug_level: int
The debug level.
verbose_task: int
The verbose interval task.
verbose: str
The verbose level.
logger: logging.Logger
The logger
"""
Expand All @@ -50,6 +50,7 @@ def __init__(
executors: dict,
options: dict = None,
debug_level: int = 0,
verbose: str = None,
logger: logging.Logger = None,
):
self._name = name
Expand All @@ -60,7 +61,8 @@ def __init__(
if logger:
self._logger = logger
else:
verbose = "debug" if debug_level > 0 else "info"
if not verbose:
verbose = "debug" if debug_level > 0 else "info"
self._logger = msc_utils.create_file_logger(verbose, workspace.relpath("AGENT_LOG"))
self._logger.info(
msc_utils.msg_block("AGENT.SETUP({})".format(self.agent_type()), self.setup())
Expand Down
4 changes: 2 additions & 2 deletions python/tvm/contrib/msc/core/gym/control/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class BaseController(object):
The worksapce.
config: dict
The config for service.
is_master: bool
Whether the node is master node
is_main: bool
Whether the node is main node
"""

def __init__(
Expand Down
8 changes: 7 additions & 1 deletion python/tvm/contrib/msc/core/gym/control/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class BaseService(object):
The record step.
debug_level: int
The debug level
verbose: str
The verbose level.
"""

def __init__(
Expand All @@ -164,15 +166,19 @@ def __init__(
max_iter: int = 1,
record_step: int = 5,
debug_level: int = 0,
verbose: str = None,
):
self._workspace = workspace
tasks = tasks or [GYMObject.ENV + ":0", GYMObject.AGENT + ":0"]
verbose = "debug" if debug_level > 0 else "info"
if not verbose:
verbose = "debug" if debug_level > 0 else "info"
self._logger = msc_utils.create_file_logger(verbose, self._workspace.relpath("SERVICE_LOG"))

def _create_workers(config: dict, obj_type: str) -> List[BaseWorker]:
if "debug_level" not in config:
config["debug_level"] = debug_level
if "verbose" not in config:
config["verbose"] = verbose
if "logger" not in config:
config["logger"] = self._logger
return [
Expand Down
8 changes: 5 additions & 3 deletions python/tvm/contrib/msc/core/gym/environment/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class BaseEnv(object):
The extra options for the environment.
debug_level: int
The debug level.
verbose_step: int
The verbose interval step.
verbose: str
The verbose level.
logger: logging.Logger
The logger
"""
Expand All @@ -60,6 +60,7 @@ def __init__(
options: dict = None,
max_tasks: int = -1,
debug_level: int = 0,
verbose: str = None,
logger: logging.Logger = None,
):
self._name = name
Expand All @@ -74,7 +75,8 @@ def __init__(
if logger:
self._logger = logger
else:
verbose = "debug" if debug_level > 0 else "info"
if not verbose:
verbose = "debug" if debug_level > 0 else "info"
self._logger = msc_utils.create_file_logger(verbose, workspace.relpath("ENV_LOG"))
self._logger.info(
msc_utils.msg_block("ENV.SETUP({})".format(self.env_type()), self.setup())
Expand Down
4 changes: 4 additions & 0 deletions python/tvm/contrib/msc/core/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def create_file_logger(level: Union[str, int] = logging.INFO, path: str = None)
level = logging.INFO
elif level == "warn":
level = logging.WARN
elif level == "error":
level = logging.ERROR
elif level == "critical":
level = logging.CRITICAL
else:
raise Exception("Unexcept verbose {}, should be debug| info| warn")

Expand Down
32 changes: 26 additions & 6 deletions python/tvm/contrib/msc/pipeline/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def __init__(self, model, config):
self._workspace = msc_utils.set_workspace(config.get("workspace"))
log_path = config.get("log_path") or self._workspace.relpath("MSC_LOG", keep_history=False)
if config.get("debug_level", 0) > 0 and "verbose" not in config:
verbose = "debug"
self._verbose = "debug"
else:
verbose = config.get("verbose", "info")
self._logger = msc_utils.set_global_logger(verbose, log_path)
self._verbose = config.get("verbose", "info")
self._logger = msc_utils.set_global_logger(self._verbose, log_path)
msc_utils.time_stamp(MSCStage.SETUP)
self._logger.info(msc_utils.msg_block("SETUP", self.setup(config)))

Expand All @@ -78,6 +78,9 @@ def setup(self, config: dict) -> dict:
self._tools_config = {}
self._relax_mod, self._runner = None, None
self._data_loader, self._sample_inputs = None, None
self._model_type = self._config["model_type"]
self._optimize_type = self._config.get("optimize", {}).get("run_type", self._model_type)
self._compile_type = self._config.get("compile", {}).get("run_type", self._model_type)
self._report = {
"success": False,
"info": {
Expand Down Expand Up @@ -172,9 +175,9 @@ def run_pipe(self) -> dict:
self._runner = self.compile(self._config["compile"], use_cache)
except Exception as exc: # pylint: disable=broad-exception-caught
err_msg = "Pipeline failed:{}\nTrace: {}".format(exc, traceback.format_exc())
report = self.summary(err_msg)
self._logger.info(msc_utils.msg_block("SUMMARY", report, 0))
return report
self.summary(err_msg)
self._logger.info(msc_utils.msg_block("SUMMARY", self._report, 0))
return self._report

def prepare(self, stage_config: dict, use_cache: bool = False) -> Dict[str, np.ndarray]:
"""Prepare datas for the pipeline.
Expand Down Expand Up @@ -573,6 +576,7 @@ def _apply_tool(self, tool_type: str, stage_config: dict, add_tool: bool = True)
"knowledge": knowledge,
},
"debug_level": runner.debug_level,
"verbose": self._verbose,
}
controller = create_controller(runner.stage, config, extra_config)
knowledge = controller.run()
Expand Down Expand Up @@ -868,6 +872,22 @@ def _get_runner_cls(self, run_type: str) -> BaseRunner:
def runner(self):
return self._runner

@property
def report(self):
return self._report

@property
def model_type(self):
return self._model_type

@property
def optimize_type(self):
return self._optimize_type

@property
def compile_type(self):
return self._compile_type


class MSCManager(BaseManager):
"""Normal manager in MSC"""
Expand Down
Loading