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-08-30 04:32:18 +08:00
|
|
|
from torch_mlir_e2e_test.framework import run_tests
|
|
|
|
from torch_mlir_e2e_test.reporting import report_results
|
|
|
|
from torch_mlir_e2e_test.registry import GLOBAL_TEST_REGISTRY
|
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.
|
2022-08-30 04:32:18 +08:00
|
|
|
from torch_mlir_e2e_test.configs import (
|
2022-10-12 01:29:07 +08:00
|
|
|
LazyTensorCoreTestConfig,
|
2022-08-23 16:47:21 +08:00
|
|
|
LinalgOnTensorsBackendTestConfig,
|
2023-02-02 21:29:47 +08:00
|
|
|
StablehloBackendTestConfig,
|
2022-08-23 16:47:21 +08:00
|
|
|
NativeTorchTestConfig,
|
2024-02-16 02:17:13 +08:00
|
|
|
OnnxBackendTestConfig,
|
2022-08-23 16:47:21 +08:00
|
|
|
TorchScriptTestConfig,
|
|
|
|
TosaBackendTestConfig,
|
2022-11-18 20:21:19 +08:00
|
|
|
TorchDynamoTestConfig,
|
2024-04-13 07:07:56 +08:00
|
|
|
FxImporterTestConfig,
|
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
|
2024-02-16 02:17:13 +08:00
|
|
|
from torch_mlir_e2e_test.onnx_backends.linalg_on_tensors import LinalgOnTensorsOnnxBackend
|
2021-10-08 10:07:03 +08:00
|
|
|
from torch_mlir_e2e_test.tosa_backends.linalg_on_tensors import LinalgOnTensorsTosaBackend
|
2024-02-16 01:08:48 +08:00
|
|
|
from torch_mlir_e2e_test.stablehlo_backends.linalg_on_tensors import LinalgOnTensorsStablehloBackend
|
2021-07-01 05:13:21 +08:00
|
|
|
|
2023-04-29 07:05:17 +08:00
|
|
|
from .xfail_sets import (
|
|
|
|
LINALG_XFAIL_SET,
|
2024-04-19 02:47:19 +08:00
|
|
|
LINALG_CRASHING_SET,
|
2023-07-13 21:07:54 +08:00
|
|
|
MAKE_FX_TOSA_PASS_SET,
|
2023-04-29 07:05:17 +08:00
|
|
|
STABLEHLO_PASS_SET,
|
2023-07-29 21:55:49 +08:00
|
|
|
STABLEHLO_CRASHING_SET,
|
2023-04-29 07:05:17 +08:00
|
|
|
TOSA_PASS_SET,
|
|
|
|
LTC_XFAIL_SET,
|
2023-08-30 18:29:39 +08:00
|
|
|
LTC_CRASHING_SET,
|
2023-04-29 07:05:17 +08:00
|
|
|
TORCHDYNAMO_XFAIL_SET,
|
2024-02-16 02:17:13 +08:00
|
|
|
TORCHDYNAMO_CRASHING_SET,
|
|
|
|
ONNX_CRASHING_SET,
|
|
|
|
ONNX_XFAIL_SET,
|
2024-04-19 12:29:17 +08:00
|
|
|
FX_IMPORTER_XFAIL_SET,
|
2024-04-13 07:07:56 +08:00
|
|
|
FX_IMPORTER_CRASHING_SET,
|
2024-04-19 12:29:17 +08:00
|
|
|
FX_IMPORTER_STABLEHLO_XFAIL_SET,
|
|
|
|
FX_IMPORTER_STABLEHLO_CRASHING_SET,
|
2023-04-29 07:05:17 +08:00
|
|
|
)
|
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():
|
2024-04-19 12:29:17 +08:00
|
|
|
config_choices = ["native_torch", "torchscript", "linalg", "stablehlo", "make_fx_tosa", "tosa", "lazy_tensor_core",
|
|
|
|
"torchdynamo", "onnx", "fx_importer", "fx_importer_stablehlo"]
|
2022-12-09 21:13:15 +08:00
|
|
|
parser = argparse.ArgumentParser(description="Run torchscript e2e tests.")
|
|
|
|
parser.add_argument("-c", "--config",
|
2021-07-01 05:13:21 +08:00
|
|
|
choices=config_choices,
|
2022-12-09 21:13:15 +08:00
|
|
|
default="linalg",
|
|
|
|
help=f"""
|
2021-04-20 06:12:29 +08:00
|
|
|
Meaning of options:
|
2022-12-09 21:13:15 +08:00
|
|
|
"linalg": run through torch-mlir"s default Linalg-on-Tensors backend.
|
|
|
|
"tosa": run through torch-mlir"s default TOSA backend.
|
2024-02-16 01:08:48 +08:00
|
|
|
"stablehlo": run through torch-mlir"s default Stablehlo 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-11-18 20:21:19 +08:00
|
|
|
"lazy_tensor_core": run the model through the Lazy Tensor Core frontend and execute the traced graph.
|
2022-12-07 21:51:24 +08:00
|
|
|
"torchdynamo": run the model through the TorchDynamo frontend and execute the graph using Linalg-on-Tensors.
|
2024-02-16 02:17:13 +08:00
|
|
|
"onnx": export to the model via onnx and reimport using the torch-onnx-to-torch path.
|
2024-04-19 12:29:17 +08:00
|
|
|
"fx_importer": run the model through the fx importer frontend and execute the graph using Linalg-on-Tensors.
|
|
|
|
"fx_importer_stablehlo": run the model through the fx importer frontend and execute the graph using Stablehlo backend.
|
2022-12-09 21:13:15 +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.
|
2022-12-09 21:13:15 +08:00
|
|
|
""")
|
|
|
|
parser.add_argument("-v", "--verbose",
|
2021-05-20 08:36:00 +08:00
|
|
|
default=False,
|
2022-12-09 21:13:15 +08:00
|
|
|
action="store_true",
|
|
|
|
help="report test results with additional detail")
|
|
|
|
parser.add_argument("-s", "--sequential",
|
2022-05-12 04:55:47 +08:00
|
|
|
default=False,
|
2022-12-09 21:13:15 +08:00
|
|
|
action="store_true",
|
|
|
|
help="""Run tests sequentially rather than in parallel.
|
2022-09-22 01:39:19 +08:00
|
|
|
This can be useful for debugging, since it runs the tests in the same process,
|
2022-12-09 21:13:15 +08:00
|
|
|
which make it easier to attach a debugger or get a stack trace.""")
|
|
|
|
parser.add_argument("--crashing_tests_to_not_attempt_to_run_and_a_bug_is_filed",
|
|
|
|
metavar="TEST", type=str, nargs="+",
|
|
|
|
help="A set of tests to not attempt to run, since they crash and cannot be XFAILed.")
|
2023-05-31 03:16:24 +08:00
|
|
|
parser.add_argument("--ignore_failures",
|
|
|
|
default=False,
|
|
|
|
action="store_true",
|
|
|
|
help="return exit code 0 even if the test fails to unblock pipeline")
|
2021-05-20 08:36:00 +08:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = _get_argparse().parse_args()
|
|
|
|
|
2022-03-26 05:47:11 +08:00
|
|
|
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.
|
2022-12-09 21:13:15 +08:00
|
|
|
if args.config == "linalg":
|
2021-09-28 02:36:44 +08:00
|
|
|
config = LinalgOnTensorsBackendTestConfig(RefBackendLinalgOnTensorsBackend())
|
2022-12-07 21:51:24 +08:00
|
|
|
xfail_set = LINALG_XFAIL_SET
|
2024-04-19 02:47:19 +08:00
|
|
|
crashing_set = LINALG_CRASHING_SET
|
2024-02-16 01:08:48 +08:00
|
|
|
elif args.config == "stablehlo":
|
|
|
|
config = StablehloBackendTestConfig(LinalgOnTensorsStablehloBackend())
|
|
|
|
xfail_set = all_test_unique_names - STABLEHLO_PASS_SET
|
|
|
|
crashing_set = STABLEHLO_CRASHING_SET
|
2023-04-29 07:05:17 +08:00
|
|
|
elif args.config == "tosa":
|
2021-10-08 10:07:03 +08:00
|
|
|
config = TosaBackendTestConfig(LinalgOnTensorsTosaBackend())
|
|
|
|
xfail_set = all_test_unique_names - TOSA_PASS_SET
|
2023-04-29 07:05:17 +08:00
|
|
|
crashing_set = set()
|
2023-07-13 21:07:54 +08:00
|
|
|
elif args.config == "make_fx_tosa":
|
|
|
|
config = TosaBackendTestConfig(LinalgOnTensorsTosaBackend(), use_make_fx=True)
|
|
|
|
xfail_set = all_test_unique_names - MAKE_FX_TOSA_PASS_SET
|
|
|
|
crashing_set = set()
|
2022-12-09 21:13:15 +08:00
|
|
|
elif args.config == "native_torch":
|
2021-04-20 06:12:29 +08:00
|
|
|
config = NativeTorchTestConfig()
|
2023-04-29 07:05:17 +08:00
|
|
|
xfail_set = set()
|
|
|
|
crashing_set = set()
|
2022-12-09 21:13:15 +08:00
|
|
|
elif args.config == "torchscript":
|
2021-04-20 06:12:29 +08:00
|
|
|
config = TorchScriptTestConfig()
|
2023-04-29 07:05:17 +08:00
|
|
|
xfail_set = set()
|
|
|
|
crashing_set = set()
|
2022-12-09 21:13:15 +08:00
|
|
|
elif args.config == "lazy_tensor_core":
|
2022-06-10 03:56:01 +08:00
|
|
|
config = LazyTensorCoreTestConfig()
|
|
|
|
xfail_set = LTC_XFAIL_SET
|
2023-08-30 18:29:39 +08:00
|
|
|
crashing_set = LTC_CRASHING_SET
|
2024-04-13 07:07:56 +08:00
|
|
|
elif args.config == "fx_importer":
|
|
|
|
config = FxImporterTestConfig(RefBackendLinalgOnTensorsBackend())
|
2024-04-19 12:29:17 +08:00
|
|
|
xfail_set = FX_IMPORTER_XFAIL_SET
|
2024-04-13 07:07:56 +08:00
|
|
|
crashing_set = FX_IMPORTER_CRASHING_SET
|
2024-04-19 12:29:17 +08:00
|
|
|
elif args.config == "fx_importer_stablehlo":
|
|
|
|
config = FxImporterTestConfig(LinalgOnTensorsStablehloBackend(), "stablehlo")
|
|
|
|
xfail_set = FX_IMPORTER_STABLEHLO_XFAIL_SET
|
|
|
|
crashing_set = FX_IMPORTER_STABLEHLO_CRASHING_SET
|
2022-12-09 21:13:15 +08:00
|
|
|
elif args.config == "torchdynamo":
|
2023-05-12 13:46:33 +08:00
|
|
|
config = TorchDynamoTestConfig(RefBackendLinalgOnTensorsBackend())
|
2022-11-18 20:21:19 +08:00
|
|
|
xfail_set = TORCHDYNAMO_XFAIL_SET
|
2023-04-29 07:05:17 +08:00
|
|
|
crashing_set = TORCHDYNAMO_CRASHING_SET
|
2024-02-16 02:17:13 +08:00
|
|
|
elif args.config == "onnx":
|
|
|
|
config = OnnxBackendTestConfig(LinalgOnTensorsOnnxBackend())
|
|
|
|
xfail_set = ONNX_XFAIL_SET
|
|
|
|
crashing_set = ONNX_CRASHING_SET
|
2021-04-22 06:07:15 +08:00
|
|
|
|
2023-04-29 07:05:17 +08:00
|
|
|
do_not_attempt = set(args.crashing_tests_to_not_attempt_to_run_and_a_bug_is_filed or []).union(crashing_set)
|
2022-09-22 01:39:19 +08:00
|
|
|
available_tests = [test for test in GLOBAL_TEST_REGISTRY if test.unique_name not in do_not_attempt]
|
|
|
|
if args.crashing_tests_to_not_attempt_to_run_and_a_bug_is_filed is not None:
|
|
|
|
for arg in args.crashing_tests_to_not_attempt_to_run_and_a_bug_is_filed:
|
|
|
|
if arg not in all_test_unique_names:
|
2022-12-09 21:13:15 +08:00
|
|
|
print(f"ERROR: --crashing_tests_to_not_attempt_to_run_and_a_bug_is_filed argument '{arg}' is not a valid test name")
|
2022-09-22 01:39:19 +08:00
|
|
|
sys.exit(1)
|
|
|
|
|
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-09-22 01:39:19 +08:00
|
|
|
test for test in available_tests
|
2021-04-22 06:07:15 +08:00
|
|
|
if re.match(args.filter, test.unique_name)
|
|
|
|
]
|
|
|
|
if len(tests) == 0:
|
|
|
|
print(
|
2022-12-09 21:13:15 +08:00
|
|
|
f"ERROR: the provided filter {args.filter!r} does not match any tests"
|
2021-04-22 06:07:15 +08:00
|
|
|
)
|
2022-12-09 21:13:15 +08:00
|
|
|
print("The available tests are:")
|
2022-09-22 01:39:19 +08:00
|
|
|
for test in available_tests:
|
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-08-26 05:44:21 +08:00
|
|
|
results = run_tests(tests, config, args.sequential, args.verbose)
|
2021-05-20 08:36:00 +08:00
|
|
|
|
|
|
|
# Report the test results.
|
2023-06-09 16:47:07 +08:00
|
|
|
failed = report_results(results, xfail_set, args.verbose, args.config)
|
2024-04-16 12:20:23 +08:00
|
|
|
if args.config == "torchdynamo":
|
|
|
|
print("\033[91mWarning: the TorchScript based dynamo support is deprecated. "
|
|
|
|
"The config for torchdynamo is planned to be removed in the future.\033[0m")
|
2023-05-31 03:16:24 +08:00
|
|
|
if args.ignore_failures:
|
|
|
|
sys.exit(0)
|
2021-07-01 05:13:21 +08:00
|
|
|
sys.exit(1 if failed else 0)
|
2021-04-20 06:12:29 +08:00
|
|
|
|
2022-07-15 07:32:03 +08:00
|
|
|
def _suppress_warnings():
|
|
|
|
import warnings
|
|
|
|
# Ignore warning due to Python bug:
|
|
|
|
# https://stackoverflow.com/questions/4964101/pep-3118-warning-when-using-ctypes-array-as-numpy-array
|
|
|
|
warnings.filterwarnings("ignore",
|
|
|
|
message="A builtin ctypes object gave a PEP3118 format string that does not match its itemsize")
|
|
|
|
|
2022-12-09 21:13:15 +08:00
|
|
|
if __name__ == "__main__":
|
2022-07-15 07:32:03 +08:00
|
|
|
_suppress_warnings()
|
2021-04-20 06:12:29 +08:00
|
|
|
main()
|