Pattern

class onnxscript.rewriter.pattern.Pattern(target_pattern: GraphPattern | Callable, condition_function: Callable | None = None, matcher: PatternMatcher | Callable[[GraphPattern], PatternMatcher] | None = None, verbose: int = 0, name: str | None = None)[source]

A pattern that can be matched against nodes in an ONNX graph.

This class encapsulates pattern matching functionality, providing the ability to match patterns against nodes without requiring replacement functionality.

match(model: Model, graph_or_function: Graph | Function, node: Node, *, verbose: int | None = None, check_nodes_are_removable: bool = True, tracer: MatchingTracer | None = None) MatchResult | None[source]

Check if the node matches the pattern and return the match result.

Parameters:
  • model – The model containing the graph or function.

  • graph_or_function – The graph or function to match against.

  • node – The node to try to match the pattern against.

  • verbose – The verbosity level of messages.

  • check_nodes_are_removable – If True, validate that matched nodes can be safely removed.

  • tracer – The tracer for debugging.

Returns:

MatchResult if the pattern matches successfully and passes the condition function, None otherwise.