You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/11/21 02:45:01 UTC

[GitHub] [incubator-tvm] comaniac opened a new pull request #6945: [AutoScheduler] Task scheduler callbacks

comaniac opened a new pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945


   I found that it would be useful to log how the total latency is improved during the tuning process, especially for the case of using task scheduler. Since this requirement could be case by case, I tried to make a callback mechanism for task scheduler, and changed the existing `_print_table_info` to one callback. This is not necessary to be the final version. Suggestions and comments about where to call the callbacks and what arguments they should accept are welcome.
   
   cc @merrymercy @jcf94 @FrozenGene @minminsun 


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] comaniac commented on pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
comaniac commented on pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#issuecomment-732359484


   @merrymercy @FrozenGene PTAL.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] comaniac commented on a change in pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#discussion_r528309917



##########
File path: tutorials/auto_scheduler/tune_network_cuda.py
##########
@@ -186,7 +189,9 @@ def run_tuning():
     print("Begin tuning...")
     measure_ctx = auto_scheduler.LocalRPCMeasureContext(repeat=1, min_repeat_ms=400, timeout=10)
 
-    tuner = auto_scheduler.TaskScheduler(tasks, task_weights)
+    tuner = auto_scheduler.TaskScheduler(
+        tasks, task_weights, callbacks=[auto_scheduler.task_scheduler.PrintTableInfoCallback()]

Review comment:
       Sounds good, so when callbacks is not None, we override the default one with whatever users pass.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] merrymercy commented on a change in pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
merrymercy commented on a change in pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#discussion_r528284355



##########
File path: python/tvm/auto_scheduler/task_scheduler.py
##########
@@ -478,3 +459,109 @@ def _restore_status(self, log_file, num_measures_per_round):
         self.cur_score = self._compute_score(self.best_costs)
 
         logger.info("TaskScheduler: Loaded %d measurement records from %s", total_ct + 1, log_file)
+
+
+class TaskSchedulerCallback:
+    """The base class of task scheduler callback functions. """
+
+    def pre_tune(self, task_scheduler, task_id):
+        """The callback before tuning each task.
+
+        Parameters
+        ----------
+        task_scheduler: TaskScheduler
+            The task scheduler.
+        task_id: int
+            The task ID going to be tuned.
+        """
+        pass
+
+    def post_tune(self, task_scheduler, task_id):
+        """The callback after tuning each task.
+
+        Parameters
+        ----------
+        task_scheduler: TaskScheduler
+            The task scheduler.
+        task_id: int
+            The task ID be tuned.
+        """
+        pass
+
+
+class PrintTableInfoCallback(TaskSchedulerCallback):

Review comment:
       We can remove the 'Callback' in the name and simply use `PrintTableInfo`.
   The callback in autotvm does not have this suffix either.

##########
File path: tutorials/auto_scheduler/tune_network_cuda.py
##########
@@ -186,7 +189,9 @@ def run_tuning():
     print("Begin tuning...")
     measure_ctx = auto_scheduler.LocalRPCMeasureContext(repeat=1, min_repeat_ms=400, timeout=10)
 
-    tuner = auto_scheduler.TaskScheduler(tasks, task_weights)
+    tuner = auto_scheduler.TaskScheduler(
+        tasks, task_weights, callbacks=[auto_scheduler.task_scheduler.PrintTableInfoCallback()]

Review comment:
       Can we make this the default callback to simplify the  API?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] merrymercy merged pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
merrymercy merged pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945


   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
FrozenGene commented on a change in pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#discussion_r528310540



##########
File path: tutorials/auto_scheduler/tune_network_cuda.py
##########
@@ -186,7 +189,9 @@ def run_tuning():
     print("Begin tuning...")
     measure_ctx = auto_scheduler.LocalRPCMeasureContext(repeat=1, min_repeat_ms=400, timeout=10)
 
-    tuner = auto_scheduler.TaskScheduler(tasks, task_weights)
+    tuner = auto_scheduler.TaskScheduler(
+        tasks, task_weights, callbacks=[auto_scheduler.task_scheduler.PrintTableInfoCallback()]

Review comment:
       Yes.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] comaniac commented on a change in pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#discussion_r528285535



##########
File path: tutorials/auto_scheduler/tune_network_cuda.py
##########
@@ -186,7 +189,9 @@ def run_tuning():
     print("Begin tuning...")
     measure_ctx = auto_scheduler.LocalRPCMeasureContext(repeat=1, min_repeat_ms=400, timeout=10)
 
