Skip to content

[AIMIGRAPHX-1151] Add pytest bridge for unit tests#5006

Open
eddieliao wants to merge 6 commits into
developfrom
pytest_unit_tests
Open

[AIMIGRAPHX-1151] Add pytest bridge for unit tests#5006
eddieliao wants to merge 6 commits into
developfrom
pytest_unit_tests

Conversation

@eddieliao

Copy link
Copy Markdown
Contributor

Motivation

Adds a pytest bridge to support running of CTest unit tests with pytest.

Technical Details

A specific test dir can be manually passed in with MIGRAPHX_TEST_DIR. Mostly generated with Claude; tested with CI build.

Example of output:

[root@efac41cc576b ROCM-26203]# pytest --pyargs migraphx_tests -v
==================================================================================================================== test session starts =====================================================================================================================
platform linux -- Python 3.12.13, pytest-9.1.1, pluggy-1.6.0 -- /opt/python/bin/python
cachedir: .pytest_cache
rootdir: /code/ROCM-26203
collected 423 items                                                                                                                                                                                                                                          

test_migraphx.py::test_migraphx[test_adjust_allocation] PASSED                                                                                                                                                                                         [  0%]
test_migraphx.py::test_migraphx[test_algorithm] PASSED                                                                                                                                                                                                 [  0%]
test_migraphx.py::test_migraphx[test_analyze_streams] PASSED                                                                                                                                                                                           [  0%]
test_migraphx.py::test_migraphx[test_any_ptr] PASSED                                                                                                                                                                                                   [  0%]
test_migraphx.py::test_migraphx[test_argument_test] PASSED                                                                                                                                                                                             [  1%]
test_migraphx.py::test_migraphx[test_auto_contiguous_test] PASSED                                                                                                                                                                                      [  1%]
test_migraphx.py::test_migraphx[test_autocast_fp8] PASSED                                                                                                                                                                                              [  1%]
test_migraphx.py::test_migraphx[test_base64_test] PASSED                                                                                                                                                                                               [  1%]
test_migraphx.py::test_migraphx[test_bf16] PASSED                                                                                                                                                                                                      [  2%]
test_migraphx.py::test_migraphx[test_bit_signal] PASSED                                                                                                                                                                                                [  2%]
test_migraphx.py::test_migraphx[test_byte_test] PASSED                                                                                                                                                                                                 [  2%]
test_migraphx.py::test_migraphx[test_check_shapes_test] PASSED                                                                                                                                                                                         [  2%]
test_migraphx.py::test_migraphx[test_comment_test] PASSED                                                                                                                                                                                              [  3%]
test_migraphx.py::test_migraphx[test_common_dims] PASSED                                                                                                                                                                                               [  3%]
test_migraphx.py::test_migraphx[test_const_eval_test] PASSED                                                                                                                                                                                           [  3%]
test_migraphx.py::test_migraphx[test_convert_inf] PASSED                                                                                                                                                                                               [  3%]
test_migraphx.py::test_migraphx[test_convert_to_json] PASSED                                                                                                                                                                                           [  4%]
test_migraphx.py::test_migraphx[test_dead_code_elimination_test] PASSED                                                                                                                                                                                [  4%]
test_migraphx.py::test_migraphx[test_debug_symbols_exception_test] PASSED                                                                                                                                                                              [  4%]
test_migraphx.py::test_migraphx[test_debug_symbols_test] PASSED                                                                                                                                                                                        [  4%]
test_migraphx.py::test_migraphx[test_dim_like_test] PASSED                                                                                                                                                                                             [  4%]
test_migraphx.py::test_migraphx[test_dom] PASSED                                                                                                                                                                                                       [  5%]
test_migraphx.py::test_migraphx[test_dot_apply_alpha_beta_test] PASSED                                                                                                                                                                                 [  5%]
test_migraphx.py::test_migraphx[test_eliminate_allocation_test] PASSED                                                                                                                                                                                 [  5%]
test_migraphx.py::test_migraphx[test_eliminate_common_subexpression_test] PASSED                                                                                                                                                                       [  5%]
test_migraphx.py::test_migraphx[test_eliminate_concat_test] PASSED                                                                                                                                                                                     [  6%]
test_migraphx.py::test_migraphx[test_eliminate_contiguous_test] PASSED                                                                                                                                                                                 [  6%]
test_migraphx.py::test_migraphx[test_eliminate_convert_test] PASSED                                                                                                                                                                                    [  6%]
test_migraphx.py::test_migraphx[test_eliminate_data_type_test] PASSED
...

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

@eddieliao eddieliao requested a review from Copilot June 23, 2026 00:48
@eddieliao eddieliao self-assigned this Jun 23, 2026
@eddieliao eddieliao added Continous Integration Pull request updates parts of continous integration pipeline Tooling Touches tools used for or that aid in MIGraphX development and debugging python Pull requests that update python code Changelog: Not Applicable This PR is not to be included in the Changelog. labels Jun 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a Python/pytest “bridge” to run MIGraphX’s existing CTest-registered unit test executables under pytest, and installs that bridge alongside the installed C++ tests so it can be used from packaged test artifacts (e.g., the tests component / migraphx_tests wheel).

Changes:

  • Add test/test_pytest_bridge.py, which discovers tests via ctest --show-only=json-v1 (or by scanning bin/) and runs each test executable as a pytest parameterized case.
  • Install the bridge script via rocm_install_test(...) so it is available next to installed test binaries.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
test/test_pytest_bridge.py Adds pytest-based discovery/execution wrapper around existing CTest tests.
test/CMakeLists.txt Installs the pytest bridge script alongside installed C++ tests.

Comment thread test/test_pytest_bridge.py Outdated
Comment on lines +65 to +72
def _make_test(name, command, env=None, fail_regexes=None, skip=None):
return {
"name": name,
"command": command,
"env": env or {},
"fail_regexes": fail_regexes or ["FAILED"],
"skip": skip,
}
Comment thread test/test_pytest_bridge.py Outdated
Comment on lines +103 to +119
env_extra = {}
fail_regexes = None
needs_fixture = False
for prop in entry.get("properties", []):
name = prop.get("name")
if name == "ENVIRONMENT":
for item in prop.get("value", []):
key, _, value = item.partition("=")
env_extra[key] = value
elif name == "FAIL_REGULAR_EXPRESSION" and prop.get("value"):
value = prop["value"]
fail_regexes = value if isinstance(value, list) else [value]
elif name in _FIXTURE_PROPS and prop.get("value"):
needs_fixture = True
tests.append(_make_test(
entry["name"], command, env=env_extra, fail_regexes=fail_regexes,
skip="requires ctest fixtures; run via ctest" if needs_fixture else None))
Comment on lines +146 to +153
result = subprocess.run(
spec["command"],
cwd=_TEST_DIR,
env=_make_env(spec["env"]),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5006   +/-   ##
========================================
  Coverage    92.71%   92.71%           
========================================
  Files          594      594           
  Lines        31465    31478   +13     
========================================
+ Hits         29170    29183   +13     
  Misses        2295     2295           

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Jun 23, 2026

Copy link
Copy Markdown
Test Batch New Rate (79f476) Old Rate (879901) Diff Status
torchvision-resnet50 64 1,700.98 3,150.16 -46.00% 🔴
torchvision-resnet50_fp16 64 4,400.17 6,674.14 -34.07% 🔴
torchvision-densenet121 32 2,479.56 2,706.47 -8.38% 🔴
torchvision-densenet121_fp16 32 3,891.27 4,555.16 -14.57% 🔴
torchvision-inceptionv3 32 1,778.28 1,799.35 -1.17%
torchvision-inceptionv3_fp16 32 1,175.69 2,816.26 -58.25% 🔴
cadene-inceptionv4 16 223.11 826.17 -73.00% 🔴
cadene-resnext64x4 16 235.68 784.34 -69.95% 🔴
slim-mobilenet 64 7,356.84 8,430.68 -12.74% 🔴
slim-nasnetalarge 64 210.36 228.89 -8.10% 🔴
slim-resnet50v2 64 2,991.19 3,327.72 -10.11% 🔴
bert-mrpc-onnx 8 1,171.38 1,170.83 0.05%
bert-mrpc-tf 1 66.78 486.06 -86.26% 🔴
pytorch-examples-wlang-gru 1 145.91 331.20 -55.94% 🔴
pytorch-examples-wlang-lstm 1 283.77 451.67 -37.17% 🔴
torchvision-resnet50_1 1 121.43 749.60 -83.80% 🔴
cadene-dpn92_1 1 387.86 455.28 -14.81% 🔴
cadene-resnext101_1 1 134.79 363.76 -62.95% 🔴
onnx-taau-downsample 1 327.44 400.78 -18.30% 🔴
dlrm-criteoterabyte 1 1.11 32.72 -96.61% 🔴
dlrm-criteoterabyte_fp16 1 31.94 52.40 -39.04% 🔴
agentmodel 1 9,874.30 11,888.91 -16.95% 🔴
unet_fp16 2 51.09 56.49 -9.55% 🔴
resnet50v1_fp16 1 974.67 962.78 1.23%
resnet50v1_int8 1 897.71 936.53 -4.15%
bert_base_cased_fp16 64 518.53 1,102.74 -52.98% 🔴
bert_large_uncased_fp16 32 334.92 347.40 -3.59%
bert_large_fp16 1 36.48 204.06 -82.12% 🔴
distilgpt2_fp16 16 2,048.29 2,095.69 -2.26%
yolov5s 1 558.96 559.75 -0.14%
tinyllama 1 18.95 46.03 -58.82% 🔴
vicuna-fastchat 1 10.45 44.19 -76.36% 🔴
whisper-tiny-encoder 1 415.01 419.99 -1.19%
whisper-tiny-decoder 1 412.34 413.71 -0.33%
llama2_7b 1 17.25 20.45 -15.65% 🔴
qwen1.5-7b 1 4.70 23.67 -80.13% 🔴
phi3-3.8b 1 2.54 26.83 -90.52% 🔴
llama3-8b 1 4.95 21.82 -77.30% 🔴
whisper-large-encoder 1 5.36 10.31 -47.95% 🔴
whisper-large-decoder 1 94.84 106.08 -10.59% 🔴
mistral-7b 1 19.08 23.83 -19.93% 🔴
FLUX.1-schnell 1 817.25 742.79 10.03% 🔆

Regressions detected 🔴

@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Jun 23, 2026

Copy link
Copy Markdown
Test Status Result
bert-mrpc-onnx PASSED: MIGraphX meets tolerance
bert-mrpc-tf PASSED: MIGraphX meets tolerance
pytorch-examples-wlang-gru PASSED: MIGraphX meets tolerance
pytorch-examples-wlang-lstm PASSED: MIGraphX meets tolerance
dlrm-criteoterabyte PASSED: MIGraphX meets tolerance
agentmodel PASSED: MIGraphX meets tolerance
unet PASSED: MIGraphX meets tolerance
resnet50v1 PASSED: MIGraphX meets tolerance
bert_base_cased_fp16 PASSED: MIGraphX meets tolerance
bert_large_uncased_fp16 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
bert_large PASSED: MIGraphX meets tolerance
yolov5s PASSED: MIGraphX meets tolerance
tinyllama PASSED: MIGraphX meets tolerance
vicuna-fastchat PASSED: MIGraphX meets tolerance
whisper-tiny-encoder PASSED: MIGraphX meets tolerance
whisper-tiny-decoder PASSED: MIGraphX meets tolerance
distilgpt2_fp16 PASSED: MIGraphX meets tolerance
llama2_7b PASSED: MIGraphX meets tolerance
qwen1.5-7b PASSED: MIGraphX meets tolerance
phi3-3.8b PASSED: MIGraphX meets tolerance
llama3-8b PASSED: MIGraphX meets tolerance
whisper-large-decoder PASSED: MIGraphX meets tolerance
mistral-7b PASSED: MIGraphX meets tolerance
FLUX.1-schnell PASSED: MIGraphX meets tolerance

@pfultz2

pfultz2 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

pytest should run the tests with CTest. It looks like its trying to extract the command which seems complicated due to fixtures. Instead it should find each test and skip fixtures. Then run the test with ctest(which should automatically run the fixtures).

@pfultz2

pfultz2 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Since pytest runs serially we dont have to worry about RESOURCE_LOCK. If we are going to use pytest-xdist which runs tests in parallel then we would need to setup xdist_group for the resource locks.

And even simpler pytest bridge is to add just one test and call ctest -j$(nproc) then we dont have to worry about translating test cases. Since its only a bridge to run the tests there isn't a need to run tests individually within pytest.

@eddieliao eddieliao marked this pull request as ready for review June 23, 2026 18:36
@eddieliao eddieliao requested a review from causten as a code owner June 23, 2026 18:36
@eddieliao

Copy link
Copy Markdown
Contributor Author

And even simpler pytest bridge is to add just one test and call ctest -j$(nproc) then we dont have to worry about translating test cases. Since its only a bridge to run the tests there isn't a need to run tests individually within pytest.

Implemented this which simplifies the bridge by quite a lot. Only downside is that when run through pytest you only see 1 test and no progress updates until something either fails or it all succeeds.

[root@efac41cc576b ROCM-26203]# pytest --pyargs migraphx_tests -v
======================================================================================================================== test session starts =========================================================================================================================
platform linux -- Python 3.12.13, pytest-9.1.1, pluggy-1.6.0 -- /opt/python/bin/python
cachedir: .pytest_cache
rootdir: /code/ROCM-26203
collected 1 item                                                                                                                                                                                                                                                     

test_pytest_bridge.py::test_migraphx PASSED                                                                                                                                                                                                                    [100%]

=================================================================================================================== 1 passed in 290.84s (0:04:50) ====================================================================================================================

@pfultz2

pfultz2 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

You can use the -s flag I think to show the output.

@eddieliao

Copy link
Copy Markdown
Contributor Author

Requires ROCm/rocm-cmake#289 to be merged first.

@eddieliao eddieliao changed the title [AIMIGRAPHX-1127] Add pytest bridge for unit tests [AIMIGRAPHX-1151] Add pytest bridge for unit tests Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Not Applicable This PR is not to be included in the Changelog. Continous Integration Pull request updates parts of continous integration pipeline python Pull requests that update python code Tooling Touches tools used for or that aid in MIGraphX development and debugging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants