masahi commented on a change in pull request #10578:
URL: https://github.com/apache/tvm/pull/10578#discussion_r826551789



##########
File path: src/relay/backend/te_compiler_cache.cc
##########
@@ -335,15 +336,14 @@ class ScheduleBuilder : public ExprVisitor {
         }
       }
       if (backend::IsMetaScheduleEnabled()) {
-        prim_func = tir::CreatePrimFunc(Concat(fn_inputs, tensor_outs));
-        Optional<ObjectRef> opt_mod_or_base_func =
-            meta_schedule::MetaScheduleContext::QueryInsideWithScope(
-                prim_fn_var->name_hint, IRModule({{prim_fn_var, relay_func}}), 
target_,
-                Array<IRModule>{IRModule({{prim_fn_var, prim_func}})});
-        if (const auto* result = opt_mod_or_base_func.as<tir::PrimFuncNode>()) 
{
-          prim_func = GetRef<tir::PrimFunc>(result);
-        } else {
-          prim_func = tir::PrimFunc(nullptr);
+        auto relay_mod = IRModule({{prim_fn_var, relay_func}});
+        auto tir_mod =
+            IRModule({{prim_fn_var, tir::CreatePrimFunc(Concat(fn_inputs, 
tensor_outs))}});
+        IRModule scheduled_mod = 
meta_schedule::MetaScheduleContext::QueryInsideWithScope(
+            prim_fn_var->name_hint, relay_mod, target_, 
Array<IRModule>{tir_mod});
+        if (scheduled_mod.defined()) {

Review comment:
       There is a case this can be be null, see 
https://github.com/apache/tvm/blob/d528861449949c06dfe8dbe43dcbcdc415369b38/src/meta_schedule/integration.cc#L143-L145
   
   This happens when not all extracted tasks are added to the tuning database. 
In my case, I only tune `dense` and `batch_matmul`, so all other tasks are 
filtered out so `ApplyHistoryBest` won't see them. Since `scheduled_mod` is 
null, this branch is not taken and `prim_func` will be left `nullptr` as well. 
They are scheduled by TE schedules in this branch 
https://github.com/apache/tvm/blob/d528861449949c06dfe8dbe43dcbcdc415369b38/src/relay/backend/te_compiler_cache.cc#L349-L353.
   
   The logic is not obvious, but here we see "selectively tune ops of interest 
by meta-schedule, the rest by autotvm" in action.




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