Skip to content

Adding compilation mode - #4770

Open
pnikolic-amd wants to merge 95 commits into
developfrom
compile-modes
Open

Adding compilation mode#4770
pnikolic-amd wants to merge 95 commits into
developfrom
compile-modes

Conversation

@pnikolic-amd

@pnikolic-amd pnikolic-amd commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Adding compilation mode which defines factor between compilation time and quality of model optimization. This is defined by compile option "compile_mode" which is defined by int value 0-100 (0 - fast, minimal/no optimization, 100 slow, best optimization quality).

Technical Details

compile_mode is represented by enum class compile_modes, and int value is mapped in the closest value. There are three modes defined for now (more fine-grained system can be implemented later):

  • BALANCED (50) - Default execution of model compilation
  • MAX (100) - Default execution with exhaustive_tune flag enabled
  • EAGER (0) - Removed most of gpu independent passes except fusions and normalize_ops and skiped benchmarking for gpu kernels

Tested on both platforms, Eager mode improves compilation time up to 10x while decreasing inference performance for 20-50%.

Changelog Category

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

    • Added: New enum class compile_modes that define compile options
    • Added: New param compile_mode in compile_options struct
    • Added: Added support to set compile mode using all supported APIs and added flag for migraphx-driver app.
    • Changed: Changed get passes function for gpu target, to support execution in defined modes.
    • TODO: Add support to skip fusions in eager mode
    • TODO: Re-run mgx tests in eager mode

@pnikolic-amd pnikolic-amd self-assigned this Apr 9, 2026
@pnikolic-amd
pnikolic-amd requested a review from causten as a code owner April 9, 2026 19:50
Comment thread src/include/migraphx/compile_modes.hpp
Comment thread src/include/migraphx/compile_options.hpp Outdated
Comment thread src/include/migraphx/compile_modes.hpp Outdated
Comment thread src/py/migraphx_py.cpp Outdated
Comment thread src/targets/gpu/target.cpp Outdated
Comment thread src/targets/gpu/target.cpp Outdated
Comment thread src/targets/gpu/target.cpp
Comment thread src/targets/gpu/target.cpp Outdated
Comment thread src/compile_modes.cpp Outdated
Comment thread src/compile_modes.cpp Outdated
@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Jun 11, 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

pipelines = {
p.dynamic_shapes_pipeline(),
p.required_pipeline(),
{optimize_module{},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I dont think we want to run optimize_module in eager mode.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If optimize_module is not included logsoftmax test fails. If we return it than we lose time improvements from eager mode, so I want to exclude it.
I didn't see this problem when testing with models, so can we skip this test right now, since you mentioned it will be removed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see the verification fails because it runs log(softmax(x)) without simplify_algebra. We could update rewrite_reduce to generate the logsoftmax correctly so simplify_algebra is not needed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because this requires additional work I want to leave it for next iterations, I have reverted all changes regarding removing passes, that will be handled in future tasks. Right now, in eager mode we have kernel benchmarking removed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Adding only simplify_algebra does not solve failing for those tests, in order to add rewrite_reduce and rewrite_topk, optimize_module also needs to be added in order for tests to pass.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This has optimize_module before rewrite. But arent you going to add simplify_algebra after rewrite_reduce? You added the header for it but I dont see it being used.

Comment thread src/targets/gpu/target.cpp
pnikolic-amd and others added 14 commits July 29, 2026 15:32
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@pnikolic-amd
pnikolic-amd requested a review from pfultz2 August 4, 2026 13:37
Comment thread test/verify/main.cpp Outdated

// Eager mode drops precision-preserving passes (rewrite_low_precision, propagate_precision,
// rewrite_gelu)
rv.disable_eager_tests({"test_topk", "test_softmax", "test_logsoftmax"});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These tests should not be disabled.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed

Comment thread test/verify/run_verify.cpp Outdated
test::add_test_case(p.name, [=] { verify(p); });
test::add_test_case(p.name, [=] { verify(p, migraphx::compile_modes::balanced); });

if(check_skipped_eager_tests(p.name))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove this as well, we shouldnt be disabling a test for a compile mode.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed

@pnikolic-amd pnikolic-amd added the Windows Related changes for Windows Environments label Aug 6, 2026
@pnikolic-amd
pnikolic-amd requested a review from pfultz2 August 7, 2026 14:45
@pfultz2

pfultz2 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

To fix the CI failures, you can probably disable fuse_attention for eager mode.

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

Labels

Windows Related changes for Windows Environments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants