blob: ad321b22800c59043ab03298b02a69b94be7170c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""TOSA advice generation."""
from functools import singledispatchmethod
from mlia.core.advice_generation import advice_category
from mlia.core.advice_generation import FactBasedAdviceProducer
from mlia.core.common import AdviceCategory
from mlia.core.common import DataItem
from mlia.target.common.reporters import handle_model_is_not_tflite_compatible_common
from mlia.target.common.reporters import handle_tflite_check_failed_common
from mlia.target.common.reporters import ModelIsNotTFLiteCompatible
from mlia.target.common.reporters import TFLiteCompatibilityCheckFailed
from mlia.target.tosa.data_analysis import ModelIsNotTOSACompatible
from mlia.target.tosa.data_analysis import ModelIsTOSACompatible
class TOSAAdviceProducer(FactBasedAdviceProducer):
"""TOSA advice producer."""
@singledispatchmethod
def produce_advice(self, _data_item: DataItem) -> None: # type: ignore
"""Produce advice."""
@produce_advice.register
@advice_category(AdviceCategory.COMPATIBILITY)
def handle_model_is_tosa_compatible(
self, _data_item: ModelIsTOSACompatible
) -> None:
"""Advice for TOSA compatibility."""
self.add_advice(["Model is fully TOSA compatible."])
@produce_advice.register
@advice_category(AdviceCategory.COMPATIBILITY)
def handle_model_is_not_tosa_compatible(
self, _data_item: ModelIsNotTOSACompatible
) -> None:
"""Advice for TOSA compatibility."""
self.add_advice(
[
"Some operators in the model are not TOSA compatible. "
"Please, refer to the operators table for more information."
]
)
@produce_advice.register
@advice_category(AdviceCategory.COMPATIBILITY)
def handle_model_is_not_tflite_compatible(
self, data_item: ModelIsNotTFLiteCompatible
) -> None:
"""Advice for TensorFlow Lite compatibility."""
handle_model_is_not_tflite_compatible_common(self, data_item)
@produce_advice.register
@advice_category(AdviceCategory.COMPATIBILITY)
def handle_tflite_check_failed(
self, _data_item: TFLiteCompatibilityCheckFailed
) -> None:
"""Advice for the failed TensorFlow Lite compatibility checks."""
handle_tflite_check_failed_common(self, _data_item)
|