diff options
author | Diego Russo <diego.russo@arm.com> | 2022-05-30 13:34:14 +0100 |
---|---|---|
committer | Diego Russo <diego.russo@arm.com> | 2022-05-30 13:34:14 +0100 |
commit | 0efca3cadbad5517a59884576ddb90cfe7ac30f8 (patch) | |
tree | abed6cb6fbf3c439fc8d947f505b6a53d5daeb1e /src/mlia/core/performance.py | |
parent | 0777092695c143c3a54680b5748287d40c914c35 (diff) | |
download | mlia-0efca3cadbad5517a59884576ddb90cfe7ac30f8.tar.gz |
Add MLIA codebase0.3.0-rc.1
Add MLIA codebase including sources and tests.
Change-Id: Id41707559bd721edd114793618d12ccd188d8dbd
Diffstat (limited to 'src/mlia/core/performance.py')
-rw-r--r-- | src/mlia/core/performance.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/mlia/core/performance.py b/src/mlia/core/performance.py new file mode 100644 index 0000000..5433d5c --- /dev/null +++ b/src/mlia/core/performance.py @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Module for performance estimation.""" +from abc import abstractmethod +from typing import Callable +from typing import Generic +from typing import List +from typing import TypeVar + + +ModelType = TypeVar("ModelType") # pylint: disable=invalid-name +PerfMetricsType = TypeVar("PerfMetricsType") # pylint: disable=invalid-name + + +class PerformanceEstimator(Generic[ModelType, PerfMetricsType]): + """Base class for the performance estimation.""" + + @abstractmethod + def estimate(self, model: ModelType) -> PerfMetricsType: + """Estimate performance.""" + + +def estimate_performance( + original_model: ModelType, + estimator: PerformanceEstimator[ModelType, PerfMetricsType], + model_transformations: List[Callable[[ModelType], ModelType]], +) -> List[PerfMetricsType]: + """Estimate performance impact. + + This function estimates performance impact on model performance after + applying provided transformations/optimizations. + + :param original_model: object that represents a model, could be + instance of the model or path to the model. This depends on + provided performance estimator. + :param estimator: performance estimator + :param model_transformations: list of the callables each of those + returns object that represents optimized model + """ + original_metrics = estimator.estimate(original_model) + + optimized_metrics = [ + estimator.estimate(transform(original_model)) + for transform in model_transformations + ] + + return [original_metrics, *optimized_metrics] |