2021-09-30 00:03:40 +08:00
|
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
# Also available under a BSD-style license. See LICENSE.
|
2021-04-20 06:12:29 +08:00
|
|
|
|
|
|
|
import argparse
|
2021-04-22 06:07:15 +08:00
|
|
|
import re
|
|
|
|
import sys
|
2021-04-20 06:12:29 +08:00
|
|
|
|
2022-04-20 03:35:56 +08:00
|
|
|
from torch_mlir_e2e_test.torchscript.framework import run_tests
|
2021-09-28 02:36:44 +08:00
|
|
|
from torch_mlir_e2e_test.torchscript.reporting import report_results
|
|
|
|
from torch_mlir_e2e_test.torchscript.registry import GLOBAL_TEST_REGISTRY
|
2022-03-26 05:47:11 +08:00
|
|
|
from torch_mlir_e2e_test.torchscript.serialization import deserialize_all_tests_from
|
2021-04-20 06:12:29 +08:00
|
|
|
|
2022-04-20 03:35:56 +08:00
|
|
|
|
2021-04-20 06:12:29 +08:00
|
|
|
# Available test configs.
|
2021-09-28 02:36:44 +08:00
|
|
|
from torch_mlir_e2e_test.torchscript.configs import (
|
2022-03-03 07:02:18 +08:00
|
|
|
LinalgOnTensorsBackendTestConfig, NativeTorchTestConfig, TorchScriptTestConfig, TosaBackendTestConfig, EagerModeTestConfig
|
2021-04-20 06:12:29 +08:00
|
|
|
)
|
|
|
|
|
2021-09-28 02:36:44 +08:00
|
|
|
from torch_mlir_e2e_test.linalg_on_tensors_backends.refbackend import RefBackendLinalgOnTensorsBackend
|
2021-10-08 10:07:03 +08:00
|
|
|
from torch_mlir_e2e_test.tosa_backends.linalg_on_tensors import LinalgOnTensorsTosaBackend
|
2021-07-01 05:13:21 +08:00
|
|
|
|
2022-04-20 03:35:56 +08:00
|
|
|
from .xfail_sets import REFBACKEND_XFAIL_SET, TOSA_PASS_SET, EAGER_MODE_XFAIL_SET
|
2021-07-01 05:13:21 +08:00
|
|
|
|
2021-04-20 06:12:29 +08:00
|
|
|
# Import tests to register them in the global registry.
|
2022-03-26 04:24:55 +08:00
|
|
|
from torch_mlir_e2e_test.test_suite import register_all_tests
|
|
|
|
register_all_tests()
|
2021-04-20 06:12:29 +08:00
|
|
|
|
2021-05-20 08:36:00 +08:00
|
|
|
def _get_argparse():
|
2022-04-20 03:35:56 +08:00
|
|
|
config_choices = ['native_torch', 'torchscript', 'refbackend', 'tosa', 'eager_mode']
|
2021-04-20 06:12:29 +08:00
|
|
|
parser = argparse.ArgumentParser(description='Run torchscript e2e tests.')
|
2021-08-06 03:00:38 +08:00
|
|
|
parser.add_argument('-c', '--config',
|
2021-07-01 05:13:21 +08:00
|
|
|
choices=config_choices,
|
2021-04-20 06:12:29 +08:00
|
|
|
default='refbackend',
|
2021-07-01 05:13:21 +08:00
|
|
|
help=f'''
|
2021-04-20 06:12:29 +08:00
|
|
|
Meaning of options:
|
2021-09-28 02:36:44 +08:00
|
|
|
"refbackend": run through torch-mlir's RefBackend.
|
2021-10-08 10:07:03 +08:00
|
|
|
"tosa": run through torch-mlir's default TOSA backend.
|
2021-04-21 05:45:43 +08:00
|
|
|
"native_torch": run the torch.nn.Module as-is without compiling (useful for verifying model is deterministic; ALL tests should pass in this configuration).
|
2021-04-20 06:12:29 +08:00
|
|
|
"torchscript": compile the model to a torch.jit.ScriptModule, and then run that as-is (useful for verifying TorchScript is modeling the program correctly).
|
2022-03-26 04:24:55 +08:00
|
|
|
"eager_mode": run through torch-mlir's eager mode frontend, using RefBackend for execution.
|
2021-04-22 06:07:15 +08:00
|
|
|
''')
|
2021-08-10 04:55:20 +08:00
|
|
|
parser.add_argument('-f', '--filter', default='.*', help='''
|
2021-04-22 06:07:15 +08:00
|
|
|
Regular expression specifying which tests to include in this run.
|
2021-04-20 06:12:29 +08:00
|
|
|
''')
|
2021-05-20 08:36:00 +08:00
|
|
|
parser.add_argument('-v', '--verbose',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='report test results with additional detail')
|
2021-07-10 03:22:45 +08:00
|
|
|
parser.add_argument('--serialized-test-dir', default=None, type=str, help='''
|
|
|
|
The directory containing serialized pre-built tests.
|
|
|
|
Right now, these are additional tests which require heavy Python dependencies
|
|
|
|
to generate (or cannot even be generated with the version of PyTorch used by
|
2021-09-28 02:36:44 +08:00
|
|
|
torch-mlir).
|
2021-07-10 03:22:45 +08:00
|
|
|
See `build_tools/torchscript_e2e_heavydep_tests/generate_serialized_tests.sh`
|
|
|
|
for more information on building these artifacts.
|
|
|
|
''')
|
2022-05-12 04:55:47 +08:00
|
|
|
parser.add_argument('-s', '--sequential',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='run e2e tests sequentially rather than in parallel')
|
2021-05-20 08:36:00 +08:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = _get_argparse().parse_args()
|
|
|
|
|
2021-10-08 10:07:03 +08:00
|
|
|
if args.serialized_test_dir:
|
2022-03-26 05:47:11 +08:00
|
|
|
deserialize_all_tests_from(args.serialized_test_dir)
|
|
|
|
all_test_unique_names = set(
|
|
|
|
test.unique_name for test in GLOBAL_TEST_REGISTRY)
|
2021-10-08 10:07:03 +08:00
|
|
|
|
2021-05-20 08:36:00 +08:00
|
|
|
# Find the selected config.
|
2021-04-20 06:12:29 +08:00
|
|
|
if args.config == 'refbackend':
|
2021-09-28 02:36:44 +08:00
|
|
|
config = LinalgOnTensorsBackendTestConfig(RefBackendLinalgOnTensorsBackend())
|
2021-10-08 10:07:03 +08:00
|
|
|
xfail_set = REFBACKEND_XFAIL_SET
|
|
|
|
if args.config == 'tosa':
|
|
|
|
config = TosaBackendTestConfig(LinalgOnTensorsTosaBackend())
|
|
|
|
xfail_set = all_test_unique_names - TOSA_PASS_SET
|
2021-04-20 06:12:29 +08:00
|
|
|
elif args.config == 'native_torch':
|
|
|
|
config = NativeTorchTestConfig()
|
2021-10-08 10:07:03 +08:00
|
|
|
xfail_set = {}
|
2021-04-20 06:12:29 +08:00
|
|
|
elif args.config == 'torchscript':
|
|
|
|
config = TorchScriptTestConfig()
|
2021-10-08 10:07:03 +08:00
|
|
|
xfail_set = {}
|
2022-03-03 07:02:18 +08:00
|
|
|
elif args.config == 'eager_mode':
|
|
|
|
config = EagerModeTestConfig()
|
|
|
|
xfail_set = EAGER_MODE_XFAIL_SET
|
2021-04-22 06:07:15 +08:00
|
|
|
|
2021-05-20 08:36:00 +08:00
|
|
|
# Find the selected tests, and emit a diagnostic if none are found.
|
2021-04-22 06:07:15 +08:00
|
|
|
tests = [
|
2022-03-26 05:47:11 +08:00
|
|
|
test for test in GLOBAL_TEST_REGISTRY
|
2021-04-22 06:07:15 +08:00
|
|
|
if re.match(args.filter, test.unique_name)
|
|
|
|
]
|
|
|
|
if len(tests) == 0:
|
|
|
|
print(
|
|
|
|
f'ERROR: the provided filter {args.filter!r} does not match any tests'
|
|
|
|
)
|
|
|
|
print('The available tests are:')
|
2022-03-26 05:47:11 +08:00
|
|
|
for test in GLOBAL_TEST_REGISTRY:
|
2021-04-22 06:07:15 +08:00
|
|
|
print(test.unique_name)
|
|
|
|
sys.exit(1)
|
2021-05-20 08:36:00 +08:00
|
|
|
|
|
|
|
# Run the tests.
|
2022-05-12 04:55:47 +08:00
|
|
|
results = run_tests(tests, config, args.sequential)
|
2021-05-20 08:36:00 +08:00
|
|
|
|
|
|
|
# Report the test results.
|
2021-10-05 02:24:12 +08:00
|
|
|
failed = report_results(results, xfail_set, args.verbose)
|
2021-07-01 05:13:21 +08:00
|
|
|
sys.exit(1 if failed else 0)
|
2021-04-20 06:12:29 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|