From b940fedfed1311d33a87b23660382135bcb824e3 Mon Sep 17 00:00:00 2001 From: Megan Hampton Date: Tue, 19 Sep 2023 21:17:16 -0400 Subject: [PATCH 1/6] Testing backend test --- test/backend/inference_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/backend/inference_backend.py b/test/backend/inference_backend.py index 13f8e20cca..076f5d511c 100644 --- a/test/backend/inference_backend.py +++ b/test/backend/inference_backend.py @@ -774,7 +774,7 @@ def get_test_models(): # ==LIM== do_not_keep_dim not supported. #"test_reduce_log_sum_desc_axes_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, #"test_reduce_log_sum_asc_axes_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, - #"test_reduce_log_sum_default_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, + "test_reduce_log_sum_default_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, "test_reduce_log_sum_negative_axes_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, # Name changed in v13 # "test_reduce_log_sum_default_expanded_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, From b2cb7e1fd94f256e9216834b6fd1d565214c0d52 Mon Sep 17 00:00:00 2001 From: Megan Hampton Date: Wed, 20 Sep 2023 16:23:07 -0400 Subject: [PATCH 2/6] Enable constant prop for backend tests --- docker/Dockerfile.onnx-mlir | 6 ++++++ docker/Dockerfile.onnx-mlir-dev | 6 ++++++ test/backend/common.py | 4 +++- test/backend/inference_backend.py | 15 ++++++++++++--- test/backend/variables.py | 11 ++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile.onnx-mlir b/docker/Dockerfile.onnx-mlir index 558e2b0d2b..c17d6b1936 100644 --- a/docker/Dockerfile.onnx-mlir +++ b/docker/Dockerfile.onnx-mlir @@ -26,6 +26,7 @@ RUN ONNX_ROOT=${WORK_DIR}/onnx-mlir/third_party/onnx \ ARG NPROC=4 ARG ACCEL=NNPA ARG TEST_NOFLOAT16 +ARG TEST_CONSTANT_PROP ARG TEST_MCPU ARG KEEPSRC @@ -55,6 +56,10 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \ && TEST_MCPU=${TEST_MCPU:-$([ "$(uname -m)" = "s390x" ] && echo z14 || \ ([ "$(uname -m)" = "x86_64" ] && echo || \ ([ "$(uname -m)" = "ppc64le" ] && echo || echo)))} \ +# Enable Constant Propagation + && TEST_CONSTANT_PROP=${TEST_CONSTANT_PROP:-$([ "$(uname -m)" = "s390x" ] && echo true || \ + ([ "$(uname -m)" = "x86_64" ] && echo true || \ + ([ "$(uname -m)" = "ppc64le" ] && echo true || echo true)))} \ && TEST_ARGS="-mcpu=${TEST_MCPU}" \ && make check-docs \ && make check-unittest \ @@ -64,6 +69,7 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \ TEST_NOFLOAT16=${TEST_NOFLOAT16} \ TEST_MCPU=${TEST_MCPU} \ TEST_ARGS="${TEST_ARGS}" \ + TEST_CONSTANT_PROP=${TEST_CONSTANT_PROP} \ -j${NPROC} \ check-onnx-backend-numerical \ && make -j${NPROC} install \ diff --git a/docker/Dockerfile.onnx-mlir-dev b/docker/Dockerfile.onnx-mlir-dev index 574737c1a9..a43690ab72 100644 --- a/docker/Dockerfile.onnx-mlir-dev +++ b/docker/Dockerfile.onnx-mlir-dev @@ -21,6 +21,7 @@ ARG NPROC=4 ARG ACCEL=NNPA ARG TEST_NOFLOAT16 ARG TEST_MCPU +ARG TEST_CONSTANT_PROP RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \ && ONNX_MLIR_ROOT=${WORK_DIR}/onnx-mlir \ @@ -54,6 +55,10 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \ && TEST_MCPU=$([ "$(uname -m)" = "s390x" ] && echo || \ ([ "$(uname -m)" = "x86_64" ] && echo || \ ([ "$(uname -m)" = "ppc64le" ] && echo || echo))) \ +# Enable Constant Propagation + && TEST_CONSTANT_PROP=${TEST_CONSTANT_PROP:-$([ "$(uname -m)" = "s390x" ] && echo true || \ + ([ "$(uname -m)" = "x86_64" ] && echo true || \ + ([ "$(uname -m)" = "ppc64le" ] && echo true || echo true)))} \ && TEST_ARGS="-mcpu=${TEST_MCPU}" \ && TEST_OPTLEVEL=0 \ && make check-docs \ @@ -65,6 +70,7 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \ TEST_MCPU=${TEST_MCPU} \ TEST_ARGS="${TEST_ARGS}" \ TEST_OPTLEVEL=${TEST_OPTLEVEL} \ + TEST_CONSTANT_PROP=${TEST_CONSTANT_PROP} \ -j${NPROC} \ check-onnx-backend-numerical \ && rm -f Debug/bin/*Test Debug/bin/Perf* Debug/bin/Test* \ diff --git a/test/backend/common.py b/test/backend/common.py index a629337ac0..9dc7db42a9 100644 --- a/test/backend/common.py +++ b/test/backend/common.py @@ -2,7 +2,7 @@ ##################### common.py ################################################ # -# Copyright 2021-2022 The IBM Research Authors. +# Copyright 2021-2023 The IBM Research Authors. # ################################################################################ # commom function `compile_model` called by both @@ -125,6 +125,8 @@ def compile_model(model, emit): if args.constants_to_file_total_threshold: command_list.append("--constants-to-file-total-threshold=" + str(args.constants_to_file_total_threshold)) + if args.enable_constant_prop: + command_list.append("--enable-constant-prop=true") command_list.append(target[emit]) command_list.append(model_name) diff --git a/test/backend/inference_backend.py b/test/backend/inference_backend.py index 076f5d511c..b09de94f73 100644 --- a/test/backend/inference_backend.py +++ b/test/backend/inference_backend.py @@ -771,13 +771,13 @@ def get_test_models(): # ==OP== ReduceLogSum # ==MIN== 13 - # ==LIM== do_not_keep_dim not supported. + # ==LIM== do_not_keep_dim not supported. Enable constant propagation #"test_reduce_log_sum_desc_axes_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, #"test_reduce_log_sum_asc_axes_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, - "test_reduce_log_sum_default_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, + "test_reduce_log_sum_default_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}, ENABLE_CONST_PROP:{}}, "test_reduce_log_sum_negative_axes_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, # Name changed in v13 - # "test_reduce_log_sum_default_expanded_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}}, + "test_reduce_log_sum_default_expanded_cpu": {STATIC_SHAPE:{}, DYNAMIC_SHAPE:{-1:{-1}}, CONSTANT_INPUT:{-1}, ENABLE_CONST_PROP:{}}, # ==OP== ReduceL1 # ==MIN== 13 @@ -1297,6 +1297,15 @@ def get_test_models(): node_test_to_enable = variables.node_test_for_constants_to_file model_test_to_enable = variables.model_test_for_constants_to_file test_to_enable = variables.test_for_constants_to_file + + #Enable Constant Propagation so that several backend test may pass + if args.enable_constant_prop: + if args.verbose: + print("constant propagation is enabled", file=sys.stderr) + node_test_to_enable = variables.node_test_for_enable_const_prop + model_test_to_enable = variables.model_test_for_enable_const_prop + test_to_enable = variables.test_for_enable_const_prop + # Build check-onnx-backend with env TEST_NOFLOAT16=true to set args.nofloat16 # on platforms like IBM Z and Linux x86_64 where LLVM float16 conversions don't yet work. diff --git a/test/backend/variables.py b/test/backend/variables.py index dfb0e2b308..f83556d109 100644 --- a/test/backend/variables.py +++ b/test/backend/variables.py @@ -2,7 +2,7 @@ ############################ variables.py ##################################### # -# Copyright 2021-2022 The IBM Research Authors. +# Copyright 2021-2023 The IBM Research Authors. # ################################################################################ # Immutable global variables: @@ -55,6 +55,7 @@ def get_args_from_env(): TEST_INSTRUCTION_CHECK = os.getenv("TEST_INSTRUCTION_CHECK") TEST_CONSTANTS_TO_FILE = os.getenv("TEST_CONSTANTS_TO_FILE") TEST_NOFLOAT16 = os.getenv("TEST_NOFLOAT16") + TEST_CONSTANT_PROP= os.getenv("TEST_CONSTANT_PROP") # Set ONNX_HOME to /tmp if not set to prevent onnx from downloading # real model files into home directory. @@ -86,6 +87,13 @@ def get_args_from_env(): default=(strtobool(TEST_CONSTANTS_TO_FILE) if TEST_CONSTANTS_TO_FILE else False), help="whether store constants to file or not, passed to the compiler", ) + parser.add_argument( + "--enable_constant_prop", + action="store_true", + default=(strtobool(TEST_CONSTANT_PROP) if TEST_CONSTANT_PROP else False), + help="enable constant propagation", + ) + parser.add_argument( "--nofloat16", action="store_true", @@ -270,6 +278,7 @@ def get_runtime_vars(): CONSTANT_INPUT = "constant" CONSTANTS_TO_FILE = "constants_to_file" FLOAT16 = "float16" +ENABLE_CONST_PROP = "enable_constant_prop" ### immutable variables ### From 82d3b2fdfb8c1f72df1970691937569e34c79bf4 Mon Sep 17 00:00:00 2001 From: Megan Hampton Date: Wed, 20 Sep 2023 16:51:51 -0400 Subject: [PATCH 3/6] Fix variable name --- test/backend/inference_backend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/backend/inference_backend.py b/test/backend/inference_backend.py index b09de94f73..48fc29dee2 100644 --- a/test/backend/inference_backend.py +++ b/test/backend/inference_backend.py @@ -1302,9 +1302,9 @@ def get_test_models(): if args.enable_constant_prop: if args.verbose: print("constant propagation is enabled", file=sys.stderr) - node_test_to_enable = variables.node_test_for_enable_const_prop - model_test_to_enable = variables.model_test_for_enable_const_prop - test_to_enable = variables.test_for_enable_const_prop + node_test_to_enable = variables.node_test_for_enable_constant_prop + model_test_to_enable = variables.model_test_for_enable_constant_prop + test_to_enable = variables.test_for_enable_constant_prop # Build check-onnx-backend with env TEST_NOFLOAT16=true to set args.nofloat16 From a629a1ff64a1a9ac59d931bd8bf25a2490b457b8 Mon Sep 17 00:00:00 2001 From: Megan Hampton Date: Wed, 20 Sep 2023 18:58:25 -0400 Subject: [PATCH 4/6] Remove test --- test/backend/inference_backend.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/backend/inference_backend.py b/test/backend/inference_backend.py index 48fc29dee2..38ffd73cd1 100644 --- a/test/backend/inference_backend.py +++ b/test/backend/inference_backend.py @@ -1297,15 +1297,6 @@ def get_test_models(): node_test_to_enable = variables.node_test_for_constants_to_file model_test_to_enable = variables.model_test_for_constants_to_file test_to_enable = variables.test_for_constants_to_file - - #Enable Constant Propagation so that several backend test may pass - if args.enable_constant_prop: - if args.verbose: - print("constant propagation is enabled", file=sys.stderr) - node_test_to_enable = variables.node_test_for_enable_constant_prop - model_test_to_enable = variables.model_test_for_enable_constant_prop - test_to_enable = variables.test_for_enable_constant_prop - # Build check-onnx-backend with env TEST_NOFLOAT16=true to set args.nofloat16 # on platforms like IBM Z and Linux x86_64 where LLVM float16 conversions don't yet work. From 99eb04d2a9fc42857f1514a120e30fa9ded8fd99 Mon Sep 17 00:00:00 2001 From: hamptonm1 <79232909+hamptonm1@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:01:58 -0400 Subject: [PATCH 5/6] Simplify argument --- docker/Dockerfile.onnx-mlir | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docker/Dockerfile.onnx-mlir b/docker/Dockerfile.onnx-mlir index c17d6b1936..b176f702e9 100644 --- a/docker/Dockerfile.onnx-mlir +++ b/docker/Dockerfile.onnx-mlir @@ -26,7 +26,7 @@ RUN ONNX_ROOT=${WORK_DIR}/onnx-mlir/third_party/onnx \ ARG NPROC=4 ARG ACCEL=NNPA ARG TEST_NOFLOAT16 -ARG TEST_CONSTANT_PROP +ARG TEST_CONSTANT_PROP=true ARG TEST_MCPU ARG KEEPSRC @@ -56,10 +56,6 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \ && TEST_MCPU=${TEST_MCPU:-$([ "$(uname -m)" = "s390x" ] && echo z14 || \ ([ "$(uname -m)" = "x86_64" ] && echo || \ ([ "$(uname -m)" = "ppc64le" ] && echo || echo)))} \ -# Enable Constant Propagation - && TEST_CONSTANT_PROP=${TEST_CONSTANT_PROP:-$([ "$(uname -m)" = "s390x" ] && echo true || \ - ([ "$(uname -m)" = "x86_64" ] && echo true || \ - ([ "$(uname -m)" = "ppc64le" ] && echo true || echo true)))} \ && TEST_ARGS="-mcpu=${TEST_MCPU}" \ && make check-docs \ && make check-unittest \ From 7d5d713c19beabed576fe4b9d1de8de35d2828d8 Mon Sep 17 00:00:00 2001 From: hamptonm1 <79232909+hamptonm1@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:02:32 -0400 Subject: [PATCH 6/6] Simplify argument --- docker/Dockerfile.onnx-mlir-dev | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docker/Dockerfile.onnx-mlir-dev b/docker/Dockerfile.onnx-mlir-dev index a43690ab72..fe18cbe5b8 100644 --- a/docker/Dockerfile.onnx-mlir-dev +++ b/docker/Dockerfile.onnx-mlir-dev @@ -21,7 +21,7 @@ ARG NPROC=4 ARG ACCEL=NNPA ARG TEST_NOFLOAT16 ARG TEST_MCPU -ARG TEST_CONSTANT_PROP +ARG TEST_CONSTANT_PROP=true RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \ && ONNX_MLIR_ROOT=${WORK_DIR}/onnx-mlir \ @@ -55,10 +55,6 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \ && TEST_MCPU=$([ "$(uname -m)" = "s390x" ] && echo || \ ([ "$(uname -m)" = "x86_64" ] && echo || \ ([ "$(uname -m)" = "ppc64le" ] && echo || echo))) \ -# Enable Constant Propagation - && TEST_CONSTANT_PROP=${TEST_CONSTANT_PROP:-$([ "$(uname -m)" = "s390x" ] && echo true || \ - ([ "$(uname -m)" = "x86_64" ] && echo true || \ - ([ "$(uname -m)" = "ppc64le" ] && echo true || echo true)))} \ && TEST_ARGS="-mcpu=${TEST_MCPU}" \ && TEST_OPTLEVEL=0 \ && make check-docs \