Skip to content

Macro refactor - #291

Merged
shivadbhavsar merged 3 commits into
masterfrom
macro_refactor
Aug 12, 2026
Merged

shivadbhavsar merged 3 commits into
masterfrom
macro_refactor

Conversation

@shivadbhavsar

Copy link
Copy Markdown
Collaborator

Use the new macro objects provided by core MIGraphX. This allows torch-migraphx to be less prone to regressions caused by changes to migraphx operations. The ownership of the semantic conversion of torch ops moves to the core repo.

@shivadbhavsar shivadbhavsar self-assigned this Aug 11, 2026
Copilot AI lite review requested due to automatic review settings August 11, 2026 22:10

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

Refactors FX converters to route MIGraphX op creation through the new core “macro/kit” builders (when available), reducing torch-migraphx’s direct dependency on individual MIGraphX op semantics and centralizing op lowering behavior in core MIGraphX.

Changes:

  • Introduces a new mgx_builder.py abstraction (add_op, add_common_op, and build_* helpers) to prefer tm:: kit builders with raw-op fallbacks.
  • Updates multiple converters to use the builder layer (including elementwise ops, reductions, pooling, conv/linear, norms, LSTM, and quant helpers).
  • Simplifies several converter implementations by delegating composite behavior (e.g., batchnorm/instance_norm/std/scatter_reduce) into builder helpers.

Reviewed changes

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

Show a summary per file
File Description
py/torch_migraphx/fx/converters/utils.py Switches selected utility instruction construction to the new builder helpers.
py/torch_migraphx/fx/converters/quant_ops_converters.py Routes a quant helper op through add_op.
py/torch_migraphx/fx/converters/module_converters.py Moves LSTM lowering to build_lstm and uses add_op for supporting ops.
py/torch_migraphx/fx/converters/mgx_builder.py Adds the new op-building layer and composite builder helpers with kit probing.
py/torch_migraphx/fx/converters/aten_ops_converters.py Uses add_op for dtype conversion in _to_copy-family ops.
py/torch_migraphx/fx/converters/acc_ops_converters.py Broad adoption of add_op/add_common_op and delegation to build_* helpers across many acc_ops converters.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +857 to 860
# Empty axes squeezes every size-1 dim, matching torch.squeeze() with no dim.
axes = [] if dim is None else [dim]
out = add_op(mgx_module, 'squeeze', [inp_ref], axes=axes)

Comment on lines 660 to +664
def acc_ops_log_softmax(mgx_module, node, _args, kwargs):
inp = kwargs['input']
assert not inp.is_quantized()
softmax_ins = mgx_module.add_instruction(
migraphx.op('softmax', axis=kwargs['dim']), [inp.instr_ref])
return MGXInstruction(
mgx_module.add_instruction(migraphx.op('log'), [softmax_ins]))
add_op(mgx_module, 'logsoftmax', [inp.instr_ref], axis=kwargs['dim']))
@shivadbhavsar
shivadbhavsar merged commit 34cac03 into master Aug 12, 2026
7 checks passed
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.

2 participants