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/03/06 23:18:29 UTC

[GitHub] [incubator-tvm] masahi commented on a change in pull request #4996: [relay][external codegen] outline and inline lifted functions for external codegen

masahi commented on a change in pull request #4996: [relay][external codegen] outline and inline lifted functions for external codegen
URL: https://github.com/apache/incubator-tvm/pull/4996#discussion_r389189569
 
 

 ##########
 File path: tests/python/relay/test_pass_partition_graph.py
 ##########
 @@ -427,10 +465,110 @@ def test_extern_dnnl_mobilenet():
                  (1, 1000), ref_res.asnumpy(), tol=1e-5, params=params)
 
 
+def test_function_lifting():
+    def partition():
+        data = relay.var("data", relay.TensorType((1, 3, 224, 224), "float32"))
+        weight = relay.var("weight", relay.TensorType((16, 3, 3, 3), "float32"))
+        bn_gamma = relay.var("bn_gamma", relay.TensorType((16, ), "float32"))
+        bn_beta = relay.var("bn_beta", relay.TensorType((16, ), "float32"))
+        bn_mmean = relay.var("bn_mean", relay.TensorType((16, ), "float32"))
+        bn_mvar = relay.var("bn_var", relay.TensorType((16, ), "float32"))
+
+        conv = relay.nn.conv2d(
+            data=data,
+            weight=weight,
+            kernel_size=(3, 3),
+            channels=16,
+            padding=(1, 1))
+        bn_output = relay.nn.batch_norm(conv, bn_gamma, bn_beta, bn_mmean,
+                                        bn_mvar)
+
+        func = relay.Function([data, weight, bn_gamma, bn_beta, bn_mmean,
+                               bn_mvar], bn_output.astuple())
+        mod = tvm.IRModule()
+        mod["main"] = func
+        op_list = ["nn.batch_norm", "nn.conv2d"]
+        mod = WhiteListAnnotator(op_list, "test_compiler")(mod)
+
+        opt_pass = transform.Sequential([
+            transform.InferType(),
+            transform.PartitionGraph(),
+            transform.SimplifyInference(),
+            transform.FoldConstant(),
+            transform.AlterOpLayout()
 
 Review comment:
   I think adding Inline here would better illustrate the motivation of this PR (also closer to `relay.optimize` pipeline).
   
   I get
   ```
   def @main(%data: Tensor[(1, 3, 224, 224), float32], %weight: Tensor[(16, 3, 3, 3), float32], %bn_gamma: Tensor[(16), float32], %bn_beta: Tensor[(16), float32], %bn_mean: Tensor[(16), float32], %bn_var: Tensor[(16), float32]) -> (Tensor[(1, 16, 224, 224), float32], Tensor[(16), float32], Tensor[(16), float32]) {
     %0 = fn (%test_compiler_input0: Tensor[(1, 3, 224, 224), float32], %test_compiler_input1: Tensor[(16, 3, 3, 3), float32], Inline=1, Compiler="test_compiler", ExternalSymbol="test_compiler_1", Primitive=1) -> Tensor[(1, 16, 224, 224), float32] {
       nn.conv2d(%test_compiler_input0, %test_compiler_input1, padding=[1, 1, 1, 1], channels=16, kernel_size=[3, 3]) /* ty=Tensor[(1, 16, 224, 224), float32] */
     };
     %1 = %0(%data, %weight) /* ty=Tensor[(1, 16, 224, 224), float32] */;
     %2 = fn (%test_compiler_input2: Tensor[(1, 16, 224, 224), float32], %test_compiler_input3: Tensor[(16), float32], %test_compiler_input4: Tensor[(16), float32], %test_compiler_input5: Tensor[(16), float32], %test_compiler_input6: Tensor[(16), float32], Inline=1, Compiler="test_compiler", ExternalSymbol="test_compiler_0", Primitive=1) -> (Tensor[(1, 16, 224, 224), float32], Tensor[(16), float32], Tensor[(16), float32]) {
       nn.batch_norm(%test_compiler_input2, %test_compiler_input3, %test_compiler_input4, %test_compiler_input5, %test_compiler_input6) /* ty=(Tensor[(1, 16, 224, 224), float32], Tensor[(16), float32], Tensor[(16), float32]) */
     };
     %2(%1, %bn_gamma, %bn_beta, %bn_mean, %bn_var) /* ty=(Tensor[(1, 16, 224, 224), float32], Tensor[(16), float32], Tensor[(16), float32]) */
   }
   ```
   which I think is more interesting

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


With regards,
Apache Git Services