Class ov::pass::MultiMatcher#

class MultiMatcher : public ov::pass::ModelPass#

MultiMatcher applies multiple independent pattern matchers across the graph.

Each registered pattern is independently matched across all graph nodes. Matches are grouped by pattern root and passed to a single callback.

This is especially useful for repeated blocks like attention heads, Q/K/V projections, and residual connections.

Match repeated Q/K/V branches

┌──────────── Pattern 1 ─────────────┐ ┌──────────── Pattern 2 ─────────────┐ │ │ │ │ │ Input ──► MatMul_Q ──► Add_Q │ │ Input ──► MatMul_K ──► Add_K │ └────────────────────────────────────┘ └────────────────────────────────────┘ │ │ ▼ ▼ concat_qkv concat_qkv │ │ ▼ ▼ SDPA (shared)

Each Q/K/V branch is matched separately using a different pattern.

After matching, callback receives:

matches = { Pattern1: [MatchQ1, MatchQ2, …], Pattern2: [MatchK1, MatchK2, …], Pattern3: [MatchV1, MatchV2, …] }

Public Functions

void register_patterns(const std::vector<std::shared_ptr<Node>> &patterns, Callback callback, bool strict = false)#

Register multiple patterns with a unified callback.

Parameters:
  • patterns – Vector of pattern root nodes

  • callback – Callback applied to all matches grouped by pattern

  • strict – Whether to use strict mode in Matcher

bool run_on_model(const std::shared_ptr<Model> &model) override#

Run all matchers once over the model.

Returns:

true if any matches were found and callback invoked