Skip to content

Commit 8c23580

Browse files
authored
Testing scripts now depend on external source (#85)
As mentioned per [previous discussions](iree-org/iree#20138 (comment)), it would be ideal and sensible to have the data to be customizable per the user and sourced within IREE repo. From [this commit in IREE](iree-org/iree@5ea6faa), the JSON configs, MLIR tuner + E2E files now live in IREE. These pytest scripts now generate test cases and configure external files from an external source specified by arguments. FYI: the linting fixed up some files, so some of them are irrelevant to this PR but clean files are always good
1 parent 31b131f commit 8c23580

36 files changed

+154
-1848
lines changed

linalg_ops/attention/generate_e2e_attention_tests.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# Licensed under the Apache License v2.0 with LLVM Exceptions.
55
# See https://llvm.org/LICENSE.txt for license information.
66
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7-
"""Generator for e2e attention tests.
8-
"""
7+
"""Generator for e2e attention tests."""
98

109
import argparse
1110
import enum

linalg_ops/convolution/generate_e2e_conv2d_tests.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# Licensed under the Apache License v2.0 with LLVM Exceptions.
55
# See https://llvm.org/LICENSE.txt for license information.
66
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7-
"""Generator for e2e conv2d tests.
8-
"""
7+
"""Generator for e2e conv2d tests."""
98

109
from typing import Optional
1110
import argparse

linalg_ops/matmul/generate_e2e_matmul_tests.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# Licensed under the Apache License v2.0 with LLVM Exceptions.
55
# See https://llvm.org/LICENSE.txt for license information.
66
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7-
"""iree_generated_e2e_matmul_test generator for e2e matmul tests.
8-
"""
7+
"""iree_generated_e2e_matmul_test generator for e2e matmul tests."""
98

109
import argparse
1110
import enum

sharktank_models/action.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ inputs:
1919
description: "Type of target to test"
2020
GPU:
2121
description: "Type of GPU to test"
22+
EXTERNAL_TEST_FILE_DIRECTORY:
23+
description: "The directory of test files and configurations"
24+
QUALITY_TEST_DIRECTORY:
25+
description: "The directory of quality tests"
26+
BENCHMARK_TEST_DIRECTORY:
27+
description: "The directory of benchmark tests"
2228

2329
runs:
2430
using: "composite"
@@ -67,7 +73,9 @@ runs:
6773
--log-cli-level=info \
6874
--durations=0 \
6975
--timeout=1200 \
70-
--capture=no
76+
--capture=no \
77+
--test-file-directory=${{ inputs.QUALITY_TEST_DIRECTORY }} \
78+
--external-file-directory=${{ inputs.EXTERNAL_TEST_FILE_DIRECTORY }}
7179
env:
7280
ROCM_CHIP: ${{ inputs.CHIP }}
7381
SKU: ${{ inputs.SKU }}
@@ -82,7 +90,10 @@ runs:
8290
${GITHUB_ACTION_PATH}/sharktank_models/benchmarks \
8391
--log-cli-level=info \
8492
--retries=7 \
85-
--timeout=600
93+
--timeout=600 \
94+
--test-file-directory=${{ inputs.BENCHMARK_TEST_DIRECTORY }} \
95+
--external-file-directory=${{ inputs.EXTERNAL_TEST_FILE_DIRECTORY }}
96+
8697
echo "$(<${GITHUB_ACTION_PATH}/job_summary.md )" >> $GITHUB_STEP_SUMMARY
8798
env:
8899
ROCM_CHIP: ${{ inputs.CHIP }}

sharktank_models/benchmarks/README.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33
### Adding your own model
44

55
- To add your own model, create a directory under `benchmarks` and add JSON files that correspond to the submodels and chip. Please follow the [JSON file schema in this README file](#required-and-optional-fields-for-the-json-model-file)
6+
- Please refer to the sample file `sdxl/clip_rocm.json`
67

78
### How to run the benchmark tests
89

910
```
11+
# Retrieving test files and external test files
12+
git clone https://github.com/iree-org/iree.git
13+
export PATH_TO_TESTS=iree/tests/external/iree-test-suites/sharktank_models/benchmarks
14+
export PATH_TO_EXTERNAL_FILES=iree/build_tools/pkgci/external_test_suite
15+
16+
# running benchmark tests
17+
git clone https://github.com/iree-org/iree-test-suites.git
1018
pytest sharktank_models/benchmarks/ \
1119
--log-cli-level=info \
1220
--timeout=600 \
13-
--retries=7
21+
--retries=7 \
22+
--test-file-directory=${PATH_TO_TESTS} \
23+
--external-file-directory=${PATH_TO_EXTERNAL_FILES}
1424
```
1525

1626
### Required and optional fields for the JSON model file
@@ -21,7 +31,7 @@ pytest sharktank_models/benchmarks/ \
2131
| compilation_required | optional | boolean | If true, this will let the benchmark test know that it needs to compile a file |
2232
| compiled_file_name | optional | string | When the compilation occurs, this will be the file name |
2333
| compile_flags | optional | array | An array of compiler flag options |
24-
| mlir_file_path | optional | string | Path to where the mlir file to compile is |
34+
| mlir_file_name | optional | string | The name of the MLIR file |
2535
| modules | optional | array | Specific to e2e, add modules here to include in the benchmarking test |
2636
| function_run | required | string | The function that the `iree-benchmark-module` will run adnd benchmark |
2737
| benchmark_repetitions | required | float | The number of times the benchmark tests will repeat |
@@ -31,7 +41,7 @@ pytest sharktank_models/benchmarks/ \
3141
| golden_time_ms | optional | object | An object of golden times, where the key is the sku and the value is the golden time in ms, (ex: `{"mi250": 100}`) |
3242
| golden_dispatch | optional | object | An object of golden dispatches, where the key is the sku and the value is the golden dispatch count, (ex: `{"mi250": 1602}`) |
3343
| golden_size | optional | object | An object of golden sizes, where the key is the sku and the value is the golden size in bytes, (ex: `{"mi250": 2000000}`) |
34-
| specific_chip_to_ignore | optional | array | An array of chip values, where the benchmark tests will ignore the chips specified |
44+
| specific_chip_to_ignore | optional | array | An array of chip values, where the benchmark tests will ignore the chips specified |
3545
| real_weights_file_name | optional | string | If real weights is a different file name, specify it here in order to get the correct real weights file |
3646

3747
Please feel free to look at any JSON examples under a model directory (ex: sdxl)

sharktank_models/benchmarks/conftest.py

+45-14
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,43 @@
1919
logger = logging.getLogger(__name__)
2020

2121

22+
def pytest_addoption(parser):
23+
parser.addoption(
24+
"--test-file-directory",
25+
action="store",
26+
help="The directory of benchmark test JSON files to build and run test cases",
27+
)
28+
29+
parser.addoption(
30+
"--external-file-directory",
31+
action="store",
32+
help="The directory of external test files (ex: E2E MLIR, tuner files)",
33+
)
34+
35+
2236
def pytest_sessionstart(session):
37+
logger.info("Pytest benchmark test session is starting")
2338
with open("job_summary.md", "a") as job_summary, open(
2439
"job_summary.json", "w+"
2540
) as content:
2641
print(f"{sku.upper()} Complete Benchmark Summary:\n", file=job_summary)
2742
json.dump({}, content)
2843

29-
logger.info("Pytest benchmark test session is starting")
44+
# Collect all .json files for benchmark tests
45+
session.config.benchmark_test_files = []
46+
path_of_benchmark_tests = Path(session.config.getoption("test_file_directory"))
47+
test_files = sorted(path_of_benchmark_tests.glob("**/*.json"))
48+
session.config.benchmark_test_files.extend(test_files)
49+
50+
# Keeping track of all external test files and their paths
51+
session.config.external_test_files = {}
52+
path_of_external_test_files = Path(
53+
session.config.getoption("external_file_directory")
54+
)
55+
external_files = sorted(path_of_external_test_files.glob("*"))
56+
for external_file in external_files:
57+
file_name = external_file.name
58+
session.config.external_test_files[file_name] = external_file
3059

3160

3261
def pytest_sessionfinish(session, exitstatus):
@@ -66,30 +95,32 @@ def pytest_sessionfinish(session, exitstatus):
6695

6796

6897
def pytest_collect_file(parent, file_path):
69-
if (
70-
file_path.suffix == ".json"
71-
and "job_summary" not in file_path.name
72-
and "benchmarks" in str(THIS_DIR)
73-
):
98+
# Run only the benchmark test for this directory
99+
if "model_benchmark_run" in str(file_path):
74100
return SharkTankModelBenchmarkTests.from_parent(parent, path=file_path)
75101

76102

77103
@dataclass(frozen=True)
78104
class BenchmarkTestSpec:
79105
model_name: str
80106
benchmark_file_name: str
107+
file_path: Path
108+
external_test_files: dict
81109

82110

83111
class SharkTankModelBenchmarkTests(pytest.File):
84112
def collect(self):
85-
path = str(self.path).split("/")
86-
benchmark_file_name = path[-1].replace(".json", "")
87-
model_name = path[-2]
113+
for file_path in self.config.benchmark_test_files:
114+
benchmark_file_name = file_path.stem
115+
model_name = str(file_path.parent)
88116

89-
item_name = f"{model_name} :: {benchmark_file_name}"
117+
item_name = f"{model_name} :: {benchmark_file_name}"
90118

91-
spec = BenchmarkTestSpec(
92-
model_name=model_name, benchmark_file_name=benchmark_file_name
93-
)
119+
spec = BenchmarkTestSpec(
120+
model_name=model_name,
121+
benchmark_file_name=benchmark_file_name,
122+
file_path=file_path,
123+
external_test_files=self.config.external_test_files,
124+
)
94125

95-
yield ModelBenchmarkRunItem.from_parent(self, name=item_name, spec=spec)
126+
yield ModelBenchmarkRunItem.from_parent(self, name=item_name, spec=spec)

sharktank_models/benchmarks/external_test_files/sdxl_pipeline_bench_f16.mlir

-23
This file was deleted.

sharktank_models/benchmarks/model_benchmark_run.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,13 @@ def __init__(self, spec, **kwargs):
9191
super().__init__(**kwargs)
9292
self.spec = spec
9393
self.model_name = self.spec.model_name
94+
self.file_path = self.spec.file_path
9495
self.benchmark_file_name = self.spec.benchmark_file_name
95-
SUBMODEL_FILE_PATH = (
96-
THIS_DIR / f"{self.model_name}/{self.benchmark_file_name}.json"
97-
)
9896
split_file_name = self.benchmark_file_name.split("_")
9997
self.submodel_name = "_".join(split_file_name[:-1])
10098
type_of_backend = split_file_name[-1]
10199

102-
with open(SUBMODEL_FILE_PATH, "r") as file:
100+
with open(self.file_path, "r") as file:
103101
data = json.load(file)
104102

105103
self.inputs = data.get("inputs", [])
@@ -124,7 +122,10 @@ def __init__(self, spec, **kwargs):
124122
# custom configurations related to e2e testing
125123
self.compilation_required = data.get("compilation_required", False)
126124
self.compiled_file_name = data.get("compiled_file_name")
127-
self.mlir_file_path = data.get("mlir_file_path", "")
125+
mlir_file_name = data.get("mlir_file_name", "")
126+
external_test_files = self.spec.external_test_files
127+
if mlir_file_name:
128+
self.mlir_file_path = external_test_files.get(mlir_file_name, "")
128129
self.modules = data.get("modules", [])
129130
self.device = data.get("device")
130131

sharktank_models/benchmarks/sdxl/clip_rocm.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
"mi308": 1.1
1919
},
2020
"golden_time_ms": {
21-
"mi250": 14.5,
21+
"mi250": 9.0,
2222
"mi300": 15.0,
23-
"mi308": 15.0
23+
"mi308": 12.0
2424
},
2525
"golden_dispatch": {
26-
"mi250": 1139,
27-
"mi300": 1139,
28-
"mi308": 1139
26+
"mi250": 794,
27+
"mi300": 794,
28+
"mi308": 794
2929
},
3030
"golden_size": {
31-
"mi250": 860000,
32-
"mi300": 860000,
33-
"mi308": 860000
31+
"mi250": 460000,
32+
"mi300": 460000,
33+
"mi308": 460000
3434
}
3535
}

sharktank_models/benchmarks/sdxl/e2e_rocm.json

-44
This file was deleted.

sharktank_models/benchmarks/sdxl/punet_int8_fp16_rocm.json

-35
This file was deleted.

sharktank_models/benchmarks/sdxl/punet_int8_fp8_rocm.json

-35
This file was deleted.

0 commit comments

Comments
 (0)