Skip to content

Update torchkit to support full converter refactor#5060

Open
shivadbhavsar wants to merge 15 commits into
developfrom
update_torch_kit
Open

Update torchkit to support full converter refactor#5060
shivadbhavsar wants to merge 15 commits into
developfrom
update_torch_kit

Conversation

@shivadbhavsar

Copy link
Copy Markdown
Contributor

Motivation

Macro builders were recently added to better manage composed ops when parsing from outside libraries. This extends the torch kit with a number of missing ops required to fully migrate torch_migraphx to use this builder framework.

Technical Details

New builders are added to either the general op builder or directly to the torch kit:

  • if the builder can be reused with an onnx parser, it is added a general op builder and aliased into the tm:: space
  • for niche torch ops, the required builders are inlined in the kit itself

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.

@shivadbhavsar shivadbhavsar self-assigned this Jul 13, 2026
Copilot AI review requested due to automatic review settings July 13, 2026 23:07
@shivadbhavsar
shivadbhavsar requested a review from causten as a code owner July 13, 2026 23:07
@shivadbhavsar
shivadbhavsar requested a review from pfultz2 July 13, 2026 23:07

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 extends MIGraphX’s Torch op-builder kit (tm::) to cover additional Torch ops needed for the ongoing converter refactor, primarily by adding new composite builders and aligning kit registration/aliasing behavior. It also updates GPU MLIR preparation to normalize certain literals, and exposes small related utilities to Python/tests.

Changes:

  • Expand tm:: torch kit coverage by registering additional common ops and new composite builders (e.g., norms, activations, convolution/dot aliases, etc.).
  • Add multiple new op-builder implementations (e.g., vector_norm, softsign, selu, glu, floor_div, normalization helpers) plus extensive torch kit tests.
  • Improve MLIR GPU prep by rewriting non-standard literals, and add Python bindings for shape.sub_shapes() and a has_op_builder() helper.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/op/builder/torch_kit_test.cpp Adds/updates torch kit builder tests for newly supported ops and builder aliasing behaviors.
src/targets/gpu/prepare_mlir.cpp Ensures MLIR input literals are in standard shapes by rewriting certain literal instructions.
src/py/migraphx_py.cpp Exposes shape.sub_shapes() and a Python helper to query registered op-builders.
src/op/builder/vector_norm.cpp Adds a vector_norm composite builder implementation.
src/op/builder/torch_kit.cpp Expands tm:: kit registrations and adds several Torch-specific composite builders.
src/op/builder/softsign.cpp Adds a softsign composite builder implementation.
src/op/builder/selu.cpp Adds a selu composite builder implementation.
src/op/builder/layer_norm.cpp Adds a layer_norm composite builder implementation using shared normalization logic.
src/op/builder/instance_norm.cpp Adds an instance_norm composite builder implementation using shared normalization logic.
src/op/builder/include/migraphx/op/builder/normalize.hpp Introduces a shared normalization helper for builder reuse.
src/op/builder/include/migraphx/op/builder/kit.hpp Changes kit builder resolution to be lazy to avoid static init ordering issues.
src/op/builder/hardsigmoid.cpp Adds a hardsigmoid composite builder implementation.
src/op/builder/group_norm.cpp Adds a group_norm composite builder implementation using shared normalization logic.
src/op/builder/glu.cpp Adds a glu composite builder implementation.
src/op/builder/gather_elements.cpp Adds a gather_elements composite builder implementation.
src/op/builder/floor_div.cpp Adds a floor_div composite builder implementation.

Comment thread src/op/builder/torch_kit.cpp Outdated
Comment thread src/op/builder/torch_kit.cpp Outdated
Comment thread src/op/builder/torch_kit.cpp Outdated
Comment thread src/op/builder/torch_kit.cpp Outdated
Comment thread src/op/builder/torch_kit.cpp Outdated
Comment thread src/op/builder/glu.cpp Outdated
Comment thread src/op/builder/torch_kit.cpp Outdated
Comment thread test/op/builder/torch_kit_test.cpp Outdated
Comment thread test/op/builder/torch_kit_test.cpp Outdated
@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Jul 14, 2026

