mehrdadh commented on code in PR #11250:
URL: https://github.com/apache/tvm/pull/11250#discussion_r874139695


##########
python/tvm/autotvm/task/dispatcher.py:
##########
@@ -178,6 +178,50 @@ def update(self, target, workload, cfg):
         self._config = cfg
 
 
+class ApplyFixedConfig(DispatchContext):
+    """Apply a config of a deterministic schedule.
+
+    Parameters
+    ----------
+    tasks : list[tvm.autotvm.task.task.Task]
+        List of autoTVM tasks.
+    schedule_name : str
+        Name of schedule to use.
+    """
+
+    def __init__(self, tasks, schedule_name: str):
+        super(ApplyFixedConfig, self).__init__()
+        self._schedule_name = schedule_name
+        self._tasks = tasks
+        self.workload = None
+
+    def _query_inside(self, target, workload):
+        """Override query"""
+        self.workload = workload
+
+        # Creat a config from correct task
+        for task in self._tasks:
+            if task.name == workload[0]:
+                config = task.config_space.get(0)
+                break
+
+        if not config:
+            raise RuntimeError(
+                "workload: %s does not exist in %s" % (str(workload), 
str(self._tasks))
+            )
+        # Add low cost to the target schedule and high cost to others.
+        if workload[0] == self._schedule_name:
+            config.cost = 0.000001

Review Comment:
   done



##########
python/tvm/autotvm/task/dispatcher.py:
##########
@@ -178,6 +178,50 @@ def update(self, target, workload, cfg):
         self._config = cfg
 
 
+class ApplyFixedConfig(DispatchContext):
+    """Apply a config of a deterministic schedule.
+
+    Parameters
+    ----------
+    tasks : list[tvm.autotvm.task.task.Task]
+        List of autoTVM tasks.
+    schedule_name : str
+        Name of schedule to use.
+    """
+
+    def __init__(self, tasks, schedule_name: str):

Review Comment:
   can you explain why?



##########
python/tvm/micro/testing/aot_test_utils.py:
##########
@@ -38,12 +36,13 @@
 import tvm
 from tvm import relay
 from tvm import te
+from tvm import autotvm

Review Comment:
   agreed, I splitted that file into `python/tvm/testing/aot.py` and 
`python/tvm/micro/testing/aot_test_utils.py`



##########
python/tvm/autotvm/task/dispatcher.py:
##########
@@ -178,6 +178,50 @@ def update(self, target, workload, cfg):
         self._config = cfg
 
 
+class ApplyFixedConfig(DispatchContext):
+    """Apply a config of a deterministic schedule.

Review Comment:
   added more details.



##########
python/tvm/micro/testing/aot_test_utils.py:
##########
@@ -708,31 +708,52 @@ def compile_models(
 
     compiled_mods = list()
     for model in models:
-        with tvm.transform.PassContext(opt_level=3, config=config):
-            # TODO(Mousius) - Remove once executor/runtime are fully removed 
from Target
-            if use_runtime_executor:
-                executor_factory = tvm.relay.build(
-                    model.module,
-                    target,
-                    executor=executor,
-                    runtime=runtime,
-                    workspace_memory_pools=workspace_memory_pools,
-                    params=model.params,
-                    mod_name=model.name,
-                )
-                compiled_mods.append(
-                    AOTCompiledTestModel(model=model, 
executor_factory=executor_factory)
-                )
-            else:
-                executor_factory = tvm.relay.build(
-                    model.module,
-                    tvm.target.Target(target, host=target),
-                    params=model.params,
-                    mod_name=model.name,
-                )
-                compiled_mods.append(
-                    AOTCompiledTestModel(model=model, 
executor_factory=executor_factory)
-                )
+        if schedule_name:
+            # Testing with deterministic schedule
+            task_list = autotvm.task.extract_from_program(
+                model.module, target=target, params=model.params
+            )
+            with tvm.autotvm.apply_fixed_config(task_list, schedule_name):
+                with tvm.transform.PassContext(opt_level=3, config=config):
+                    if use_runtime_executor:
+                        executor_factory = tvm.relay.build(
+                            model.module,
+                            target,
+                            executor=executor,
+                            runtime=runtime,
+                            workspace_memory_pools=workspace_memory_pools,
+                            params=model.params,
+                            mod_name=model.name,
+                        )
+                        compiled_mods.append(
+                            AOTCompiledTestModel(model=model, 
executor_factory=executor_factory)
+                        )

Review Comment:
   added



##########
python/tvm/autotvm/task/dispatcher.py:
##########
@@ -178,6 +178,50 @@ def update(self, target, workload, cfg):
         self._config = cfg
 
 
+class ApplyFixedConfig(DispatchContext):
+    """Apply a config of a deterministic schedule.
+
+    Parameters
+    ----------
+    tasks : list[tvm.autotvm.task.task.Task]
+        List of autoTVM tasks.
+    schedule_name : str
+        Name of schedule to use.
+    """
+
+    def __init__(self, tasks, schedule_name: str):
+        super(ApplyFixedConfig, self).__init__()
+        self._schedule_name = schedule_name
+        self._tasks = tasks
+        self.workload = None
+
+    def _query_inside(self, target, workload):
+        """Override query"""
+        self.workload = workload
+
+        # Creat a config from correct task

Review Comment:
   fixed, thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to