SimplePatternMatcher

class onnxscript.rewriter.pattern.SimplePatternMatcher(pattern: GraphPattern)[source]
fail(reason: str, node: Node | None = None) bool[source]
match(model: Model, graph_or_function: Graph | Function, node: Node, *, verbose: int = 0, remove_nodes: bool = True, tracer: MatchingTracer | None = None) MatchResult[source]

Match the pattern against the subgraph ending at the given node.

For patterns with multiple output nodes, the given node is matched against the first output node in the pattern. For the remaining output nodes in the pattern, we use a brute-force algorithm that enumerates all possible combinations of nodes from the graph (with a filter based on op-type).

TODO: Consider omitting parameters model and graph_or_function. With the new IR, the graph can be obtained from the node, and the model is not used. But this is a shared abstract method of the Matcher interface, so other matcher implementation also needs to be updated. More importantly, matching in the presence of subgraphs (control-flow) can introduce some complications which require careful consideration.