diff options
author | Raul Farkas <raul.farkas@arm.com> | 2022-11-29 13:29:04 +0000 |
---|---|---|
committer | Raul Farkas <raul.farkas@arm.com> | 2023-01-10 10:46:07 +0000 |
commit | 5800fc990ed1e36ce7d06670f911fbb12a0ec771 (patch) | |
tree | 294605295cd2624ba63e6ad3df335a2a4b2700ab /src/mlia/core/common.py | |
parent | dcd0bd31985c27e1d07333351b26cf8ad12ad1fd (diff) | |
download | mlia-5800fc990ed1e36ce7d06670f911fbb12a0ec771.tar.gz |
MLIA-650 Implement new CLI changes
Breaking change in the CLI and API: Sub-commands "optimization",
"operators", and "performance" were replaced by "check", which
incorporates compatibility and performance checks, and "optimize" which
is used for optimization. "get_advice" API was adapted to these CLI
changes.
API changes:
* Remove previous advice category "all" that would perform all three
operations (when possible). Replace them with the ability to pass a
set of the advice categories.
* Update api.get_advice method docstring to reflect new changes.
* Set default advice category to COMPATIBILITY
* Update core.common.AdviceCategory by changing the "OPERATORS" advice
category to "COMPATIBILITY" and removing "ALL" enum type.
Update all subsequent methods that previously used "OPERATORS" to use
"COMPATIBILITY".
* Update core.context.ExecutionContext to have "COMPATIBILITY" as
default advice_category instead of "ALL".
* Remove api.generate_supported_operators_report and all related
functions from cli.commands, cli.helpers, cli.main, cli.options,
core.helpers
* Update tests to reflect new API changes.
CLI changes:
* Update README.md to contain information on the new CLI
* Remove the ability to generate supported operators support from MLIA
CLI
* Replace `mlia ops` and `mlia perf` with the new `mlia check` command
that can be used to perform both operations.
* Replace `mlia opt` with the new `mlia optimize` command.
* Replace `--evaluate-on` flag with `--backend` flag
* Replace `--verbose` flag with `--debug` flag (no behaviour change).
* Remove the ability for the user to select MLIA working directory.
Create and use a temporary directory in /temp instead.
* Change behaviour of `--output` flag to not format the content
automatically based on file extension anymore. Instead it will simply
redirect to a file.
* Add the `--json` flag to specfy that the format of the output should
be json.
* Add command validators that are used to validate inter-dependent
flags (e.g. backend validation based on target_profile).
* Add support for selecting built-in backends for both `check` and
`optimize` commands.
* Add new unit tests and update old ones to test the new CLI changes.
* Update RELEASES.md
* Update copyright notice
Change-Id: Ia6340797c7bee3acbbd26601950e5a16ad5602db
Diffstat (limited to 'src/mlia/core/common.py')
-rw-r--r-- | src/mlia/core/common.py | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/src/mlia/core/common.py b/src/mlia/core/common.py index 6c9dde1..53df001 100644 --- a/src/mlia/core/common.py +++ b/src/mlia/core/common.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 """Common module. @@ -13,6 +13,9 @@ from enum import auto from enum import Flag from typing import Any +from mlia.core.typing import OutputFormat +from mlia.core.typing import PathOrFileLike + # This type is used as type alias for the items which are being passed around # in advisor workflow. There are no restrictions on the type of the # object. This alias used only to emphasize the nature of the input/output @@ -20,31 +23,55 @@ from typing import Any DataItem = Any +class FormattedFilePath: + """Class used to keep track of the format that a path points to.""" + + def __init__(self, path: PathOrFileLike, fmt: OutputFormat = "plain_text") -> None: + """Init FormattedFilePath.""" + self._path = path + self._fmt = fmt + + @property + def fmt(self) -> OutputFormat: + """Return file format.""" + return self._fmt + + @property + def path(self) -> PathOrFileLike: + """Return file path.""" + return self._path + + def __eq__(self, other: object) -> bool: + """Check for equality with other objects.""" + if isinstance(other, FormattedFilePath): + return other.fmt == self.fmt and other.path == self.path + + return False + + def __repr__(self) -> str: + """Represent object.""" + return f"FormattedFilePath {self.path=}, {self.fmt=}" + + class AdviceCategory(Flag): """Advice category. Enumeration of advice categories supported by ML Inference Advisor. """ - OPERATORS = auto() + COMPATIBILITY = auto() PERFORMANCE = auto() OPTIMIZATION = auto() - ALL = ( - # pylint: disable=unsupported-binary-operation - OPERATORS - | PERFORMANCE - | OPTIMIZATION - # pylint: enable=unsupported-binary-operation - ) @classmethod - def from_string(cls, value: str) -> AdviceCategory: + def from_string(cls, values: set[str]) -> set[AdviceCategory]: """Resolve enum value from string value.""" category_names = [item.name for item in AdviceCategory] - if not value or value.upper() not in category_names: - raise Exception(f"Invalid advice category {value}") + for advice_value in values: + if advice_value.upper() not in category_names: + raise Exception(f"Invalid advice category {advice_value}") - return AdviceCategory[value.upper()] + return {AdviceCategory[value.upper()] for value in values} class NamedEntity(ABC): |