From d37c22d4feb689aa086033faabf665fa2ed8f9b5 Mon Sep 17 00:00:00 2001 From: Luke Hutton Date: Thu, 20 Oct 2022 12:06:22 +0000 Subject: [PATCH 1/2] [ETHOSN] Consolidate target string usage Removes support for a deprecated target string. The deprecation warning has been around for a couple of releases now so it should be safe to remove. The target to use moving forward is: `ethos-n -variant=n78 ...` Refactored direct use of a driver stack target string in the testing infrastructure to use the same string we expect users to provide. This simplified some of the code in codegen and hopefully avoids confusion in the future. Change-Id: Ic50842e15725d6440efc1ab525ac7dd9a4068ac4 --- python/tvm/driver/tvmc/composite_target.py | 12 --- python/tvm/relay/op/contrib/ethosn.py | 17 +--- src/relay/backend/contrib/ethosn/codegen.cc | 85 ++++++++----------- .../backend/contrib/ethosn/codegen_ethosn.h | 9 +- .../contrib/test_ethosn/infrastructure.py | 38 +++++---- .../contrib/test_ethosn/test_codegen.py | 49 +++++++++++ .../test_ethosn/test_partition_params.py | 82 ------------------ tests/scripts/task_python_ethosn_tests.sh | 7 +- 8 files changed, 114 insertions(+), 185 deletions(-) create mode 100644 tests/python/contrib/test_ethosn/test_codegen.py delete mode 100644 tests/python/contrib/test_ethosn/test_partition_params.py diff --git a/python/tvm/driver/tvmc/composite_target.py b/python/tvm/driver/tvmc/composite_target.py index 88bea9980014..a7087ea9239f 100644 --- a/python/tvm/driver/tvmc/composite_target.py +++ b/python/tvm/driver/tvmc/composite_target.py @@ -18,7 +18,6 @@ Provides support to composite target on TVMC. """ import logging -import warnings # Make sure Vitis AI codegen is registered import tvm.contrib.target.vitis_ai # pylint: disable=unused-import @@ -72,11 +71,6 @@ "config_key": "relay.ext.vitis_ai.options", "pass_pipeline": partition_for_vitis_ai, }, - # Deprecated in favour of "ethos-n". - "ethos-n78": { - "config_key": "relay.ext.ethos-n.options", - "pass_pipeline": partition_for_ethosn, - }, } @@ -105,12 +99,6 @@ def get_codegen_by_target(name): requested target codegen information """ try: - if name == "ethos-n78": - warnings.warn( - "Please use 'ethos-n' instead of the deprecated 'ethos-n78' target, " - "which will be removed in a later release of TVM.", - DeprecationWarning, - ) return REGISTERED_CODEGEN[name] except KeyError: raise TVMCException("Composite target %s is not defined in TVMC." % name) diff --git a/python/tvm/relay/op/contrib/ethosn.py b/python/tvm/relay/op/contrib/ethosn.py index 9afab68ccd8f..bbe95dac9bba 100644 --- a/python/tvm/relay/op/contrib/ethosn.py +++ b/python/tvm/relay/op/contrib/ethosn.py @@ -17,7 +17,6 @@ # pylint: disable=invalid-name, unused-argument """Arm(R) Ethos(TM)-N NPU supported operators.""" from enum import Enum -import warnings from distutils.version import LooseVersion import tvm.ir @@ -97,6 +96,8 @@ def is_inline_non_compute_intensive_partitions_enabled() -> bool: True if inlining should happen, False if not. """ compiler_attrs = tvm.get_global_func("relay.ext.ethos-n.get_compiler_attrs")() + if not compiler_attrs: + return False return compiler_attrs.inline_non_compute_intensive_partitions @@ -115,20 +116,6 @@ def partition_for_ethosn(mod, params=None, **opts): ------- ret : annotated and partitioned module. """ - opts = opts or {} - if "variant" not in opts: - raise ValueError("Please specify a variant in the target string, e.g. -variant=n78.") - - # -variant=ethos-n78 deprecated in favour of -variant=n78 - if opts["variant"].lower() == "ethos-n78": - warnings.warn( - "Please use '-variant=n78' instead of the deprecated " - "'-variant=ethos-n78', which will be removed in TVM v0.9.", - DeprecationWarning, - ) - elif opts["variant"] != "n78": - raise ValueError("When targeting Ethos(TM)-N78, -variant=n78 should be set.") - api_version = ethosn_api_version() supported_api_versions = ["3.1.0"] if all(api_version != LooseVersion(exp_ver) for exp_ver in supported_api_versions): diff --git a/src/relay/backend/contrib/ethosn/codegen.cc b/src/relay/backend/contrib/ethosn/codegen.cc index d2281f782615..edf7caca820d 100644 --- a/src/relay/backend/contrib/ethosn/codegen.cc +++ b/src/relay/backend/contrib/ethosn/codegen.cc @@ -226,36 +226,27 @@ sl::TensorsAndId MakeOps(const sl::TensorAndId& op) { return ops; } -String MakeVariant(Optional configuration) { - String variant = configuration.value()->variant; - // Transform variant string to lowercase for comparison - std::string variant_string = variant.c_str(); - - // Checking deprecated variant format. Support for specifying - // the variant in this way only remains for backwards compatibility - // and will be removed in a later release of TVM. - std::string deprecated_variant_string = variant_string; - std::transform(deprecated_variant_string.begin(), deprecated_variant_string.end(), - deprecated_variant_string.begin(), ::tolower); - if (variant_string == "n78" || deprecated_variant_string == "ethos-n78") { - String tops = configuration.value()->tops; - String ple_ratio = configuration.value()->ple_ratio; - variant = "Ethos-N78_" + tops + "TOPS_" + ple_ratio + "PLE_RATIO"; - } - return variant; +sl::EthosNVariant MakeVariant(EthosnCompilerConfig configuration) { + String variant = configuration->variant; + String tops = configuration->tops; + String ple_ratio = configuration->ple_ratio; + + std::string capitalized_variant = variant; + std::transform(capitalized_variant.begin(), capitalized_variant.end(), + capitalized_variant.begin(), ::toupper); + std::string sl_variant_string = + "Ethos-" + capitalized_variant + "_" + tops + "TOPS_" + ple_ratio + "PLE_RATIO"; + return sl::EthosNVariantFromString(sl_variant_string.c_str()); } NetworkWithIDs ConstructNetworkVisitor::Construct(const Function& func) { // Initialise everything - auto ctx = transform::PassContext::Current(); - auto cfg = ctx->GetConfig("relay.ext.ethos-n.options"); - if (!cfg.defined()) { - cfg = AttrsWithDefaultValues(); - } + EthosnCompilerConfig cfg = GetCompilerAttrs(); + sl::EthosNVariant variant = MakeVariant(cfg); + NetworkWithIDs network_with_ids; network_ = sl::CreateNetwork( - sl::GetFwAndHwCapabilities(sl::EthosNVariantFromString(MakeVariant(cfg).c_str()), - static_cast(std::stoul(cfg.value()->sram_size)))); + sl::GetFwAndHwCapabilities(variant, static_cast(std::stoul(cfg->sram_size)))); network_with_ids.network = network_; operand_table_.clear(); @@ -744,28 +735,24 @@ runtime::ethosn::OrderedCompiledNetwork EthosnCompiler::CompileEthosnFunc(const } sl::CompilationOptions EthosnCompiler::CreateOptions() { - auto ctx = transform::PassContext::Current(); - auto cfg = ctx->GetConfig("relay.ext.ethos-n.options"); - if (!cfg.defined()) { - cfg = AttrsWithDefaultValues(); - } + EthosnCompilerConfig cfg = GetCompilerAttrs(); sl::CompilationOptions options; - options.m_Strategy0 = cfg.value()->strategy0; - options.m_Strategy1 = cfg.value()->strategy1; - options.m_Strategy3 = cfg.value()->strategy3; - options.m_Strategy4 = cfg.value()->strategy4; - options.m_Strategy6 = cfg.value()->strategy6; - options.m_Strategy7 = cfg.value()->strategy7; - options.m_DebugInfo.m_DumpRam = cfg.value()->dump_ram; - options.m_DebugInfo.m_InitialSramDump = cfg.value()->initial_sram_dump; - options.m_BlockConfig16x16 = cfg.value()->block_config_16x16; - options.m_BlockConfig32x8 = cfg.value()->block_config_32x8; - options.m_BlockConfig8x32 = cfg.value()->block_config_8x32; - options.m_BlockConfig8x8 = cfg.value()->block_config_8x8; - options.m_EnableIntermediateCompression = cfg.value()->enable_intermediate_compression; - options.m_DisableWinograd = cfg.value()->disable_winograd; - options.m_DebugInfo.m_DebugDir = cfg.value()->debug_dir; + options.m_Strategy0 = cfg->strategy0; + options.m_Strategy1 = cfg->strategy1; + options.m_Strategy3 = cfg->strategy3; + options.m_Strategy4 = cfg->strategy4; + options.m_Strategy6 = cfg->strategy6; + options.m_Strategy7 = cfg->strategy7; + options.m_DebugInfo.m_DumpRam = cfg->dump_ram; + options.m_DebugInfo.m_InitialSramDump = cfg->initial_sram_dump; + options.m_BlockConfig16x16 = cfg->block_config_16x16; + options.m_BlockConfig32x8 = cfg->block_config_32x8; + options.m_BlockConfig8x32 = cfg->block_config_8x32; + options.m_BlockConfig8x8 = cfg->block_config_8x8; + options.m_EnableIntermediateCompression = cfg->enable_intermediate_compression; + options.m_DisableWinograd = cfg->disable_winograd; + options.m_DebugInfo.m_DebugDir = cfg->debug_dir; return options; } @@ -806,12 +793,10 @@ std::unique_ptr EthosnCompiler::m_Queries; EthosnError EthosnCompiler::SupportedSetup() { if (m_Queries == nullptr) { - auto ctx = transform::PassContext::Current(); - auto cfg = ctx->GetConfig("relay.ext.ethos-n.options").defined() - ? ctx->GetConfig("relay.ext.ethos-n.options") - : AttrsWithDefaultValues(); - m_Queries = std::make_unique(sl::GetFwAndHwCapabilities( - sl::EthosNVariantFromString(MakeVariant(cfg).c_str()), std::stoul(cfg.value()->sram_size))); + EthosnCompilerConfig cfg = GetCompilerAttrs(); + sl::EthosNVariant variant = MakeVariant(cfg); + m_Queries = std::make_unique( + sl::GetFwAndHwCapabilities(variant, std::stoul(cfg->sram_size))); if (m_Queries == nullptr) { return EthosnError("Could not initialise Arm(R) Ethos(TM)-N compiler isSupported"); } diff --git a/src/relay/backend/contrib/ethosn/codegen_ethosn.h b/src/relay/backend/contrib/ethosn/codegen_ethosn.h index c640db47b6dd..7c52da713c5c 100644 --- a/src/relay/backend/contrib/ethosn/codegen_ethosn.h +++ b/src/relay/backend/contrib/ethosn/codegen_ethosn.h @@ -296,13 +296,14 @@ class EthosnCompilerConfig : public Attrs { TVM_REGISTER_NODE_TYPE(EthosnCompilerConfigNode); TVM_REGISTER_PASS_CONFIG_OPTION("relay.ext.ethos-n.options", EthosnCompilerConfig); -auto GetCompilerAttrs() { +EthosnCompilerConfig GetCompilerAttrs() { auto ctx = transform::PassContext::Current(); - auto cfg = ctx->GetConfig("relay.ext.ethos-n.options"); + Optional cfg = + ctx->GetConfig("relay.ext.ethos-n.options"); if (!cfg.defined()) { - cfg = AttrsWithDefaultValues(); + return AttrsWithDefaultValues(); } - return cfg; + return cfg.value(); } TVM_REGISTER_GLOBAL("relay.ext.ethos-n.get_compiler_attrs").set_body_typed(GetCompilerAttrs); diff --git a/tests/python/contrib/test_ethosn/infrastructure.py b/tests/python/contrib/test_ethosn/infrastructure.py index 85ebd98efcff..334cd6d3b87c 100644 --- a/tests/python/contrib/test_ethosn/infrastructure.py +++ b/tests/python/contrib/test_ethosn/infrastructure.py @@ -31,6 +31,7 @@ from tvm import relay from tvm.contrib import utils, graph_executor, download from tvm.relay.op.contrib import partition_for_ethosn +from tvm.driver.tvmc.target import parse_target from . import _infrastructure @@ -143,7 +144,9 @@ def visit_call(self, call): return c.count -def build(mod, params, npu=True, expected_host_ops=0, npu_partitions=1, optimize_partitions=True): +def build( + mod, params, npu=True, expected_host_ops=0, npu_partitions=1, additional_config_args=None +): """Build a network with or without Ethos-N offloading. Parameters @@ -158,22 +161,17 @@ def build(mod, params, npu=True, expected_host_ops=0, npu_partitions=1, optimize The number of ops expected to remain on the host. npu_partitions : int, optional The number of Ethos-N partitions expected. - optimize_partitions : bool, optional - Disable the pass that optimizes NPU partitions post partitioning. + additional_config_args : dict, optional + Additional compiler config options for the NPU. """ relay.backend.te_compiler.get().clear() - with tvm.transform.PassContext( - opt_level=3, - config={ - "relay.ext.ethos-n.options": { - "variant": get_ethosn_variant(), - "inline_non_compute_intensive_partitions": optimize_partitions, - } - }, - ): + if not additional_config_args: + additional_config_args = {} + npu_config = {**get_ethosn_device_options(), **additional_config_args} + with tvm.transform.PassContext(opt_level=3, config={"relay.ext.ethos-n.options": npu_config}): with tvm.target.Target("llvm"): if npu: - mod = partition_for_ethosn(mod, params, variant="n78") + mod = partition_for_ethosn(mod, params) host_op_count = get_host_op_count(mod) assert ( host_op_count == expected_host_ops @@ -244,12 +242,12 @@ def build_and_run( npu=True, expected_host_ops=0, npu_partitions=1, - optimize_partitions=True, + additional_config_args=None, ): """ Convenient wrapper for building and running a module on the NPU. """ - lib = build(mod, params, npu, expected_host_ops, npu_partitions, optimize_partitions) + lib = build(mod, params, npu, expected_host_ops, npu_partitions, additional_config_args) return run(lib, inputs, outputs, npu) @@ -285,7 +283,7 @@ def test_error(mod, params, err_msg): caught = None with tvm.transform.PassContext( - opt_level=3, config={"relay.ext.ethos-n.options": {"variant": get_ethosn_variant()}} + opt_level=3, config={"relay.ext.ethos-n.options": get_ethosn_device_options()} ): with tvm.target.Target("llvm"): try: @@ -403,5 +401,9 @@ def get_same_padding( return (pad_top, pad_left, pad_bottom, pad_right) -def get_ethosn_variant(): - return os.getenv("ETHOSN_VARIANT_CONFIG", default="Ethos-N78_1TOPS_2PLE_RATIO") +def get_ethosn_device_options(): + """Determine the NPU configuration used for testing.""" + default_target_string = "ethos-n -variant=n78 -tops=1 -ple_ratio=2" + target_string = os.getenv("ETHOSN_TEST_TARGET_CONFIG", default_target_string) + target = parse_target(target_string) + return target[0]["opts"] diff --git a/tests/python/contrib/test_ethosn/test_codegen.py b/tests/python/contrib/test_ethosn/test_codegen.py new file mode 100644 index 000000000000..89b383fe836e --- /dev/null +++ b/tests/python/contrib/test_ethosn/test_codegen.py @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""NPU codegen tests""" + +import pytest +import numpy as np + +import tvm +from tvm import relay +from tvm.testing import requires_ethosn + +from . import infrastructure as tei + + +@requires_ethosn +def test_compile_with_unsupported_variant(): + """Test compilation with unsupported variant.""" + dtype = "int8" + input_shape = (1, 2, 2, 2) + + x = relay.var("x", shape=input_shape, dtype=dtype) + y = relay.reshape(x, newshape=(1, 1, 1, 8)) + mod = tei.make_ethosn_partition(y) + + additional_config_args = {"variant": "foo"} + + inputs = { + "x": np.random.randint( + low=np.iinfo(dtype).min, high=np.iinfo(dtype).max, size=input_shape, dtype=dtype + ) + } + + with pytest.raises(tvm.TVMError, match=r"Unknown NPU type"): + tei.build_and_run(mod, inputs, 1, {}, True, additional_config_args=additional_config_args) diff --git a/tests/python/contrib/test_ethosn/test_partition_params.py b/tests/python/contrib/test_ethosn/test_partition_params.py deleted file mode 100644 index e8ac687c04b0..000000000000 --- a/tests/python/contrib/test_ethosn/test_partition_params.py +++ /dev/null @@ -1,82 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -"""Arm(R) Ethos(TM)-N partition parameter tests""" - -import pytest -import numpy as np - -import tvm -from tvm import relay -from tvm.relay.op.contrib.ethosn import partition_for_ethosn -from tvm.testing import requires_ethosn - - -@requires_ethosn -def test_ethosn78_partition_no_error(): - """Test Arm(R) Ethos(TM)-N78 partition""" - - a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") - weights = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) - res = relay.nn.conv2d( - a, weights, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8" - ) - b = relay.var("b", shape=[8], dtype="uint8") - res = relay.nn.bias_add(res, b, axis=1) - - mod = tvm.IRModule.from_expr(res) - opts = {"variant": "n78"} - partition_for_ethosn(mod, **opts) - - -@requires_ethosn -def test_ethosn78_partition_undefined_variant(): - """Test Arm(R) Ethos(TM)-N78 partition with undefined variant""" - - with pytest.raises( - ValueError, match=r".*Please specify a variant in the target string, e.g. -variant=n78.*" - ): - a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") - weights = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) - res = relay.nn.conv2d( - a, weights, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8" - ) - b = relay.var("b", shape=[8], dtype="uint8") - res = relay.nn.bias_add(res, b, axis=1) - - mod = tvm.IRModule.from_expr(res) - partition_for_ethosn(mod) - - -@requires_ethosn -def test_ethosn78_partition_invalid_variant(): - """Test Arm(R) Ethos(TM)-N78 partition with invalid variant""" - - with pytest.raises( - ValueError, match=r".*When targeting Ethos\(TM\)-N78, -variant=n78 should be set.*" - ): - a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") - wwights = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) - res = relay.nn.conv2d( - a, wwights, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8" - ) - b = relay.var("b", shape=[8], dtype="uint8") - res = relay.nn.bias_add(res, b, axis=1) - - mod = tvm.IRModule.from_expr(res) - opts = {"variant": "Ethos-N"} - partition_for_ethosn(mod, **opts) diff --git a/tests/scripts/task_python_ethosn_tests.sh b/tests/scripts/task_python_ethosn_tests.sh index d49b8518a4ad..812c02798da8 100755 --- a/tests/scripts/task_python_ethosn_tests.sh +++ b/tests/scripts/task_python_ethosn_tests.sh @@ -27,8 +27,7 @@ source tests/scripts/setup-pytest-env.sh find . -type f -path "*.pyc" | xargs rm -f make cython3 -# Note: Default behaviour is to assume the test target is Ethos-N78 -# but setting ETHOSN_VARIANT_CONFIG appropriately -# (e.g. ETHOSN_VARIANT_CONFIG=Ethos-N78_1TOPS_2PLE_RATIO) -# switches the target to various Ethos-N78 configurations. +# Note: Setting ETHOSN_TEST_TARGET_CONFIG appropriately +# (e.g. ETHOSN_TEST_TARGET_CONFIG="ethos-n -variant=n78 -tops=1 -ple_ratio=2") +# switches the target to various NPU configurations. run_pytest ctypes python-ethosn tests/python/contrib/test_ethosn From 6242010a5aeefb1e110b1aadaff4011884b9bcd7 Mon Sep 17 00:00:00 2001 From: Luke Hutton Date: Mon, 7 Nov 2022 11:04:11 +0000 Subject: [PATCH 2/2] rebase Change-Id: I0258e6144bad5cde5662091c637111fb3151db60 --- .../contrib/test_ethosn/infrastructure.py | 1 + .../contrib/test_ethosn/test_addition.py | 22 ++++++++++-- .../contrib/test_ethosn/test_codegen.py | 5 ++- .../contrib/test_ethosn/test_concatenate.py | 11 +++++- .../test_ethosn/test_depth_to_space.py | 11 +++++- .../contrib/test_ethosn/test_leaky_relu.py | 11 +++++- .../contrib/test_ethosn/test_multiply.py | 9 ++++- tests/python/contrib/test_ethosn/test_relu.py | 11 +++++- .../contrib/test_ethosn/test_requantize.py | 18 ++++++++-- .../contrib/test_ethosn/test_reshape.py | 17 +++++++-- .../python/contrib/test_ethosn/test_split.py | 9 ++++- tests/python/contrib/test_ethosn/test_tanh.py | 11 +++++- .../contrib/test_ethosn/test_topologies.py | 35 +++++++++++++++---- 13 files changed, 151 insertions(+), 20 deletions(-) diff --git a/tests/python/contrib/test_ethosn/infrastructure.py b/tests/python/contrib/test_ethosn/infrastructure.py index 334cd6d3b87c..8a469403872f 100644 --- a/tests/python/contrib/test_ethosn/infrastructure.py +++ b/tests/python/contrib/test_ethosn/infrastructure.py @@ -168,6 +168,7 @@ def build( if not additional_config_args: additional_config_args = {} npu_config = {**get_ethosn_device_options(), **additional_config_args} + print(npu_config) with tvm.transform.PassContext(opt_level=3, config={"relay.ext.ethos-n.options": npu_config}): with tvm.target.Target("llvm"): if npu: diff --git a/tests/python/contrib/test_ethosn/test_addition.py b/tests/python/contrib/test_ethosn/test_addition.py index 53afd01b8449..9841e798aff4 100644 --- a/tests/python/contrib/test_ethosn/test_addition.py +++ b/tests/python/contrib/test_ethosn/test_addition.py @@ -111,7 +111,16 @@ def test_addition(dtype, shape): model = _get_model(shape, shape, lhs_zp, lhs_sc, rhs_zp, rhs_sc, out_zp, out_sc, dtype) for npu in [False, True]: mod = tei.make_module(model, []) - outputs.append(tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 1) @@ -227,7 +236,16 @@ def test_addition_to_reinterpret_quantize(lhs_shape, lhs_is_constant, rhs_shape, outputs = [] for npu in [False, True]: mod = tei.make_module(model, {}) - outputs.append(tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 1) diff --git a/tests/python/contrib/test_ethosn/test_codegen.py b/tests/python/contrib/test_ethosn/test_codegen.py index 89b383fe836e..c50dfb7963d3 100644 --- a/tests/python/contrib/test_ethosn/test_codegen.py +++ b/tests/python/contrib/test_ethosn/test_codegen.py @@ -37,7 +37,10 @@ def test_compile_with_unsupported_variant(): y = relay.reshape(x, newshape=(1, 1, 1, 8)) mod = tei.make_ethosn_partition(y) - additional_config_args = {"variant": "foo"} + additional_config_args = { + "variant": "foo", + "inline_non_compute_intensive_partitions": False, + } inputs = { "x": np.random.randint( diff --git a/tests/python/contrib/test_ethosn/test_concatenate.py b/tests/python/contrib/test_ethosn/test_concatenate.py index f8521b595060..83e84046d0a6 100644 --- a/tests/python/contrib/test_ethosn/test_concatenate.py +++ b/tests/python/contrib/test_ethosn/test_concatenate.py @@ -76,7 +76,16 @@ def test_concatenate(dtype, shapes, axis): for npu in [False, True]: model = _get_model(shapes, dtype, axis) mod = tei.make_module(model, {}) - outputs.append(tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 0) diff --git a/tests/python/contrib/test_ethosn/test_depth_to_space.py b/tests/python/contrib/test_ethosn/test_depth_to_space.py index 814693b664ca..7bbd532241fd 100644 --- a/tests/python/contrib/test_ethosn/test_depth_to_space.py +++ b/tests/python/contrib/test_ethosn/test_depth_to_space.py @@ -53,7 +53,16 @@ def test_depth_to_space(dtype, shape): for npu in [False, True]: model = _get_model(shape, 2, dtype, "NHWC") mod = tei.make_module(model, {}) - outputs.append(tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 1) diff --git a/tests/python/contrib/test_ethosn/test_leaky_relu.py b/tests/python/contrib/test_ethosn/test_leaky_relu.py index 7c1969ec44ba..ccf67151bf1e 100644 --- a/tests/python/contrib/test_ethosn/test_leaky_relu.py +++ b/tests/python/contrib/test_ethosn/test_leaky_relu.py @@ -65,7 +65,16 @@ def test_leaky_relu(dtype, shape, alpha): for npu in [False, True]: model = _get_model(shape, input_zp, input_sc, output_zp, output_sc, dtype, alpha) mod = tei.make_module(model, []) - outputs.append(tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 1) diff --git a/tests/python/contrib/test_ethosn/test_multiply.py b/tests/python/contrib/test_ethosn/test_multiply.py index a7b97e39cb13..d7ebcfab40a8 100644 --- a/tests/python/contrib/test_ethosn/test_multiply.py +++ b/tests/python/contrib/test_ethosn/test_multiply.py @@ -152,7 +152,14 @@ def test_multiply_to_reinterpret_quantize(shape, constant_shape, reverse_inputs) for npu in [False, True]: mod = tei.make_module(model, params) outputs.append( - tei.build_and_run(mod, inputs, 1, params, npu=npu, optimize_partitions=False) + tei.build_and_run( + mod, + inputs, + 1, + params, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) ) tei.verify(outputs, dtype, 1) diff --git a/tests/python/contrib/test_ethosn/test_relu.py b/tests/python/contrib/test_ethosn/test_relu.py index 8ecea0d23ce4..b1ab6ede2c42 100644 --- a/tests/python/contrib/test_ethosn/test_relu.py +++ b/tests/python/contrib/test_ethosn/test_relu.py @@ -60,7 +60,16 @@ def test_relu(dtype, shape, a_min, a_max): for npu in [False, True]: model = _get_model(inputs["a"].shape, dtype, a_min, a_max) mod = tei.make_module(model, {}) - outputs.append(tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 1) diff --git a/tests/python/contrib/test_ethosn/test_requantize.py b/tests/python/contrib/test_ethosn/test_requantize.py index 618b00c6e4ee..315beddbe45e 100644 --- a/tests/python/contrib/test_ethosn/test_requantize.py +++ b/tests/python/contrib/test_ethosn/test_requantize.py @@ -64,7 +64,14 @@ def test_requantize(in_dtype, out_dtype, shape): out_dtype=out_dtype, ) mod = tei.make_module(model, []) - x = tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False) + x = tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) outputs.append(x) tei.verify(outputs, out_dtype, 1) @@ -128,7 +135,14 @@ def get_model(): for npu in [False, True]: model = get_model() mod = tei.make_module(model, {}) - x = tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False) + x = tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) outputs.append(x) tei.verify(outputs, out_dtype, 1) diff --git a/tests/python/contrib/test_ethosn/test_reshape.py b/tests/python/contrib/test_ethosn/test_reshape.py index d60ad50b97bc..2c6b4fda5af5 100644 --- a/tests/python/contrib/test_ethosn/test_reshape.py +++ b/tests/python/contrib/test_ethosn/test_reshape.py @@ -72,7 +72,14 @@ def test_reshape(dtype, input_shape, output_shape): model, params = _get_model(input_shape, output_shape, dtype) mod = tei.make_module(model, params) outputs.append( - tei.build_and_run(mod, inputs, 1, params, npu=npu, optimize_partitions=False) + tei.build_and_run( + mod, + inputs, + 1, + params, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) ) tei.verify(outputs, dtype, 1) @@ -93,4 +100,10 @@ def test_reshape_failure(input_shape, output_shape): model, params = _get_model(input_shape, output_shape, "int8") mod = tei.make_module(model, params) - tei.build(mod, params, expected_host_ops=1, npu_partitions=0, optimize_partitions=False) + tei.build( + mod, + params, + expected_host_ops=1, + npu_partitions=0, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) diff --git a/tests/python/contrib/test_ethosn/test_split.py b/tests/python/contrib/test_ethosn/test_split.py index 56e51e2de159..0c13df97eef3 100644 --- a/tests/python/contrib/test_ethosn/test_split.py +++ b/tests/python/contrib/test_ethosn/test_split.py @@ -57,7 +57,14 @@ def test_split(dtype, shape, splits, axis): mod = tei.make_module(model, {}) output_count = splits if isinstance(splits, int) else len(splits) + 1 outputs.append( - tei.build_and_run(mod, inputs, output_count, {}, npu=npu, optimize_partitions=False) + tei.build_and_run( + mod, + inputs, + output_count, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) ) tei.verify(outputs, dtype, 0) diff --git a/tests/python/contrib/test_ethosn/test_tanh.py b/tests/python/contrib/test_ethosn/test_tanh.py index c2fc5188e5f1..25f46e51eda9 100644 --- a/tests/python/contrib/test_ethosn/test_tanh.py +++ b/tests/python/contrib/test_ethosn/test_tanh.py @@ -59,7 +59,16 @@ def test_tanh(dtype, shape): for npu in [False, True]: model = _get_model(shape, zp_min + 120, 0.0250629, zp_min + 128, 0.0078125, dtype) mod = tei.make_module(model, []) - outputs.append(tei.build_and_run(mod, inputs, 1, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 1, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 1) diff --git a/tests/python/contrib/test_ethosn/test_topologies.py b/tests/python/contrib/test_ethosn/test_topologies.py index 4a4fc1e4d126..78aa19a846eb 100644 --- a/tests/python/contrib/test_ethosn/test_topologies.py +++ b/tests/python/contrib/test_ethosn/test_topologies.py @@ -90,7 +90,7 @@ def get_model(input_shape, dtype, var_names): npu=npu, expected_host_ops=expected_host_ops, npu_partitions=npu_partitions, - optimize_partitions=False, + additional_config_args={"inline_non_compute_intensive_partitions": False}, ) ) @@ -178,7 +178,16 @@ def get_model(input_shape, dtype, var_names): for npu in [False, True]: model = get_model(inputs["a"].shape, dtype, iter(inputs)) mod = tei.make_module(model, []) - outputs.append(tei.build_and_run(mod, inputs, 8, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 8, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 1) @@ -286,7 +295,7 @@ def get_model(shape, dtype, splits, axis): npu=npu, expected_host_ops=expected_host_ops, npu_partitions=npu_partitions, - optimize_partitions=False, + additional_config_args={"inline_non_compute_intensive_partitions": False}, ) else: outputs.append( @@ -298,7 +307,7 @@ def get_model(shape, dtype, splits, axis): npu=npu, expected_host_ops=expected_host_ops, npu_partitions=npu_partitions, - optimize_partitions=False, + additional_config_args={"inline_non_compute_intensive_partitions": False}, ) ) @@ -329,7 +338,16 @@ def get_model(dtype): for npu in [False, True]: model = get_model(dtype) mod = tei.make_module(model, {}) - outputs.append(tei.build_and_run(mod, inputs, 4, {}, npu=npu, optimize_partitions=False)) + outputs.append( + tei.build_and_run( + mod, + inputs, + 4, + {}, + npu=npu, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) + ) tei.verify(outputs, dtype, 0) @@ -378,7 +396,12 @@ def get_model(shapes, dtype, axis): mod = tei.make_module(model, {}) else: mod = tei.make_ethosn_partition(model) - lib = tei.build(mod, {}, npu=False, optimize_partitions=False) + lib = tei.build( + mod, + {}, + npu=False, + additional_config_args={"inline_non_compute_intensive_partitions": False}, + ) outputs.append(tei.run(lib, inputs, 1, npu=npu)) tei.verify(outputs, dtype, 0)