You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ma...@apache.org on 2022/12/27 21:10:22 UTC

[tvm] branch main updated: [QNN] Change in Pass Context for lookup table calculation (#13660)

This is an automated email from the ASF dual-hosted git repository.

masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new f83055f90a [QNN] Change in Pass Context for lookup table calculation (#13660)
f83055f90a is described below

commit f83055f90ad300fe60ad710260abba5a0693eefd
Author: ibsidorenko <98...@users.noreply.github.com>
AuthorDate: Wed Dec 28 00:10:15 2022 +0300

    [QNN] Change in Pass Context for lookup table calculation (#13660)
    
    Motivation:
    It is possible to disable specific passes through the "disabled_pass"
    parameter in the Pass Context. These "disabled" passes can be optional
    for one target and mandatory for another one.
    Since lookup table for some QNN operations (tanh, round and etc.) is
    calculated on the host and some of disabled passes can be required for
    the host, no need to disable these passes. This constant calculation/
    evaluation is orthogonal to the compilation process for specific target.
    
    What was changed:
    This commit creates its own compilation Pass Context for lookup table
    calculation and evaluation (for elemwise QNN ops: tanh, sqrt ...).
---
 python/tvm/relay/qnn/op/canonicalizations.py | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/python/tvm/relay/qnn/op/canonicalizations.py b/python/tvm/relay/qnn/op/canonicalizations.py
index 1f2c57c6da..6bfcd34aba 100644
--- a/python/tvm/relay/qnn/op/canonicalizations.py
+++ b/python/tvm/relay/qnn/op/canonicalizations.py
@@ -23,10 +23,25 @@ from tvm import relay
 
 
 def run_const_expr(expr: "relay.Expr") -> np.ndarray:
-    """Evaluate a const expression, receiving result as np array."""
-    mod = tvm.IRModule.from_expr(expr)
-    vm_exe = relay.create_executor("vm", mod=mod)
-    return vm_exe.evaluate()().asnumpy()
+    """Evaluate a const expression, receiving result as np array.
+
+    If a number of passes are disabled in the current Pass Context, then there is no need to disable
+    these passes for const expression evaluation as well. That's why we use empty list
+    "disabled_pass=[]", all other arguments are inherited from the current Pass Context.
+    """
+    curr_pass_ctx = tvm.ir.transform.PassContext.current()
+    with tvm.ir.transform.PassContext(
+        opt_level=curr_pass_ctx.opt_level,
+        required_pass=curr_pass_ctx.required_pass,
+        disabled_pass=[],
+        instruments=curr_pass_ctx.instruments,
+        config=curr_pass_ctx.config,
+    ):
+        mod = tvm.IRModule.from_expr(expr)
+        vm_exe = relay.create_executor("vm", mod=mod)
+        output = vm_exe.evaluate()().asnumpy()
+
+    return output
 
 
 def create_integer_lookup_table(