From ae5bb0056931752a1839c1d4398d48f1e17c0cba Mon Sep 17 00:00:00 2001 From: Zhi <5145158+zhiics@users.noreply.github.com> Date: Thu, 30 Apr 2020 10:00:27 -0700 Subject: [PATCH] [Fix] Add ConstantNode to IsAtomic (#5457) * add constantnode to atomic * Add ToANormalForm to FoldConstant --- 3rdparty/dlpack | 2 +- 3rdparty/dmlc-core | 2 +- src/relay/pass/fold_constant.cc | 1 + tests/python/relay/test_pass_fold_constant.py | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/3rdparty/dlpack b/3rdparty/dlpack index 0acb731e0e43d..3ec04430e89a6 160000 --- a/3rdparty/dlpack +++ b/3rdparty/dlpack @@ -1 +1 @@ -Subproject commit 0acb731e0e43d15deee27b66f10e4c5b4e667913 +Subproject commit 3ec04430e89a6834e5a1b99471f415fa939bf642 diff --git a/3rdparty/dmlc-core b/3rdparty/dmlc-core index 808f485387f9a..6c401e242c59a 160000 --- a/3rdparty/dmlc-core +++ b/3rdparty/dmlc-core @@ -1 +1 @@ -Subproject commit 808f485387f9a03f78fa9f1159f387d0d91b7a28 +Subproject commit 6c401e242c59a1f4c913918246591bb13fd714e7 diff --git a/src/relay/pass/fold_constant.cc b/src/relay/pass/fold_constant.cc index b034c5699fe3a..5d3ec03f578fc 100644 --- a/src/relay/pass/fold_constant.cc +++ b/src/relay/pass/fold_constant.cc @@ -184,6 +184,7 @@ class ConstantFolder : public ExprMutator { // Constant evaluate a expression. Expr ConstEvaluate(Expr expr) { std::vector passes = {transform::FuseOps(0), + transform::ToANormalForm(), transform::InferType()}; Function func; if (expr.as()) { diff --git a/tests/python/relay/test_pass_fold_constant.py b/tests/python/relay/test_pass_fold_constant.py index 4752597c828ee..adc3bd401c533 100644 --- a/tests/python/relay/test_pass_fold_constant.py +++ b/tests/python/relay/test_pass_fold_constant.py @@ -29,6 +29,25 @@ def run_opt_pass(expr, opt_pass): return entry if isinstance(expr, relay.Function) else entry.body +def test_concatenate_const(): + def before(): + data = tvm.nd.array(np.array([1.0, 2.0, 3.0])) + const = relay.const(data) + concat = relay.op.concatenate([const, const], axis=0) + func = relay.Function([], concat) + return func + + def expected(): + data = tvm.nd.array(np.array([1.0, 2.0, 3.0, 1.0, 2.0, 3.0])) + const = relay.const(data) + func = relay.Function([], const) + return func + + zz = run_opt_pass(before(), transform.FoldConstant()) + zexpected = run_opt_pass(expected(), transform.InferType()) + assert relay.analysis.alpha_equal(zz, zexpected) + + def test_fold_const(): c_data = np.array([1, 2, 3]).astype("float32") t = relay.TensorType([1, 2, 3], "float32")