Conversation
Traverse over ins with empty debug symbols also just in case. Probably will not occur however
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ins_debug_symbols
…to netron_output_update
…to python_api_debug_symbols
There was a problem hiding this comment.
Pull request overview
This PR extends MIGraphX’s Python bindings to expose instruction/module debug symbols and adds a Netron export path that emits an ONNX ModelProto binary (including debug symbols when present), updating the driver/docs/tests accordingly.
Changes:
- Added Python API bindings for
instruction_ref.get_debug_symbols()and moduleadd/remove/has_debug_symbols. - Reworked Netron export from JSON to ONNX protobuf binary via
write_netron_output(...), and added program APIs to write it to a file. - Added C++/C/Python tests covering Netron output and debug symbols.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/py/migraphx_py.cpp |
Exposes debug symbols + program.write_netron_output() in pybind11 module. |
src/onnx/netron_output.cpp |
Implements ONNX ModelProto Netron export and includes debug symbols as node attributes. |
src/include/migraphx/netron_output.hpp |
Updates public Netron export API to a stream-based writer. |
src/api/api.cpp / tools/api/api.cpp |
Adds C API plumbing to write Netron output to a file. |
src/api/include/migraphx/migraphx.h / migraphx.hpp |
Adds migraphx_program_write_netron_output and C++ wrapper method. |
src/driver/main.cpp + docs (docs/*) |
Switches --netron output to protobuf binary and updates help/docs text. |
test/* |
Adds/updates C++ and Python tests for Netron export and debug symbols. |
src/program.cpp / src/include/migraphx/program.hpp |
Exposes program file version via getter and centralizes constant. |
src/CMakeLists.txt / codecov.yml |
Removes old src/netron_output.cpp from build/coverage ignore. |
CHANGELOG.md |
Adds release note about Netron export and debug symbols. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| onnx::ModelProto model; | ||
| auto prog_value = prog.to_value(); | ||
| model.set_ir_version(prog.get_program_file_version()); |
There was a problem hiding this comment.
model.set_ir_version(prog.get_program_file_version()) uses MIGraphX's MXR serialization version as the ONNX IR version. ONNX consumers expect an ONNX IR version (e.g., onnx::IR_VERSION), and using an unrelated value can make the exported model invalid or rejected. Set ir_version to the ONNX constant and consider also populating opset_import to improve compatibility with ONNX tooling/Netron.
| model.set_ir_version(prog.get_program_file_version()); | |
| model.set_ir_version(onnx::IR_VERSION); |
| #include <ostream> | ||
| #include <migraphx/config.hpp> | ||
| #include <migraphx/program.hpp> | ||
| #include <migraphx/onnx/export.h> | ||
|
|
||
| namespace migraphx { | ||
| inline namespace MIGRAPHX_INLINE_NS { | ||
|
|
||
| MIGRAPHX_EXPORT std::string make_netron_output(const program& prog); | ||
| MIGRAPHX_ONNX_EXPORT void write_netron_output(const program& prog, std::ostream& os); |
There was a problem hiding this comment.
This header replaces the existing make_netron_output(const program&) -> std::string API with write_netron_output(program, ostream), which is a breaking change for C++ consumers. Consider keeping make_netron_output as a compatibility wrapper (e.g., implemented via std::ostringstream + write_netron_output) and/or deprecating it instead of removing it outright.
| * Updated `argmin` and `argmax` ops to be implemented as reduction ops, so they now have JIT support and can fuse (#4620). | ||
| * Replaced usages of `std::cout` and `std::cerr` with the logger (#4732) | ||
| * Converted RNN variable sequence length operations (`rnn_var_sl_shift_sequence`, `rnn_var_sl_shift_output`, `rnn_var_sl_last_output`) from device implementation to JIT compilation (#4755). | ||
| * Updated netron output to create an ONNX-like protobuff. Now also includes debug symbols if enabled. (#4701) |
There was a problem hiding this comment.
The changelog entry says "protobuff"; the correct term is "protobuf".
| * Updated netron output to create an ONNX-like protobuff. Now also includes debug symbols if enabled. (#4701) | |
| * Updated netron output to create an ONNX-like protobuf. Now also includes debug symbols if enabled. (#4701) |
| static void write_netron_output_file(const program& p, const char* filename) | ||
| { | ||
| std::ofstream os(filename, std::ios::binary); | ||
| if(not os.is_open()) | ||
| MIGRAPHX_THROW(migraphx_status_bad_param, | ||
| "Failed to open file for writing: " + std::string(filename)); | ||
| write_netron_output(p, os); |
There was a problem hiding this comment.
write_netron_output_file constructs std::ofstream and later builds std::string(filename) without validating filename. If the C API is called with a null pointer, this is undefined behavior and can crash before returning a status. Add an explicit filename == nullptr (and ideally empty-string) check and throw migraphx_status_bad_param before using it.
| static void write_netron_output_file(const program& p, const char* filename) | ||
| { | ||
| std::ofstream os(filename, std::ios::binary); | ||
| if(not os.is_open()) | ||
| MIGRAPHX_THROW(migraphx_status_bad_param, | ||
| "Failed to open file for writing: " + std::string(filename)); | ||
| write_netron_output(p, os); |
There was a problem hiding this comment.
Template version has the same issue as the generated C API: write_netron_output_file uses filename without checking for null, and std::string(filename) will crash on nullptr. Add a filename == nullptr (and optionally empty-string) check before opening/formatting the filename.
| [](migraphx::module& mm, migraphx::instruction_ref ins) { | ||
| mm.remove_debug_symbols(ins); | ||
| }, | ||
| py::arg("ins")) |
There was a problem hiding this comment.
Only get_debug_symbols should be exposed to the API.
There was a problem hiding this comment.
What if a user wants to add a debug symbol to an instruction when manually adding instructions?
There was a problem hiding this comment.
We should add a debug_symbols parameter to the add_instruction, insert_instruction, add_macro, insert_macro, etc methods. So they can write m.add_instruction(op("add"), [x, y], debug_symbols=['addOp']).
This will make it consistent and can handle the macros, which is a little more complicated.
Hold off on the C++ API as we need a better design to make it more extensible, and it doesnt even support macros right now.
|
|
||
| void print() const { call(&migraphx_program_print, this->get_handle_ptr()); } | ||
|
|
||
| void write_netron_output(const char* filename) const |
There was a problem hiding this comment.
Why are we adding this to the C++ API?
There was a problem hiding this comment.
This is from #4701. There wasn't a way to write out as ONNX-like protobuff from the C++ API before, only the driver.
There was a problem hiding this comment.
Why is #4701 in this PR? The python API debug symbols are not related to this.
| case shape::fp8e5m2_type: return onnx::TensorProto::FLOAT8E5M2; | ||
| case shape::fp8e5m2fnuz_type: return onnx::TensorProto::FLOAT8E5M2FNUZ; | ||
| case shape::tuple_type: return onnx::TensorProto::UNDEFINED; | ||
| case shape::fp4x2_type: return onnx::TensorProto::UINT4; |
There was a problem hiding this comment.
Can this be onnx::TensorProto::FLOAT4E2M1 or are we limited by ONNX opset version? Will using UINT4 result in display issues for fp4 types?
There was a problem hiding this comment.
This change is also from #4701. The update should be doable. I made the netron output before ONNX had the type.
Motivation
Technical Details
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable