Expose op builder to the python API using a macro class#4747
Expose op builder to the python API using a macro class#4747
Conversation
There was a problem hiding this comment.
Pull request overview
This PR exposes the C++ op builder API to the Python bindings via a new migraphx.macro type, enabling users to insert builder-expanded instruction sequences into a module with add_instructions / insert_instructions.
Changes:
- Add
migraphx.macro(name, **options)Python type to carry an op-builder name plus options. - Add
module.add_instructions(macro, args, mod_args=[])andmodule.insert_instructions(ins, macro, args, mod_args=[])Python APIs backed byop::builder::{add,insert}. - Add Python tests covering macro metadata and several builder expansions (add/mul/sub/broadcast/gemm, plus insertion).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/py/migraphx_py.cpp |
Adds macro binding and module methods that call op::builder::add/insert. |
test/py/test_macro.py |
New test suite validating macro/options and builder insertion behavior via the Python API. |
test/py/CMakeLists.txt |
Registers the new test_macro.py in the Python test CMake targets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4747 +/- ##
===========================================
+ Coverage 92.43% 92.48% +0.05%
===========================================
Files 583 583
Lines 29244 29514 +270
===========================================
+ Hits 27031 27296 +265
- Misses 2213 2218 +5 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
should we really be using op builders for simple ops like add, sub, mul, etc? Then along those lines, could we instead have more tests of the ops like batchnorm, convolution, einsum?
Also another minor nit is that we call the macro variable mac, but I would prefer it be named according to the op (like gemm_mac). So that it's a bit more clear
There was a problem hiding this comment.
should we really be using op builders for simple ops like add, sub, mul, etc?
We dont actually have op builders for these operators they just fallback to migraphx operators.
The goal is to build a set of op builders that torch_migraphx can call to instead of directly adding ops. That way we can update the operators in non-backwards compatible way and it wont break. This actually blocks merging in things like #4606.
Then along those lines, could we instead have more tests of the ops like batchnorm, convolution, einsum?
I can try to update the test.
Motivation
This exposes the op builder to the API, but uses slightly different API. Instead there is a
m.add_instructionsmethod that will take amacrothat will then insert the ops from the op builder. I chosemacroas it is short and descriptive of what it does.Technical Details
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable