pub struct FusionPattern { /* private fields */ }Expand description
A fusion rule: an op-type sequence rewritten to a single replacement op.
Implementations§
Source§impl FusionPattern
impl FusionPattern
Sourcepub fn new(name: &str, ops: &[&str], replacement: &str) -> Self
pub fn new(name: &str, ops: &[&str], replacement: &str) -> Self
A new structural pattern matching ops in sequence, replaced by
replacement. The fused node’s inputs are the matched region’s external
inputs in first-seen order.
Sourcepub fn layernorm() -> Self
pub fn layernorm() -> Self
The schema-aware LayerNorm pattern: the canonical 9-op decomposition
(ReduceMean, Sub, Pow, ReduceMean, Add, Sqrt, Div, Mul, Add) rewritten
to a com.microsoft::LayerNormalization node with inputs [X, Scale, B]
and synthesized axis/epsilon attributes.
Sourcepub fn attention() -> Self
pub fn attention() -> Self
The schema-aware SDPA-core pattern, rewritten to a
com.microsoft::FusedAttention node with inputs [Q, K, V] (+ optional
[mask]) and synthesized scale/k_transposed attributes. Anchored on
the Softmax (see Self::try_match_attention).
Sourcepub fn gelu() -> Self
pub fn gelu() -> Self
The schema-aware exact-GELU pattern: the Erf decomposition
0.5·X · (1 + Erf(X / √2)) rewritten to a com.microsoft::Gelu node
with the single input [X] and no attributes. Anchored on the Erf
(see Self::try_match_gelu).
Sourcepub fn pattern_name(&self) -> &str
pub fn pattern_name(&self) -> &str
This pattern’s name.
Sourcepub fn find_match(&self, graph: &Graph) -> Option<PatternMatch>
pub fn find_match(&self, graph: &Graph) -> Option<PatternMatch>
Find the next occurrence of this pattern, scanning nodes in id order.
[RewriteKind::LayerNorm] uses a dedicated DAG-aware matcher
(Self::try_match_layernorm) because a real LayerNorm decomposition is
a diamond DAG whose mean feeds two branches (variance + numerator) and
may even use two distinct Sub(x, mean) nodes; the linear successor-walk
used by the structural patterns can’t express that. All structural
patterns (MatMul+Add, MatMul+Add+Relu) keep the linear-chain matcher.
Sourcepub fn apply_fusion(&self, graph: &mut Graph, m: &PatternMatch) -> Result<()>
pub fn apply_fusion(&self, graph: &mut Graph, m: &PatternMatch) -> Result<()>
Apply a match: remove the matched nodes and insert the replacement,
reusing m.output so downstream consumers and graph outputs stay wired.
Trait Implementations§
Source§impl Clone for FusionPattern
impl Clone for FusionPattern
Source§fn clone(&self) -> FusionPattern
fn clone(&self) -> FusionPattern
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more