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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Tests for advice generation."""
from __future__ import annotations
import pytest
from mlia.core.advice_generation import Advice
from mlia.core.common import AdviceCategory
from mlia.core.common import DataItem
from mlia.core.context import ExecutionContext
from mlia.devices.cortexa.advice_generation import CortexAAdviceProducer
from mlia.devices.cortexa.data_analysis import ModelIsCortexACompatible
from mlia.devices.cortexa.data_analysis import ModelIsNotCortexACompatible
from mlia.devices.cortexa.data_analysis import ModelIsNotTFLiteCompatible
@pytest.mark.parametrize(
"input_data, advice_category, expected_advice",
[
[
ModelIsNotCortexACompatible(),
AdviceCategory.OPERATORS,
[
Advice(
[
"Some operators in the model are not compatible with Cortex-A. "
"Please, refer to the operators table for more information."
]
)
],
],
[
ModelIsCortexACompatible(),
AdviceCategory.OPERATORS,
[Advice(["Model is fully compatible with Cortex-A."])],
],
[
ModelIsNotTFLiteCompatible(
flex_ops=["flex_op1", "flex_op2"],
custom_ops=["custom_op1", "custom_op2"],
),
AdviceCategory.OPERATORS,
[
Advice(
[
"The following operators are not natively "
"supported by TensorFlow Lite: flex_op1, flex_op2.",
"Please refer to the TensorFlow documentation for "
"more details.",
]
),
Advice(
[
"The following operators are custom and not natively "
"supported by TensorFlow Lite: custom_op1, custom_op2.",
"Please refer to the TensorFlow documentation for "
"more details.",
]
),
],
],
[
ModelIsNotTFLiteCompatible(),
AdviceCategory.OPERATORS,
[
Advice(
[
"Model could not be converted into TensorFlow Lite format.",
"Please refer to the table for more details.",
]
),
],
],
],
)
def test_cortex_a_advice_producer(
tmpdir: str,
input_data: DataItem,
advice_category: AdviceCategory,
expected_advice: list[Advice],
) -> None:
"""Test Cortex-A advice producer."""
producer = CortexAAdviceProducer()
context = ExecutionContext(
advice_category=advice_category,
working_dir=tmpdir,
)
producer.set_context(context)
producer.produce_advice(input_data)
assert producer.get_advice() == expected_advice
|