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/07/12 05:06:40 UTC

[GitHub] [incubator-tvm] hzfan commented on a change in pull request #5235: [Fix] i64 indices

hzfan commented on a change in pull request #5235:
URL: https://github.com/apache/incubator-tvm/pull/5235#discussion_r453268159



##########
File path: tests/python/relay/test_pass_fuse_ops.py
##########
@@ -621,6 +621,81 @@ def expected():
     after = run_opt_pass(expected(), transform.InferType())
     assert tvm.ir.structural_equal(zz, after)
 
+
+def test_fuse_take():

Review comment:
       Sure. It may cause problems when fusing i32 ops into i64 ops. A simplified example:
   
   ```
   i64_2 = tvm.tir.const(2, "int64")
   i64_4 = tvm.tir.const(4, "int64")
   i32_2 = tvm.tir.const(2, "int32")
   a = te.placeholder((i64_4, i64_4), "a")
   b = te.compute((i64_2, i64_2), lambda i, j: a[i + 2, j + 2])
   c = te.compute((i32_2, i32_2), lambda i, j: b[i, j] + 1)
   ```
   
   When fusing `b` into `c`, the i64 variables in `b` are replaced by i32 expressions in `c`, which does not make sense.

##########
File path: tests/python/relay/test_pass_fuse_ops.py
##########
@@ -621,6 +621,81 @@ def expected():
     after = run_opt_pass(expected(), transform.InferType())
     assert tvm.ir.structural_equal(zz, after)
 
+
+def test_fuse_take():
+    """Test fusion case involving concat and take"""
+
+    def before():
+        shape = (tvm.tir.const(10, "int64"),
+                 tvm.tir.const(1, "int64"))
+        x = relay.var("x", shape=shape)
+        concat = relay.concatenate([x,x], axis=-1)
+        out = relay.op.take(concat, indices=relay.const([0], dtype="int64"))
+        return relay.Function(relay.analysis.free_vars(out), out)
+
+    def expected():
+        shape1 = (tvm.tir.const(10, "int64"),
+                  tvm.tir.const(1, "int64"))
+        shape2 = (tvm.tir.const(1, "int64"),)
+        x = relay.var("x", shape=shape1)
+        p0 = relay.var("p0", shape=shape1)
+        p1 = relay.var("p1", shape=shape2,
+                             dtype="int64")
+        c = relay.const([0], dtype="int64")
+        concat = relay.concatenate([p0,p0], axis=-1)
+        out = relay.op.take(concat, indices=p1)
+
+        f0 = relay.Function([p0, p1], out)
+        f0 = f0.with_attr("Primitive", tvm.tir.IntImm("int32", 1))
+
+        y = relay.Call(f0, [x, c])
+        return relay.Function([x], y)
+
+    orig = before()
+    fuse0(tvm.IRModule.from_expr(orig))

Review comment:
       Can I just remove this? @kazum 




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