Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ArmTester logging #6080

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backends/arm/test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import logging
import os
import shutil
import subprocess
import sys
import tempfile

import pytest
Expand Down Expand Up @@ -37,6 +39,7 @@ def pytest_configure(config):
"Tests are run with --arm_run_corstone300 but corstone300 FVP is not installed."
)
_enabled_options.append("corstone300")
logging.basicConfig(level=logging.INFO, stream=sys.stdout)


def pytest_collection_modifyitems(config, items):
Expand Down
120 changes: 109 additions & 11 deletions backends/arm/test/misc/test_debug_feats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import os
import shutil
import tempfile
import unittest

Expand Down Expand Up @@ -126,8 +127,62 @@ def test_numerical_diff_prints(self):
self.fail()


class TestDumpOperatorsAndDtypes(unittest.TestCase):
def test_dump_ops_and_dtypes(self):
def test_dump_ops_and_dtypes():
model = Linear(20, 30)
(
ArmTester(
model,
example_inputs=model.get_inputs(),
compile_spec=common.get_tosa_compile_spec(),
)
.quantize()
.dump_dtype_distribution()
.dump_operator_distribution()
.export()
.dump_dtype_distribution()
.dump_operator_distribution()
.to_edge()
.dump_dtype_distribution()
.dump_operator_distribution()
.partition()
.dump_dtype_distribution()
.dump_operator_distribution()
)
# Just test that there are no execptions.


def test_dump_ops_and_dtypes_parseable():
model = Linear(20, 30)
(
ArmTester(
model,
example_inputs=model.get_inputs(),
compile_spec=common.get_tosa_compile_spec(),
)
.quantize()
.dump_dtype_distribution(print_table=False)
.dump_operator_distribution(print_table=False)
.export()
.dump_dtype_distribution(print_table=False)
.dump_operator_distribution(print_table=False)
.to_edge()
.dump_dtype_distribution(print_table=False)
.dump_operator_distribution(print_table=False)
.partition()
.dump_dtype_distribution(print_table=False)
.dump_operator_distribution(print_table=False)
)
# Just test that there are no execptions.


class TestCollateTosaTests(unittest.TestCase):
"""Tests the collation of TOSA tests through setting the environment variable TOSA_TESTCASE_BASE_PATH."""

def test_collate_tosa_BI_tests(self):
# Set the environment variable to trigger the collation of TOSA tests
os.environ["TOSA_TESTCASES_BASE_PATH"] = "test_collate_tosa_tests"
# Clear out the directory

model = Linear(20, 30)
(
ArmTester(
Expand All @@ -136,16 +191,59 @@ def test_dump_ops_and_dtypes(self):
compile_spec=common.get_tosa_compile_spec(),
)
.quantize()
.dump_dtype_distribution()
.dump_operator_distribution()
.export()
.dump_dtype_distribution()
.dump_operator_distribution()
.to_edge()
.dump_dtype_distribution()
.dump_operator_distribution()
.partition()
.dump_dtype_distribution()
.dump_operator_distribution()
.to_executorch()
)
# test that the output directory is created and contains the expected files
assert os.path.exists(
"test_collate_tosa_tests/tosa-bi/TestCollateTosaTests/test_collate_tosa_BI_tests"
)
assert os.path.exists(
"test_collate_tosa_tests/tosa-bi/TestCollateTosaTests/test_collate_tosa_BI_tests/output_tag8.tosa"
)
assert os.path.exists(
"test_collate_tosa_tests/tosa-bi/TestCollateTosaTests/test_collate_tosa_BI_tests/desc_tag8.json"
)

os.environ.pop("TOSA_TESTCASES_BASE_PATH")
shutil.rmtree("test_collate_tosa_tests", ignore_errors=True)


def test_dump_tosa_ops(caplog):
caplog.set_level(logging.INFO)
model = Linear(20, 30)
(
ArmTester(
model,
example_inputs=model.get_inputs(),
compile_spec=common.get_tosa_compile_spec(),
)
# Just test that there are no execeptions.
.quantize()
.export()
.to_edge()
.partition()
.dump_operator_distribution()
)
assert "TOSA operators:" in caplog.text


def test_fail_dump_tosa_ops(caplog):
caplog.set_level(logging.INFO)

class Add(torch.nn.Module):
def forward(self, x):
return x + x

model = Add()
compile_spec = common.get_u55_compile_spec()
(
ArmTester(model, example_inputs=(torch.ones(5),), compile_spec=compile_spec)
.quantize()
.export()
.to_edge()
.partition()
.dump_operator_distribution()
)
assert "Can not get operator distribution for Vela command stream." in caplog.text
Loading
Loading