Copy link
Copy Markdown
Test Batch New Rate (23083c) Old Rate (5c50d0) Diff Status
torchvision-resnet50 64 3,276.07 3,278.37 -0.07%
torchvision-resnet50_fp16 64 7,524.63 7,611.38 -1.14%
torchvision-densenet121 32 986.34 2,501.41 -60.57% 🔴
torchvision-densenet121_fp16 32 4,531.83 5,004.64 -9.45% 🔴
torchvision-inceptionv3 32 1,114.44 2,059.27 -45.88% 🔴
torchvision-inceptionv3_fp16 32 4,394.42 4,417.65 -0.53%
cadene-inceptionv4 16 822.66 819.80 0.35%
cadene-resnext64x4 16 783.84 783.52 0.04%
slim-mobilenet 64 8,435.99 8,394.63 0.49%
slim-nasnetalarge 64 176.40 197.60 -10.73% 🔴
slim-resnet50v2 64 3,198.96 3,185.87 0.41%
bert-mrpc-onnx 8 1,135.47 1,161.65 -2.25%
bert-mrpc-tf 1 489.32 486.30 0.62%
pytorch-examples-wlang-gru 1 479.31 469.65 2.06%
pytorch-examples-wlang-lstm 1 382.12 379.72 0.63%
torchvision-resnet50_1 1 953.21 1,023.59 -6.88% 🔴
cadene-dpn92_1 1 419.98 436.69 -3.83%
cadene-resnext101_1 1 288.84 364.25 -20.70% 🔴
onnx-taau-downsample 1 847.39 845.97 0.17%
dlrm-criteoterabyte 1 30.05 32.54 -7.65% 🔴
dlrm-criteoterabyte_fp16 1 52.54 52.59 -0.10%
agentmodel 1 9,326.18 9,452.06 -1.33%
unet_fp16 2 53.49 59.01 -9.35% 🔴
resnet50v1_fp16 1 203.41 1,378.39 -85.24% 🔴
resnet50v1_int8 1 1,712.50 1,626.43 5.29% 🔆
bert_base_cased_fp16 64 1,014.98 1,102.97 -7.98% 🔴
bert_large_uncased_fp16 32 346.66 346.63 0.01%
bert_large_fp16 1 206.14 205.51 0.30%
distilgpt2_fp16 16 1,235.55 2,098.82 -41.13% 🔴
yolov5s 1 208.05 562.00 -62.98% 🔴
tinyllama 1 45.60 45.93 -0.72%
vicuna-fastchat 1 44.18 44.06 0.27%
whisper-tiny-encoder 1 414.55 415.56 -0.24%
whisper-tiny-decoder 1 409.32 410.79 -0.36%
llama2_7b 1 12.31 21.01 -41.42% 🔴
qwen1.5-7b 1 23.65 23.60 0.20%
phi3-3.8b 1 16.96 26.80 -36.72% 🔴
llama3-8b 1 21.84 21.70 0.63%
whisper-large-encoder 1 10.21 10.22 -0.04%
whisper-large-decoder 1 107.61 104.52 2.96%
mistral-7b 1 23.90 23.74 0.66%
FLUX.1-schnell 1 778.72 723.54 7.63% 🔆

Regressions detected 🔴

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

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

@shivadbhavsar
shivadbhavsar requested a review from pfultz2 July 15, 2026 03:12
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.73822% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/op/builder/gather_elements.cpp 96.88% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5060      +/-   ##
===========================================
+ Coverage    92.90%   92.99%   +0.10%     
===========================================
  Files          603      623      +20     
  Lines        32528    32898     +370     
===========================================
+ Hits         30218    30593     +375     
+ Misses        2310     2305       -5     
Files with missing lines Coverage Δ
src/op/builder/floor_div.cpp 100.00% <100.00%> (ø)
src/op/builder/glu.cpp 100.00% <100.00%> (ø)
src/op/builder/group_norm.cpp 100.00% <100.00%> (ø)
src/op/builder/hardsigmoid.cpp 100.00% <100.00%> (ø)
src/op/builder/include/migraphx/op/builder/kit.hpp 100.00% <100.00%> (ø)
src/op/builder/instance_norm.cpp 100.00% <100.00%> (ø)
src/op/builder/layer_norm.cpp 100.00% <100.00%> (ø)
src/op/builder/normalize.cpp 100.00% <100.00%> (ø)
src/op/builder/selu.cpp 100.00% <100.00%> (ø)
src/op/builder/softsign.cpp 100.00% <100.00%> (ø)
... and 12 more

... and 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.

Comment thread src/targets/gpu/prepare_mlir.cpp
Comment thread src/op/builder/include/migraphx/op/builder/normalize.hpp Outdated
auto lo_op = mm_op_built.add_parameter("lo", {f, {2, 3}});
auto hi_op = mm_op_built.add_instruction(migraphx::make_op("undefined"));
migraphx::op::builder::add("tm::clip", mm_op_built, {x_op, lo_op, hi_op});
EXPECT(mm == mm_op_built);

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.

It doesnt have to be in this PR, but it would be nice if we could update the make_op_module so it reinserts any nullary function instead of just parameters so you could write: make_op_module("tm::clip", {x_op, lo_op, hi_op}).

@shivadbhavsar
shivadbhavsar requested a review from pfultz2 July 15, 2026 20:11
shivadbhavsar and others added 2 commits July 15, 2026 13:26
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@shivadbhavsar
shivadbhavsar requested a review from kahmed10 July 20, 2026 17:27
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.

3 participants