Skip to content

Add adaptive benchmarking to MIGraphX - #5133

Draft
justinrosner wants to merge 7 commits into
developfrom
1169-fix-timeouts
Draft

Add adaptive benchmarking to MIGraphX#5133
justinrosner wants to merge 7 commits into
developfrom
1169-fix-timeouts

Conversation

@justinrosner

@justinrosner justinrosner commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Motivation

GPU JIT tuning timed every solution candidate with a fixed schedule (20 samples of a bundle-sized inner loop), so the wall-clock cost of tuning scaled with how slow the candidates happened to be. A problem with a long solution list, or with candidates in the tens of milliseconds, could spend minutes in compile_ops and hit compile timeouts, and there was no way to cap or configure that cost.

Technical Details

Two-stage candidate selection

When more than 10 valid candidates are available:

  1. Briefly benchmark every candidate in a coarse ranking stage.
  2. Precisely benchmark the fastest 10 candidates.
  3. Select the fastest successful precise result.

When there are 10 or fewer candidates, every candidate is measured precisely and the coarse stage is skipped. If a shortlisted candidate fails, the next coarse-ranked candidate is promoted.

Hard per-candidate execution budget

Each candidate is capped at 1 + 20 × benchmark_bundle executions across initialization, estimation, coarse timing, and precise timing. This matches the work allowed by the previous fixed 20-sample benchmark rather than adding coarse and precise work on top of it.

The timing scheduler still adapts bundle and sample counts to candidate speed, but cannot exceed this lifetime budget.

Performance

Compared with develop across tier-1 models:

  • 28.0% geomean compile-time reduction (1.39× speedup)
  • 46.3% reduction in total compilation time
    • 6,579 seconds reduced to 3,533 seconds
  • Inference geomean improved by 1.26%

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.

Follow the LLVM AI Tool Use Policy for contributions using AI.

@justinrosner

justinrosner commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Note: This is still in draft as I'm collecting some more data for how this holds up across a larger set of models.

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 introduces an adaptive, two-stage GPU JIT tuning benchmark path to bound compile-time spent timing candidate solutions while still selecting the fastest valid kernel configuration.

Changes:

  • Added adaptive timing primitives (make_timing_schedule, adaptive_time_loop, adaptive_time_topk) and an adaptive_time_program entry point.
  • Integrated adaptive two-stage tuning into gpu::compile_ops, with JSON/reflectable tuning overrides plumbed through GPU target backend options.
  • Added GPU unit tests covering schedule construction, override resolution/validation, and top‑k selection behavior; updated the changelog.

Reviewed changes

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

Show a summary per file
File Description
test/gpu/time_op.cpp Adds unit tests for timing schedule math, override resolution, and top‑k candidate selection.
src/targets/gpu/time_op.cpp Implements adaptive timing schedule computation, adaptive loop timing, and top‑k benchmarking logic; refactors program timing to share logic.
src/targets/gpu/target.cpp Threads tuning overrides through backend options into compile_ops.
src/targets/gpu/include/migraphx/gpu/time_op.hpp Exposes new adaptive timing/tuning APIs and option structs.
src/targets/gpu/include/migraphx/gpu/compile_ops.hpp Adds compile_ops_tuning_overrides (reflectable) and a tuning field on compile_ops.
src/targets/gpu/compile_ops.cpp Implements override resolution and replaces fixed benchmarking with adaptive two-stage timing and failure-tolerant selection.
CHANGELOG.md Documents the new adaptive GPU JIT tuning behavior.
Suppressed comments (1)

