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/09/03 17:18:15 UTC

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #6353: [RELAY][DYN] Dynamic UpSampling3D Op

zhiics commented on a change in pull request #6353:
URL: https://github.com/apache/incubator-tvm/pull/6353#discussion_r483136198



##########
File path: tests/python/relay/dyn/test_dynamic_op_level2.py
##########
@@ -52,30 +52,84 @@ def verify_upsampling(dshape, scale_h, scale_w, layout, method, align_corners=Fa
         func = relay.Function([x, scale_h_var, scale_w_var], z)
 
         for target, ctx in ctx_list():
-             if "llvm" not in target: continue
-             for kind in ["vm", "debug"]:
-                 mod = tvm.ir.IRModule.from_expr(func)
-                 intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
-                 op_res = intrp.evaluate()(x_data, np.array(scale_h).astype("float32"), np.array(scale_w).astype("float32"))
-                 tvm.testing.assert_allclose(op_res.asnumpy(), ref_res, rtol=1e-4, atol=1e-6)
-
-    verify_upsampling((1, 16, 32, 32), 2.0, 2.0,"NCHW", "nearest_neighbor")
-    verify_upsampling((1, 16, 32, 32), 2.0, 2.0, "NCHW", "bilinear", True)
-    verify_upsampling((1, 16, 32, 32), 2.0, 2.0, "NHWC", "nearest_neighbor")
+            ##TODO(mbrookhart)(electriclilies): remove when VM supports heterogeneous execution
+            if "llvm" not in target: continue
+            for kind in ["vm", "debug"]:
+                mod = tvm.ir.IRModule.from_expr(func)
+                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
+                op_res = intrp.evaluate()(x_data, np.array(scale_h).astype("float32"), np.array(scale_w).astype("float32"))
+                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res, rtol=1e-4, atol=1e-6)
+
+    verify_upsampling((1, 16, 32, 32), 3, 2.0,"NCHW", "nearest_neighbor")
+    verify_upsampling((1, 16, 32, 32), 5, 2.0, "NCHW", "bilinear", True)
+    verify_upsampling((1, 16, 32, 32), 2.0, 6, "NHWC", "nearest_neighbor")
     verify_upsampling((1, 16, 32, 32), 2.0, 2.0,"NHWC", "bilinear", True)
 
 #tests upsampling type inference with scale_h passed in as a constant and scale_w as a variable
 def test_dyn_upsampling_infer_type_const():
     n, c, h, w = te.size_var("n"), te.size_var("c"), te.size_var("h"), te.size_var("w")
 
     data = relay.var("data", relay.TensorType((n, c, h, w), "int8"))
-    scale_h = relay.Var("scale_h", relay.TensorType((), "float32"))
     scale_w = relay.Var("scale_w", relay.TensorType((), "float32"))
 
     z = relay.nn.upsampling(data, 2.0, scale_w)
     zz = run_infer_type(z)
     assert zz.checked_type == relay.TensorType((n, c, relay.Any(), relay.Any()), "int8")
 
+def test_dyn_upsampling3d_run():
+    def verify_upsampling3d(dshape, scale_d, scale_h, scale_w, layout, method, coord_trans="half_pixel"):
+
+        if layout == "NCDHW":
+            (n, c, d, h, w) = dshape
+            x_data = np.random.uniform(size=(n, c, d, h, w)).astype("float32")
+
+        elif layout == "NDHWC":
+            (n, d, h, w, c) = dshape
+            x_data = np.random.uniform(size=(n, d, h, w, c)).astype("float32")
+
+        if method == "nearest_neighbor":
+            ref_res = tvm.topi.testing.upsampling3d_python(x_data, (scale_d, scale_h, scale_w), layout)
+        else:
+            ref_res = tvm.topi.testing.trilinear_resize3d_python(x_data, (int(round(d*scale_d)),
+                                                                 int(round(h*scale_h)),
+                                                                 int(round(w*scale_w))), layout)
+        x = relay.Var("x", relay.TensorType(dshape, "float32"))
+        scale_d_var = relay.var("scale_d", relay.TensorType((), "float32"))
+        scale_h_var = relay.var("scale_h", relay.TensorType((), "float32"))
+        scale_w_var = relay.var("scale_h", relay.TensorType((), "float32"))
+
+        z = relay.nn.upsampling3d(x, scale_d_var, scale_h_var, scale_w_var, method=method, layout=layout,
+                                coordinate_transformation_mode=coord_trans)
+        zz = run_infer_type(z)
+        func = relay.Function([x, scale_d_var, scale_h_var, scale_w_var], z)
+
+        for target, ctx in ctx_list():
+            ##TODO(mbrookhart)(electriclilies): remove when VM supports heterogeneous execution

Review comment:
       we can try gpu tests now




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