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 2021/12/22 06:34:49 UTC

[GitHub] [tvm] zxybazh opened a new pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

zxybazh opened a new pull request #9789:
URL: https://github.com/apache/tvm/pull/9789


   This PR is part of the stage M3c of the meta schedule project (#8473).
   
   The architecture is re-designed by Junru and Xiyou. In this PR we modified the design of multiple classes and added post processings, mutators to the meta schedule framework. Also more concrete classes would be added later. We intend to make the interfaces more flexible yet user-friendly with updates in the PR, mostly in SearchStrategy class.
   
   Unittests are also updated in this PR. Thanks to all co-authors for contributing!
   
   Co-authored-by: Junru Shao <<j...@gmail.com>>
   Co-authored-by: Bohan Hou <<3...@users.noreply.github.com>>
   Co-authored-by: Ruihang Lai <<l...@qq.com>>
   Co-authored-by: Hongyi Jin <<3...@qq.com>>
   Co-authored-by: Wuwei Lin <<w...@apache.org>>
   Co-authored-by: Siyuan Feng <<H...@sjtu.edu.cn>>


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777055569



##########
File path: src/meta_schedule/utils.h
##########
@@ -233,6 +242,73 @@ inline std::string Concat(const Array<String>& strs, const std::string& delim) {
   return os.str();
 }
 
+/*!
+ * \brief A helper data structure that replays a trace and collects failure counts
+ * for each postprocessor
+ */
+struct ThreadedTraceApply {
+  /*! \brief Constructor */
+  explicit ThreadedTraceApply(const Array<Postproc>& postprocs)
+      : n_(postprocs.size()), items_(new Item[n_]) {
+    for (int i = 0; i < n_; ++i) {
+      items_[i].postproc = postprocs[i];
+      items_[i].fail_counter = 0;
+    }
+  }
+
+  /*! \brief Destructor */
+  ~ThreadedTraceApply() { delete[] items_; }
+
+  /*!
+   * \brief Apply the trace and postprocessors to an IRModule
+   * \param mod The IRModule to be applied
+   * \param trace The trace to apply to the IRModule
+   * \param rand_state The random seed
+   * \return The schedule created, or NullOpt if any postprocessor fails
+   */
+  Optional<tir::Schedule> Apply(const IRModule& mod, const tir::Trace& trace,
+                                TRandState* rand_state) {
+    tir::Schedule sch =
+        tir::Schedule::Traced(mod,
+                              /*rand_state=*/ForkSeed(rand_state),
+                              /*debug_mode=*/0,
+                              /*error_render_level=*/tir::ScheduleErrorRenderLevel::kNone);
+    trace->ApplyToSchedule(sch, /*remove_postproc=*/true);
+    sch->EnterPostproc();
+    for (int i = 0; i < n_; ++i) {
+      Item& item = items_[i];
+      if (!item.postproc->Apply(sch)) {
+        ++item.fail_counter;
+        return NullOpt;
+      }
+    }
+    return sch;
+  }
+
+  /*! \brief Returns a string summarizing the failures on each postprocessor */
+  std::string SummarizeFailures() const {
+    std::ostringstream os;
+    for (int i = 0; i < n_; ++i) {
+      const Item& item = items_[i];
+      os << "Postproc #" << i << " [" << item.postproc  //
+         << "]: " << item.fail_counter.load() << " failure(s)";
+      if (i != n_ - 1) {
+        os << "\n";
+      }
+    }
+    return os.str();
+  }
+
+ private:
+  struct Item {
+    Postproc postproc{nullptr};
+    std::atomic<int> fail_counter{0};
+  };
+
+  int n_;
+  Item* items_;

Review comment:
       doc?




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777055169



##########
File path: include/tvm/meta_schedule/tune_context.h
##########
@@ -41,34 +48,48 @@ class TuneContextNode : public runtime::Object {
   Optional<SearchStrategy> search_strategy;
   /*! \brief The schedule rules. */
   Array<ScheduleRule> sch_rules;
+  /*! \brief The postprocessors. */
+  Array<Postproc> postprocs;
+  /*! \brief The probability of using certain mutator. */
+  Map<Mutator, FloatImm> mutator_probs;
   /*! \brief The name of the tuning task. */
-  Optional<String> task_name;
+  String task_name;
   /*! \brief The random state. */
   support::LinearCongruentialEngine::TRandState rand_state;
   /*! \brief The number of threads to be used. */
   int num_threads;
 
+  /*! \brief The task scheduler that owns the tune context */
+  const TaskSchedulerNode* task_scheduler;
   /*! \brief Whether the tuning task has been stopped or finished. */
   bool is_stopped;
-  /*! \brief Packed functions to fetch the runner results asynchronously. */
-  Optional<Array<RunnerFuture>> runner_futures;
   /*! \brief The measure candidates. */
   Optional<Array<MeasureCandidate>> measure_candidates;
+  /*! \brief The building results. */
+  Optional<Array<BuilderResult>> builder_results;
+  /*! \brief Packed functions to fetch the runner results asynchronously. */
+  Optional<Array<RunnerFuture>> runner_futures;
 
   void VisitAttrs(tvm::AttrVisitor* v) {
     v->Visit("mod", &mod);
     v->Visit("target", &target);
     v->Visit("space_generator", &space_generator);
     v->Visit("search_strategy", &search_strategy);
     v->Visit("sch_rules", &sch_rules);
+    v->Visit("postprocs", &postprocs);
+    v->Visit("mutator_probs", &mutator_probs);
     v->Visit("task_name", &task_name);
     v->Visit("rand_state", &rand_state);
     v->Visit("num_threads", &num_threads);
     v->Visit("is_stopped", &is_stopped);
+    v->Visit("builder_results", &builder_results);
     v->Visit("runner_futures", &runner_futures);
     v->Visit("measure_candidates", &measure_candidates);

Review comment:
       add `builder_results` and `runner_futures`




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] zxybazh commented on a change in pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
zxybazh commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777085448



##########
File path: include/tvm/meta_schedule/tune_context.h
##########
@@ -41,34 +48,48 @@ class TuneContextNode : public runtime::Object {
   Optional<SearchStrategy> search_strategy;
   /*! \brief The schedule rules. */
   Array<ScheduleRule> sch_rules;
+  /*! \brief The postprocessors. */
+  Array<Postproc> postprocs;
+  /*! \brief The probability of using certain mutator. */
+  Map<Mutator, FloatImm> mutator_probs;
   /*! \brief The name of the tuning task. */
-  Optional<String> task_name;
+  String task_name;

Review comment:
       It should be optional, will fix.




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777055136



##########
File path: include/tvm/meta_schedule/tune_context.h
##########
@@ -41,34 +48,48 @@ class TuneContextNode : public runtime::Object {
   Optional<SearchStrategy> search_strategy;
   /*! \brief The schedule rules. */
   Array<ScheduleRule> sch_rules;
+  /*! \brief The postprocessors. */
+  Array<Postproc> postprocs;
+  /*! \brief The probability of using certain mutator. */
+  Map<Mutator, FloatImm> mutator_probs;
   /*! \brief The name of the tuning task. */
-  Optional<String> task_name;
+  String task_name;

Review comment:
       Why is it changed to non-optional?




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777055428



##########
File path: src/meta_schedule/search_strategy/replay_trace.cc
##########
@@ -17,27 +17,26 @@
  * under the License.
  */
 #include "../utils.h"
+#include "tvm/tir/schedule/schedule.h"

Review comment:
       let's fix this?




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777055213



##########
File path: python/tvm/auto_scheduler/workload_registry.py
##########
@@ -194,7 +194,10 @@ def workload_key_to_tensors(workload_key):
     assert callable(value)
 
     args = deserialize_args(workload[1:])
-    return value(*args)
+    result = value(*args)
+    if isinstance(result, tuple):
+        result = list(result)
+    return result

Review comment:
       no need for this change




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] junrushao1994 merged pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
junrushao1994 merged pull request #9789:
URL: https://github.com/apache/tvm/pull/9789


   


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] zxybazh commented on pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
zxybazh commented on pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#issuecomment-1000044302


   CC @comaniac @jcf94 @merrymercy


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777055208



##########
File path: python/tvm/auto_scheduler/search_task.py
##########
@@ -543,7 +543,8 @@ def print_best(self, log_file, print_mode="schedule"):
         code: str
             The best schedule code in python API or CUDA source code
         """
-        inp, _ = load_best_record(log_file, self.workload_key)
+        inp, res = load_best_record(log_file, self.workload_key)
+        print("Best codes (ms):", [float(c) * 1000.0 for c in res.costs])

Review comment:
       remove this change




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] zxybazh commented on a change in pull request #9789: [M3c][MetaScheduler] Update TuneContext, TaskScheduler & Search Strategy Design

Posted by GitBox <gi...@apache.org>.
zxybazh commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777085437



##########
File path: include/tvm/meta_schedule/tune_context.h
##########
@@ -41,34 +48,48 @@ class TuneContextNode : public runtime::Object {
   Optional<SearchStrategy> search_strategy;
   /*! \brief The schedule rules. */
   Array<ScheduleRule> sch_rules;
+  /*! \brief The postprocessors. */
+  Array<Postproc> postprocs;
+  /*! \brief The probability of using certain mutator. */
+  Map<Mutator, FloatImm> mutator_probs;
   /*! \brief The name of the tuning task. */
-  Optional<String> task_name;
+  String task_name;
   /*! \brief The random state. */
   support::LinearCongruentialEngine::TRandState rand_state;
   /*! \brief The number of threads to be used. */
   int num_threads;
 
+  /*! \brief The task scheduler that owns the tune context */
+  const TaskSchedulerNode* task_scheduler;
   /*! \brief Whether the tuning task has been stopped or finished. */
   bool is_stopped;
-  /*! \brief Packed functions to fetch the runner results asynchronously. */
-  Optional<Array<RunnerFuture>> runner_futures;
   /*! \brief The measure candidates. */
   Optional<Array<MeasureCandidate>> measure_candidates;
+  /*! \brief The building results. */
+  Optional<Array<BuilderResult>> builder_results;
+  /*! \brief Packed functions to fetch the runner results asynchronously. */
+  Optional<Array<RunnerFuture>> runner_futures;
 
   void VisitAttrs(tvm::AttrVisitor* v) {
     v->Visit("mod", &mod);
     v->Visit("target", &target);
     v->Visit("space_generator", &space_generator);
     v->Visit("search_strategy", &search_strategy);
     v->Visit("sch_rules", &sch_rules);
+    v->Visit("postprocs", &postprocs);
+    v->Visit("mutator_probs", &mutator_probs);
     v->Visit("task_name", &task_name);
     v->Visit("rand_state", &rand_state);
     v->Visit("num_threads", &num_threads);
     v->Visit("is_stopped", &is_stopped);
+    v->Visit("builder_results", &builder_results);
     v->Visit("runner_futures", &runner_futures);
     v->Visit("measure_candidates", &measure_candidates);

Review comment:
       Do you mean remove?




-- 
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: commits-unsubscribe@tvm.apache.org

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