Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IR] Graph editor API #2005

Open
justinchuby opened this issue Jan 9, 2025 · 0 comments
Open

[IR] Graph editor API #2005

justinchuby opened this issue Jan 9, 2025 · 0 comments
Assignees
Labels
topic: discussion For discussion topic: IR Intermediate representation

Comments

@justinchuby
Copy link
Collaborator

justinchuby commented Jan 9, 2025

This design describes a stateful Editor api for editing ONNX graph structures. It provides an intuitive select and modify experience.

from onnxscript import ir

editor = ir.editing.Editor(graph)

Select

Users can select a part of the graph:

editor.select("node_a")
node_b: ir.None
editor.select(node_b)
editor.select_inputs(value1, value2)
editor.select_outputs(value3, value4)

Remove

editor.select(node_b)
editor.remove_selection(safe=True)
editor.select_inputs(value1, value2)
editor.select_outputs(value3, value4)
editor.remove_selection(safe=True)

Removing a subgraph and stich the connections.

For example

node_a -> node_b -> node_c  ==Remove(b)==> node_a -> node_c
node_a -> {node_b1, node_b2} -> node_c  ==Remove(b1,b2)==> node_a -> node_c

We need to analyze cases when the removal subgraph has multiple outputs and design a good default

Insert

The reverse of Remove

editor.select_inputs(value1, value2)
editor.select_outputs(value3, value4)
editor.insert(inputs, outputs, nodes)

Replace

editor.select_inputs(value1, value2)
editor.select_outputs(value3, value4)
editor.replace(new_inputs, new_outputs, nodes, safe=True)
@justinchuby justinchuby added topic: discussion For discussion topic: IR Intermediate representation labels Jan 10, 2025
@justinchuby justinchuby self-assigned this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: discussion For discussion topic: IR Intermediate representation
Projects
None yet
Development

No branches or pull requests

1 participant