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
|
# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Tests for TOSA data analysis module."""
from __future__ import annotations
import pytest
from mlia.backend.tosa_checker.compat import TOSACompatibilityInfo
from mlia.core.common import DataItem
from mlia.core.data_analysis import Fact
from mlia.nn.tensorflow.tflite_compat import TFLiteCompatibilityInfo
from mlia.nn.tensorflow.tflite_compat import TFLiteCompatibilityStatus
from mlia.nn.tensorflow.tflite_compat import TFLiteConversionError
from mlia.nn.tensorflow.tflite_compat import TFLiteConversionErrorCode
from mlia.target.common.reporters import ModelHasCustomOperators
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
from mlia.target.tosa.data_analysis import TOSADataAnalyzer
@pytest.mark.parametrize(
"input_data, expected_facts",
[
[
TOSACompatibilityInfo(True, []),
[ModelIsTOSACompatible()],
],
[
TOSACompatibilityInfo(False, []),
[ModelIsNotTOSACompatible()],
],
[
TFLiteCompatibilityInfo(status=TFLiteCompatibilityStatus.COMPATIBLE),
[],
],
[
TFLiteCompatibilityInfo(
status=TFLiteCompatibilityStatus.MODEL_WITH_CUSTOM_OP_ERROR
),
[ModelHasCustomOperators()],
],
[
TFLiteCompatibilityInfo(status=TFLiteCompatibilityStatus.UNKNOWN_ERROR),
[TFLiteCompatibilityCheckFailed()],
],
[
TFLiteCompatibilityInfo(
status=TFLiteCompatibilityStatus.TFLITE_CONVERSION_ERROR
),
[ModelIsNotTFLiteCompatible(custom_ops=[], flex_ops=[])],
],
[
TFLiteCompatibilityInfo(
status=TFLiteCompatibilityStatus.TFLITE_CONVERSION_ERROR,
conversion_errors=[
TFLiteConversionError(
"error",
TFLiteConversionErrorCode.NEEDS_CUSTOM_OPS,
"custom_op1",
[],
),
TFLiteConversionError(
"error",
TFLiteConversionErrorCode.NEEDS_FLEX_OPS,
"flex_op1",
[],
),
],
),
[
ModelIsNotTFLiteCompatible(
custom_ops=["custom_op1"],
flex_ops=["flex_op1"],
)
],
],
],
)
def test_tosa_data_analyzer(input_data: DataItem, expected_facts: list[Fact]) -> None:
"""Test TOSA data analyzer."""
analyzer = TOSADataAnalyzer()
analyzer.analyze_data(input_data)
assert analyzer.get_analyzed_data() == expected_facts
|