Skip to content

Commit 140ffa6

Browse files
authored
Switch to pytest (#44)
* move to pytest; factor out operator registration into context class * fixes * fix * format * fix application test * remove test * fix * make all operators share the same default context * unify tests into single function (incorporate Erika's feedback) * reduce iterations of application tests to one for now due to CI inconsistency * oops
1 parent 130b6ea commit 140ffa6

File tree

60 files changed

+1634
-1841
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1634
-1841
lines changed

.github/actions/build/action.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/actions/test/action.yaml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ name: "Run test suite"
66
inputs:
77
test_flags:
88
required: false
9-
default: "--log tests.log --csv-latest tests_latest.csv"
9+
default: ""
1010
env_name:
1111
required: false
1212
default: "ci_env"
13-
testing_dir:
13+
extensive:
1414
required: false
15-
default: "testing"
15+
default: "false"
16+
test_suite:
17+
required: false
18+
default: "operators"
19+
description: "Which tests to run: 'operators', 'applications', or 'both'"
1620

1721
runs:
1822
using: "composite"
@@ -23,4 +27,23 @@ runs:
2327
shell: "bash"
2428
run: |
2529
source ${{ inputs.env_name }}/bin/activate
26-
./scripts/run_tests.py ${{ inputs.test_flags }} ${{ inputs.testing_dir }}
30+
31+
case "${{ inputs.test_suite }}" in
32+
operators)
33+
TEST_PATH="operators/"
34+
;;
35+
applications)
36+
TEST_PATH="applications/"
37+
;;
38+
*)
39+
echo "Invalid test_suite: ${{ inputs.test_suite }}"
40+
exit 1
41+
;;
42+
esac
43+
44+
if [ "${{ inputs.extensive }}" = "true" ]; then
45+
pytest $TEST_PATH --csv-output=tests_latest.csv ${{ inputs.test_flags }}
46+
else
47+
pytest -m "not extensive" $TEST_PATH --csv-output=tests_latest.csv ${{ inputs.test_flags }}
48+
fi
49+

.github/workflows/extensive.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@ jobs:
3232
with:
3333
env_name: ci_env
3434

35-
- name: Build
36-
uses: ./.github/actions/build
37-
with:
38-
env_name: ci_env
39-
extensive: "true"
40-
4135
- name: Test
4236
id: test
4337
continue-on-error: true
4438
uses: ./.github/actions/test
4539
with:
4640
env_name: ci_env
41+
extensive: "true"
42+
test_suite: "operators"
4743

4844
- name: Commit test results
4945
id: commit_results

.github/workflows/small.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,14 @@ jobs:
3131
with:
3232
env_name: ci_env
3333

34-
- name: Build
35-
uses: ./.github/actions/build
36-
with:
37-
env_name: ci_env
38-
extensive: "false"
39-
4034
- name: Test
4135
id: test
4236
continue-on-error: true
4337
uses: ./.github/actions/test
4438
with:
4539
env_name: ci_env
40+
extensive: "false"
41+
test_suite: "operators"
4642

4743
- name: Commit test results
4844
id: commit_results

.github/workflows/test-examples.yml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,14 @@ jobs:
3838
source ci_env/bin/activate
3939
pip install -r requirements_examples.txt
4040
41-
- name: Generate application tests
42-
shell: bash
43-
env:
44-
HOME: /workspace
45-
run: |
46-
source ci_env/bin/activate
47-
set -euxo pipefail
48-
mkdir -p testing
49-
cd testing
50-
python3 ../applications/discover_application_tests.py --output-dir .
51-
echo "Application tests generated:"
52-
ls -la
53-
5441
- name: Run examples
5542
id: test
5643
continue-on-error: true
57-
shell: bash
58-
env:
59-
HOME: /workspace
60-
run: |
61-
source ci_env/bin/activate
62-
./scripts/run_tests.py --log tests.log --csv-latest tests_latest.csv testing
44+
uses: ./.github/actions/test
45+
with:
46+
env_name: ci_env
47+
test_suite: "applications"
48+
test_flags: "--iterations 1"
6349