src/targets/gpu/time_op.cpp:268

  • Using std::accumulate here purely for side effects (and ignoring its return value) is hard to read/maintain. A simple loop makes the intent ("collect up to top_k successful precise timings, continuing past failures") explicit.
        std::accumulate(ranked.begin(), ranked.end(), std::size_t{0}, [&](auto measured, auto i) {
            if(measured >= top_k)
                return measured;
            auto candidate_options         = precise_options;
            candidate_options.estimated_ms = *coarse[i];

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/targets/gpu/include/migraphx/gpu/time_op.hpp
Comment thread src/targets/gpu/time_op.cpp
@justinrosner justinrosner changed the title [DRAFT] Add adaptive two-stage benchmarking Add adaptive benchmarking to MIGraphX Aug 18, 2026
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5133      +/-   ##
===========================================
+ Coverage    93.12%   93.13%   +0.01%     
===========================================
  Files          625      625              
  Lines        33162    33252      +90     
===========================================
+ Hits         30879    30967      +88     
- Misses        2283     2285       +2     

see 2 files with indirect coverage changes

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

@justinrosner
justinrosner requested a balanced review from Copilot August 18, 2026 17:29

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/targets/gpu/time_op.cpp:118

  • These existing environment variables are documented as setting the bundle size and run count exactly (docs/reference/MIGraphX-dev-env-vars.rst:778-786), but the adaptive path now treats them only as preferred_bundle and max_samples. For example, a slow candidate with MIGRAPHX_BENCHMARKING_BUNDLE=10 is still scheduled with bundle 1, and MIGRAPHX_BENCHMARKING_NRUNS=20 may produce only 4 samples. Because adaptive timing is now the default compile_ops path, this silently breaks the manual benchmarking overrides. Please either preserve exact override semantics within the hard execution budget or explicitly replace/deprecate this interface and update its documentation.
    if(const auto bundle = benchmarking_override(MIGRAPHX_BENCHMARKING_BUNDLE{}))
        options.preferred_bundle = *bundle;
    if(const auto samples = benchmarking_override(MIGRAPHX_BENCHMARKING_NRUNS{}))
        options.max_samples = *samples;

@justinrosner
justinrosner marked this pull request as ready for review August 18, 2026 17:37
@justinrosner
justinrosner requested review from a team and causten as code owners August 18, 2026 17:37
@justinrosner

Copy link
Copy Markdown
Contributor Author

NOTE: Will add reviewers once the performance CI comes back clean

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

gh-app-migraphx-bot-pr-write Bot commented Aug 19, 2026

Copy link
Copy Markdown
Test Batch New Rate (9be7c2) Old Rate (3a503c)* Diff Status
torchvision-resnet50 64 3,320.16 3,264.92 1.69%
torchvision-resnet50_fp16 64 7,877.26 7,548.67 4.35%
torchvision-densenet121 32 2,489.59 2,483.99 0.23%
torchvision-densenet121_fp16 32 5,022.52 5,004.24 0.37%
torchvision-inceptionv3 32 2,070.19 2,058.51 0.57%
torchvision-inceptionv3_fp16 32 4,457.60 4,416.99 0.92%
cadene-inceptionv4 16 817.25 820.61 -0.41%
cadene-resnext64x4 16 782.79 782.78 0.00%
slim-mobilenet 64 8,384.36 8,386.36 -0.02%
slim-nasnetalarge 64 228.26 228.86 -0.26%
slim-resnet50v2 64 3,237.41 3,180.91 1.78%
bert-mrpc-onnx 8 1,169.65 1,168.84 0.07%
bert-mrpc-tf 1 497.97 498.63 -0.13%
pytorch-examples-wlang-gru 1 488.34 473.35 3.16%
pytorch-examples-wlang-lstm 1 409.16 384.83 6.32% 🔆
torchvision-resnet50_1 1 1,054.70 1,046.63 0.77%
cadene-dpn92_1 1 442.35 437.32 1.15%
cadene-resnext101_1 1 365.71 365.89 -0.05%
onnx-taau-downsample 1 849.38 844.09 0.63%
dlrm-criteoterabyte 1 32.25 32.42 -0.54%
dlrm-criteoterabyte_fp16 1 51.67 51.80 -0.26%
agentmodel 1 15,165.95 9,209.12 64.68% 🔆
unet_fp16 2 58.30 58.80 -0.84%
resnet50v1_fp16 1 1,442.10 1,366.11 5.56% 🔆
resnet50v1_int8 1 1,777.84 1,883.96 -5.63% 🔴
bert_base_cased_fp16 64 1,097.69 1,098.16 -0.04%
bert_large_uncased_fp16 32 345.45 345.59 -0.04%
bert_large_fp16 1 205.55 206.59 -0.50%
distilgpt2_fp16 16 2,087.55 2,092.89 -0.26%
yolov5s 1 564.53 558.33 1.11%
tinyllama 1 45.83 45.83 -0.01%
vicuna-fastchat 1 44.25 44.20 0.12%
whisper-tiny-encoder 1 411.68 411.87 -0.05%
whisper-tiny-decoder 1 409.18 408.48 0.17%
llama2_7b 1 20.86 20.84 0.12%
qwen1.5-7b 1 23.66 23.58 0.33%
phi3-3.8b 1 26.70 26.72 -0.06%
llama3-8b 1 21.75 21.80 -0.25%
whisper-large-encoder 1 10.17 10.18 -0.10%
whisper-large-decoder 1 107.13 105.30 1.74%
mistral-7b 1 23.84 23.78 0.26%
FLUX.1-schnell 1 785.97 755.22 4.07%

Regressions detected 🔴

* No develop baseline was found for this PR's branch point; compared against the latest available develop run instead.

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

Copy link
Copy Markdown
Test Status Result
bert-mrpc-onnx PASSED: MIGraphX meets tolerance
bert-mrpc-tf ERROR - check error output
traceback
Traceback (most recent call last):
File "/src/AMDMIGraphX/tools/accuracy/accuracy_checker.py", line 377, in
main()
File "/src/AMDMIGraphX/tools/accuracy/accuracy_checker.py", line 313, in main
import tensorflow as tf
File "/usr/local/lib/python3.12/dist-packages/tensorflow/init.py", line 40, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow # pylint: disable=unused-import
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 37, in
self_check.preload_check()
File "/usr/local/lib/python3.12/dist-packages/tensorflow/python/platform/self_check.py", line 63, in preload_check
from tensorflow.python.platform import _pywrap_cpu_feature_guard
ImportError: libnuma.so.1: cannot open shared object file: No such file or directory
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 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
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-encoder PASSED: MIGraphX meets tolerance
whisper-large-decoder PASSED: MIGraphX meets tolerance
mistral-7b PASSED: MIGraphX meets tolerance
FLUX.1-schnell PASSED: MIGraphX meets tolerance

@justinrosner
justinrosner marked this pull request as draft August 19, 2026 13:45
@justinrosner
justinrosner requested a review from pfultz2 August 19, 2026 13:46
@justinrosner

Copy link
Copy Markdown
Contributor Author

@pfultz2 My initial prototype showed significant compile time increases (especially when benchmarking larger kernels). Let me know if you like the look of these initial changes and I can work on cleaning it up and productizing further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants