Skip to content

Commit

Permalink
[ETHOSN] Remove remaining support for the N77 variant (apache#11262)
Browse files Browse the repository at this point in the history
Specifically removes some TVMC tests that are no longer necessary
and some partitioning infrastructure.
  • Loading branch information
lhutton1 authored and Yuanjing Shi committed May 17, 2022
1 parent 2b82691 commit 18c58c4
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 129 deletions.
5 changes: 0 additions & 5 deletions python/tvm/driver/tvmc/composite_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import tvm.contrib.target.vitis_ai # pylint: disable=unused-import

from tvm.relay.op.contrib.arm_compute_lib import partition_for_arm_compute_lib
from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
from tvm.relay.op.contrib.cmsisnn import partition_for_cmsisnn
from tvm.relay.op.contrib.ethosu import partition_for_ethosu
Expand Down Expand Up @@ -56,10 +55,6 @@
"config_key": "relay.ext.cmsisnn.options",
"pass_pipeline": partition_for_cmsisnn,
},
"ethos-n77": {
"config_key": "relay.ext.ethos-n.options",
"pass_pipeline": partition_for_ethosn77,
},
"ethos-n78": {
"config_key": "relay.ext.ethos-n.options",
"pass_pipeline": partition_for_ethosn78,
Expand Down
40 changes: 0 additions & 40 deletions python/tvm/relay/op/contrib/ethosn.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,6 @@ def ethosn_available():
return Available.SW_AND_HW if hw else Available.SW_ONLY


def partition_for_ethosn77(mod, params=None, **opts):
"""Partition the graph greedily offloading supported
operators to Arm Ethos-N NPU.
Parameters
----------
mod : Module
The module to run passes on.
params : Optional[Dict[str, NDArray]]
Constant input parameters.
Returns
-------
ret : annotated and partitioned module.
"""
if opts:
tops = opts.get("tops", None)
ple_ratio = opts.get("ple_ratio", None)
sram_size = opts.get("sram_size", None)
if tops or ple_ratio or sram_size:
raise ValueError(
"Setting tops, ple_ratio or sram_size has no effect when targeting Ethos(TM)-N77"
)

if params:
mod["main"] = bind_params_by_name(mod["main"], params)

seq = tvm.transform.Sequential(
[
transform.InferType(),
transform.MergeComposite(pattern_table()),
transform.AnnotateTarget("ethos-n"),
transform.MergeCompilerRegions(),
transform.PartitionGraph(),
]
)

return seq(mod)


def partition_for_ethosn78(mod, params=None, **opts):
"""Partition the graph greedily offloading supported
operators to Arm Ethos-N NPU.
Expand Down
50 changes: 0 additions & 50 deletions tests/python/contrib/test_ethosn/test_partition_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from tvm import relay
import numpy as np

from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
from tvm.testing import requires_ethosn

Expand Down Expand Up @@ -73,52 +72,3 @@ def test_ethosn78_partition_invalid_variant():
mod = tvm.IRModule.from_expr(res)
opts = {"variant": "Ethos-N"}
partition_for_ethosn78(mod, **opts)


@requires_ethosn
def test_ethosn78_partition_error():
with pytest.raises(
ValueError, match=r".*When targeting Ethos\(TM\)-N78, -variant=Ethos-N78 should be set.*"
):
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8")
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8"))
res = relay.nn.conv2d(
a, w, 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-N77"}
partition_for_ethosn78(mod, **opts)


@requires_ethosn
def test_ethosn77_partition_no_error():
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8")
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8"))
res = relay.nn.conv2d(a, w, 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_ethosn77(mod)


@requires_ethosn
def test_ethosn77_partition_error():
with pytest.raises(
ValueError,
match=r".*Setting tops, ple_ratio or sram_size has no effect when targeting Ethos\(TM\)-N77.*",
):
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8")
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8"))
res = relay.nn.conv2d(
a, w, 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 = {"tops": 4}
partition_for_ethosn77(mod, **opts)
18 changes: 0 additions & 18 deletions tests/python/driver/tvmc/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,24 +378,6 @@ def test_compile_opencl(tflite_mobilenet_v1_0_25_128):
assert os.path.exists(dumps_path)


@pytest.mark.skipif(
not ethosn_available(),
reason="--target=Ethos(TM)-N78 is not available. TVM built with 'USE_ETHOSN OFF'",
)
def test_compile_tflite_module_with_external_codegen_ethos_n77(tflite_mobilenet_v1_1_quant):
pytest.importorskip("tflite")
tvmc_model = tvmc.load(tflite_mobilenet_v1_1_quant)
tvmc_package = tvmc.compile(tvmc_model, target="ethos-n77, llvm", dump_code="relay")
dumps_path = tvmc_package.package_path + ".relay"

# check for output types
assert type(tvmc_package) is TVMCPackage
assert type(tvmc_package.graph) is str
assert type(tvmc_package.lib_path) is str
assert type(tvmc_package.params) is bytearray
assert os.path.exists(dumps_path)


@tvm.testing.requires_cmsisnn
def test_compile_tflite_module_with_external_codegen_cmsisnn(
tmpdir_factory, tflite_cnn_s_quantized
Expand Down
1 change: 0 additions & 1 deletion tests/python/driver/tvmc/test_composite_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
def test_get_codegen_names():
names = tvmc.composite_target.get_codegen_names()

assert "ethos-n77" in names
assert "ethos-n78" in names
assert "vitis-ai" in names
assert len(names) > 0
Expand Down
15 changes: 0 additions & 15 deletions tests/python/driver/tvmc/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ def test_target_from_cli__error_target_not_found():
_ = target_from_cli("invalidtarget")


def test_target_from_cli__error_no_tvm_target():
with pytest.raises(TVMCException):
_ = target_from_cli("ethos-n77")


def test_target_two_tvm_targets():
tvm_target, extra_targets = target_from_cli(
"opencl -device=mali, llvm -mtriple=aarch64-linux-gnu"
Expand Down Expand Up @@ -157,16 +152,6 @@ def test_parse_quotes_and_separators_on_options():
assert "+v1.0x,+value" == targets_double_quote[0]["opts"]["option1"]


def test_parse_multiple_target_with_opts_ethos_n77():
targets = parse_target("ethos-n77 -myopt=value, llvm -device=arm_cpu --system-lib")

assert len(targets) == 2
assert "ethos-n77" == targets[0]["name"]
assert "myopt" in targets[0]["opts"]
assert "value" == targets[0]["opts"]["myopt"]
assert "llvm" == targets[1]["name"]


def test_parse_multiple_target_with_opts_ethos_n78():
targets = parse_target("ethos-n78 -myopt=value, llvm -device=arm_cpu --system-lib")

Expand Down

0 comments on commit 18c58c4

Please sign in to comment.