Isolating A Subgraph
Introduction
This example first generates a basic model, then extracts a subgraph from this model.
Isolating a subgraph from a model is as simple as modifying the inputs and
outputs of the graph, running graph.cleanup(), and then re-exporting the graph.
We do not need to know which nodes, initializers, or intermediate tensors we want - marking the inputs and outputs is sufficient for ONNX GraphSurgeon to be able to determine the other information automatically.
Running the example
-
Generate a model with several nodes and save it to
model.onnxby running:python3 generate.pyThe generated model computes
Y = x0 + (a * x1 + b): -
Isolate the subgraph that computes
(a * x1 + b)and save it tosubgraph.onnxby running:python3 isolate.pyThe resulting model computes
add_out = (a * x1 + b):

