Update torchkit to support full converter refactor#5060
Conversation
There was a problem hiding this comment.
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 ahas_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. |
Regressions detected 🔴 |
|
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
| 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); |
There was a problem hiding this comment.
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}).
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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:
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.