aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Klimczak <benjamin.klimczak@arm.com>2022-12-23 17:26:09 +0000
committerBenjamin Klimczak <benjamin.klimczak@arm.com>2023-02-08 15:17:02 +0000
commit6fbcffb4ee039438a409fbc92e38fa5d1d118833 (patch)
tree9e2268059a6963201efc8b980d79104337155f2f
parentc6cfc78d5245c550016b9709686d2b32ab3fcd5b (diff)
downloadmlia-6fbcffb4ee039438a409fbc92e38fa5d1d118833.tar.gz
MLIA-737 Show connection between target / backend
- The help text of MLIA now shows a table of supported targets, backends and advice. - The table is only shown with the help message and not when MLIA is run normally. Change-Id: I3234ce91e943de4b08b9471bd95a474df34755f7
-rw-r--r--src/mlia/cli/main.py15
-rw-r--r--src/mlia/target/registry.py57
-rw-r--r--src/mlia/utils/console.py4
-rw-r--r--tests/test_target_ethos_u_reporters.py1
-rw-r--r--tests/test_utils_console.py4
5 files changed, 65 insertions, 16 deletions
diff --git a/src/mlia/cli/main.py b/src/mlia/cli/main.py
index 2b63124..4a91b08 100644
--- a/src/mlia/cli/main.py
+++ b/src/mlia/cli/main.py
@@ -11,7 +11,6 @@ from inspect import signature
from mlia import __version__
from mlia.backend.errors import BackendUnavailableError
-from mlia.backend.registry import registry as backend_registry
from mlia.cli.commands import backend_install
from mlia.cli.commands import backend_list
from mlia.cli.commands import backend_uninstall
@@ -35,7 +34,7 @@ from mlia.core.context import ExecutionContext
from mlia.core.errors import ConfigurationError
from mlia.core.errors import InternalError
from mlia.core.logging import setup_logging
-from mlia.target.registry import registry as target_registry
+from mlia.target.registry import table as target_table
logger = logging.getLogger(__name__)
@@ -43,14 +42,10 @@ logger = logging.getLogger(__name__)
INFO_MESSAGE = f"""
ML Inference Advisor {__version__}
-Help the design and optimization of neural network models for efficient inference on a target CPU and NPU
-
-Supported targets:
-{target_registry}
-
-Supported backends:
-{backend_registry}
+Help the design and optimization of neural network models for efficient inference on a target CPU or NPU.
+{target_table().to_plain_text(show_title=True, space=False)}
+Use command 'mlia-backend' to install backends.
""".strip()
@@ -192,7 +187,7 @@ def run_command(args: argparse.Namespace) -> int:
)
try:
- logger.info(INFO_MESSAGE)
+ logger.info("ML Inference Advisor %s", __version__)
logger.info(
"\nThis execution of MLIA uses output directory: %s", ctx.output_dir
)
diff --git a/src/mlia/target/registry.py b/src/mlia/target/registry.py
index 6b33084..2d29f1b 100644
--- a/src/mlia/target/registry.py
+++ b/src/mlia/target/registry.py
@@ -1,10 +1,17 @@
-# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Target module."""
from __future__ import annotations
+from typing import cast
+
+from mlia.backend.config import BackendType
+from mlia.backend.manager import DefaultInstallationManager
from mlia.backend.registry import registry as backend_registry
+from mlia.cli.config import get_installation_manager
from mlia.core.common import AdviceCategory
+from mlia.core.reporting import Column
+from mlia.core.reporting import Table
from mlia.target.config import TargetInfo
from mlia.utils.registry import Registry
@@ -32,3 +39,51 @@ def supported_targets(advice: AdviceCategory) -> list[str]:
for name, info in registry.items.items()
if info.is_supported(advice, check_system=False)
]
+
+
+def table() -> Table:
+ """Get a table representation of registered targets with backends."""
+
+ def get_status(backend: str) -> str:
+ if backend_registry.items[backend].type == BackendType.BUILTIN:
+ return BackendType.BUILTIN.name
+ mgr = cast(DefaultInstallationManager, get_installation_manager())
+ return "INSTALLED" if mgr.already_installed(backend) else "NOT INSTALLED"
+
+ def get_advice(target: str) -> tuple[str, str, str]:
+ supported = supported_advice(target)
+ return tuple( # type: ignore
+ "YES" if advice in supported else "NO"
+ for advice in (
+ AdviceCategory.COMPATIBILITY,
+ AdviceCategory.PERFORMANCE,
+ AdviceCategory.OPTIMIZATION,
+ )
+ )
+
+ rows = [
+ (
+ name,
+ Table(
+ columns=[Column("Backend"), Column("Status")],
+ rows=[
+ (backend, get_status(backend))
+ for backend in info.supported_backends
+ ],
+ name="Backends",
+ ),
+ "/".join(get_advice(name)),
+ )
+ for name, info in registry.items.items()
+ ]
+
+ return Table(
+ columns=[
+ Column("Target"),
+ Column("Backend(s)"),
+ Column("Advice: comp/perf/opt"),
+ ],
+ rows=rows,
+ name="Supported Targets/Backends",
+ notes="Comp/Perf/Opt: Advice categories compatibility/performance/optimization",
+ )
diff --git a/src/mlia/utils/console.py b/src/mlia/utils/console.py
index 1f428a7..57e3ba2 100644
--- a/src/mlia/utils/console.py
+++ b/src/mlia/utils/console.py
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Console output utility functions."""
from __future__ import annotations
@@ -71,7 +71,7 @@ def _get_table(table_style: str) -> Table:
return Table(
show_header=False,
box=None,
- padding=(0, 1, 1, 0),
+ padding=(0, 1, 0, 0), # (top, right, bottom, left)
)
if table_style == "no_borders":
diff --git a/tests/test_target_ethos_u_reporters.py b/tests/test_target_ethos_u_reporters.py
index ee7ea52..bc764a0 100644
--- a/tests/test_target_ethos_u_reporters.py
+++ b/tests/test_target_ethos_u_reporters.py
@@ -62,7 +62,6 @@ Operators:
│ 2 │ cpu_only │ test_type │ CPU │ * CPU only operator │
├───┼─────────────────┼───────────────┼───────────┼───────────────────────────────┤
│ 3 │ npu_unsupported │ test_type │ CPU │ * Not supported operator │
-│ │ │ │ │ │
│ │ │ │ │ * Reason why operator is not │
│ │ │ │ │ supported │
└───┴─────────────────┴───────────────┴───────────┴───────────────────────────────┘
diff --git a/tests/test_utils_console.py b/tests/test_utils_console.py
index 5b01403..0a537a6 100644
--- a/tests/test_utils_console.py
+++ b/tests/test_utils_console.py
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Tests for console utility functions."""
from __future__ import annotations
@@ -33,7 +33,7 @@ from mlia.utils.console import remove_ascii_codes
[["1", "2", "3"]],
["Col 1", "Col 2", "Col 3"],
"nested",
- "Col 1 Col 2 Col 3 \n \n1 2 3",
+ "Col 1 Col 2 Col 3 \n1 2 3",
],
[
[["1", "2", "3"]],