Open
Description
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)