-    tuner = auto_scheduler.TaskScheduler(tasks, task_weights)
+    tuner = auto_scheduler.TaskScheduler(
+        tasks, task_weights, callbacks=[auto_scheduler.task_scheduler.PrintTableInfoCallback()]

Review comment:
       If we make this as the default, then it means users have no way to turn it off. That's why I didn't do that, but I'm also fine if you prefer such semantic.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
FrozenGene commented on a change in pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#discussion_r528305417



##########
File path: tutorials/auto_scheduler/tune_network_cuda.py
##########
@@ -186,7 +189,9 @@ def run_tuning():
     print("Begin tuning...")
     measure_ctx = auto_scheduler.LocalRPCMeasureContext(repeat=1, min_repeat_ms=400, timeout=10)
 
-    tuner = auto_scheduler.TaskScheduler(tasks, task_weights)
+    tuner = auto_scheduler.TaskScheduler(
+        tasks, task_weights, callbacks=[auto_scheduler.task_scheduler.PrintTableInfoCallback()]

Review comment:
       How about setting `PrintTableInfoCallback` be default callback but allow users pass `callbacks=None` to turn  off ? We could add comment here to explain our design




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] merrymercy commented on a change in pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
merrymercy commented on a change in pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#discussion_r528946151



##########
File path: tutorials/auto_scheduler/tune_network_cuda.py
##########
@@ -168,6 +168,10 @@ def get_network(name, batch_size, layout="NHWC", dtype="float32"):
 # * :code:`min_repeat_ms` defines the minimum duration of one "repeat" in every measurement.
 #   This can warmup the GPU, which is necessary to get accurate measurement results.
 #   Typically, we recommend a value > 300 ms.
+# * :code:`callbacks` could be a list of task scheduler callbacks during the tuning.
+#   You can use callbacks such as LogEstimatedLatency to log the estimated total latency
+#   to a file for better analysis. When not specified, PrintTableInfo is used to print
+#   a timely progress table.

Review comment:
       ```suggestion
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] comaniac commented on a change in pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#discussion_r528923005



##########
File path: tutorials/auto_scheduler/tune_network_cuda.py
##########
@@ -186,7 +189,9 @@ def run_tuning():
     print("Begin tuning...")
     measure_ctx = auto_scheduler.LocalRPCMeasureContext(repeat=1, min_repeat_ms=400, timeout=10)
 
-    tuner = auto_scheduler.TaskScheduler(tasks, task_weights)
+    tuner = auto_scheduler.TaskScheduler(
+        tasks, task_weights, callbacks=[auto_scheduler.task_scheduler.PrintTableInfoCallback()]

Review comment:
       Done

##########
File path: python/tvm/auto_scheduler/task_scheduler.py
##########
@@ -478,3 +459,109 @@ def _restore_status(self, log_file, num_measures_per_round):
         self.cur_score = self._compute_score(self.best_costs)
 
         logger.info("TaskScheduler: Loaded %d measurement records from %s", total_ct + 1, log_file)
+
+
+class TaskSchedulerCallback:
+    """The base class of task scheduler callback functions. """
+
+    def pre_tune(self, task_scheduler, task_id):
+        """The callback before tuning each task.
+
+        Parameters
+        ----------
+        task_scheduler: TaskScheduler
+            The task scheduler.
+        task_id: int
+            The task ID going to be tuned.
+        """
+        pass
+
+    def post_tune(self, task_scheduler, task_id):
+        """The callback after tuning each task.
+
+        Parameters
+        ----------
+        task_scheduler: TaskScheduler
+            The task scheduler.
+        task_id: int
+            The task ID be tuned.
+        """
+        pass
+
+
+class PrintTableInfoCallback(TaskSchedulerCallback):

Review comment:
       Done




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] merrymercy commented on a change in pull request #6945: [AutoScheduler] Task scheduler callbacks

Posted by GitBox <gi...@apache.org>.
merrymercy commented on a change in pull request #6945:
URL: https://github.com/apache/incubator-tvm/pull/6945#discussion_r528284355



##########
File path: python/tvm/auto_scheduler/task_scheduler.py
##########
@@ -478,3 +459,109 @@ def _restore_status(self, log_file, num_measures_per_round):
         self.cur_score = self._compute_score(self.best_costs)
 
         logger.info("TaskScheduler: Loaded %d measurement records from %s", total_ct + 1, log_file)
+
+
+class TaskSchedulerCallback:
+    """The base class of task scheduler callback functions. """
+
+    def pre_tune(self, task_scheduler, task_id):
+        """The callback before tuning each task.
+
+        Parameters
+        ----------
+        task_scheduler: TaskScheduler
+            The task scheduler.
+        task_id: int
+            The task ID going to be tuned.
+        """
+        pass
+
+    def post_tune(self, task_scheduler, task_id):
+        """The callback after tuning each task.
+
+        Parameters
+        ----------
+        task_scheduler: TaskScheduler
+            The task scheduler.
+        task_id: int
+            The task ID be tuned.
+        """
+        pass
+
+
+class PrintTableInfoCallback(TaskSchedulerCallback):

Review comment:
       We can remove the 'Callback' in the name and simply use `PrintTableInfo`.
   The callbacks in autotvm do not have this suffix either.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org