6450
- name: Commit example test results
6551
uses: ./.github/actions/commit_results

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,20 @@ All available operators can be found in `operators`. These each contain:
135135
> `source /opt/xilinx/xrt/setup.sh`
136136
> `source /path/to/ironenv/bin/activate`
137137
138-
To build and test all the operators, first generate a list of all test cases, then run them:
139-
``` python
140-
mkdir testing && cd testing
141-
../operators/common/discover_tests.py
142-
../scripts/run_tests.py --iter 1
138+
To build and test all the operators:
139+
``` bash
140+
pytest operators/ -m "not extensive"
143141
```
144142
145-
You can select a single test to run using the `--select` flag.
143+
To run the extensive test suite:
144+
``` bash
145+
pytest operators/
146+
```
147+
148+
To run a specific operator's tests:
149+
``` bash
150+
pytest operators/axpy/
151+
```
146152

147153
### Git Hooks (Optional but Recommended)
148154

applications/discover_application_tests.py

Lines changed: 0 additions & 122 deletions
This file was deleted.

applications/llama_3.2_1b/inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ def inference(
299299

300300
logging.info("Preparing AIE operators...")
301301
# At this point the model is fully described (operators and their dimensions and how to compile them)
302-
AIEOperatorBase.compile_all_operators()
303-
AIEOperatorBase.prepare_runtime()
302+
AIEOperatorBase.get_default_context().compile_all()
303+
AIEOperatorBase.get_default_context().prepare_runtime()
304304
logging.info("AIE operator preparation completed.")
305305
print(f"Starting text generation...")
306306
print(f"Generating {num_tokens} tokens...")

applications/llama_3.2_1b/test.py

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,50 @@
22
# SPDX-FileCopyrightText: Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import subprocess
6+
import pytest
57
from pathlib import Path
68

7-
# Get the directory containing this test file
8-
test_dir = Path(__file__).parent.absolute()
9+
test_dir = Path(__file__).parent
10+
weights_dir = Path("/srv")
911

10-
run = f"python3 {test_dir}/inference.py /srv/llama3.2-1b/model.safetensors /srv/llama3.2-1b/tokenizer.model --prompt_len 2048 --num_tokens 40"
1112

12-
checks = []
13+
def generate_test_params():
14+
prompt_lengths = [2048]
15+
num_tokens_list = [40]
1316

14-
metrics = [
15-
("Total", r" Total time: (?P<metric>[\d\.e\+-]+) seconds"),
16-
("TTFT", r" Prefill time: (?P<metric>[\d\.e\+-]+) seconds"),
17-
("TPS", r" Tokens per second: (?P<metric>[\d\.e\+-]+)"),
18-
("Num Tokens", r" Tokens generated: (?P<metric>[\d\.e\+-]+)"),
19-
]
17+
params = []
18+
names = []
19+
for prompt_len in prompt_lengths:
20+
for num_tokens in num_tokens_list:
21+
params.append((prompt_len, num_tokens))
22+
names.append(f"llama_3.2_1b_prompt_{prompt_len}_tokens_{num_tokens}")
23+
return params, names
24+
25+
26+
params, names = generate_test_params()
27+
28+
29+
@pytest.mark.metrics(
30+
TTFT=r"Prefill time: (?P<value>[\d\.e\+-]+) seconds",
31+
TPS=r"Tokens per second: (?P<value>[\d\.e\+-]+)",
32+
Num_Tokens=r"Tokens generated: (?P<value>[\d\.e\+-]+)",
33+
)
34+
@pytest.mark.parametrize("prompt_len,num_tokens", params, ids=names)
35+
def test_llama_3_2_1b(prompt_len, num_tokens):
36+
command = f"python3 {test_dir}/inference.py {weights_dir}/llama3.2-1b/model.safetensors {weights_dir}/llama3.2-1b/tokenizer.model --prompt_len {prompt_len} --num_tokens {num_tokens}"
37+
38+
result = subprocess.run(
39+
command,
40+
cwd=test_dir,
41+
shell=True,
42+
capture_output=True,
43+
text=True,
44+
timeout=300,
45+
)
46+
47+
assert (
48+
result.returncode == 0
49+
), f"Command failed with return code {result.returncode}\nStderr: {result.stderr}"
50+
51+
print(result.stdout)

0 commit comments

Comments
 (0)