Patterns#

This table is generated from the patterns registered by the installed onnx_light package. Summaries come from the C++ Doxygen comments; follow the C++ class links to see the rewrite graphs.

#

Pattern

Summary

1

AttentionGQA (attention)

Python — Converts cached grouped-query attention into ONNX Attention cache inputs and outputs.

2

BatchNormalization (normalization)

Python — Removes an identity BatchNormalization in inference mode.

3

BatchNormalizationTraining (normalization)

Python — Expands training BatchNormalization into primitive operators.

4

Cast (canonicalization)

Python — Canonicalizes a Cast to Identity when its input already has the target type.

5

CastCast (canonicalization)

Python — Canonicalizes consecutive Cast nodes when a single conversion is equivalent.

6

CastCastBinary (canonicalization)

Python — Moves matching floating-point Cast nodes after a binary arithmetic operation.

7

CastLayerNormalizationCast (normalization)

Python — Removes FP32 promotion around eligible standard FP16 normalization.

8

CastOpCast (canonicalization)

Python — Moves an operation from a temporary floating-point type to its result type.

9

ClipClip (canonicalization)

Python — Merges two consecutive Clip nodes when one defines the minimum and the other the maximum.

10

ConcatEmpty (collections)

Python — Removes Concat inputs that are empty along the concatenation axis.

11

ConcatGather (collections)

Python — Simplifies Gather(Concat(...), cst_index) when the index is a constant single-element int64 tensor and every Concat input is a 1-D tensor of a statically known size.

12

ConcatReshape (reshape)

Python — Replaces dynamic dimensions in a concatenated Reshape target with one inferred dimension.

13

ConcatSliceElimination (collections)

Python — Removes a Concat whose consumers are exact, non-overlapping Slice nodes that recover every input in order along the concatenation axis.

14

ConcatTwiceUnary (collections)

Python — Pushes a shape-preserving unary operator through a Concat(x, x) so that Unary(Concat(x, x)) becomes Concat(Unary(x), Unary(x)), exposing the shared Unary(x) for common-subexpression elimination.

15

ConstantToInitializer (canonicalization)

Python — Replaces a Constant node by an initializer and an Identity node.

16

ConvAddFusion (canonicalization)

Python — Fuses a channel-wise Add following a Conv into the Conv bias.

17

ConvBatchNormalizationFusion (canonicalization)

Python — Fuses inference BatchNormalization following a Conv into the Conv weights and bias.

18

ConvBiasNull (canonicalization)

Python — Removes a null (all-zero) bias input from a Conv node.

19

ConvMulFusion (canonicalization)

Python — Fuses a scalar or channel-wise Mul following a Conv into its weights and optional bias.

20

DivMul (algebra)

Python — Fuses a reciprocal followed by multiplication into one division.

21

Dropout (canonicalization)

Python — Replaces an eligible Dropout by an Identity node.

22

Expand (expand)

Python — Removes an Expand that does not change the shape of its input.

23

ExpandBroadcast (expand)

Python — Drops an Expand feeding an element-wise binary operator.

24

ExpandSwap (expand)

Python — Moves an Expand past a following unary-like operator.

25

ExpandUnsqueezeExpand (expand)

Python — Fuses Expand, Unsqueeze and Expand into Unsqueeze then Expand.

26

FunctionAttention (attention)

Python — Fuses a masked scaled-dot-product attention graph into a local function.

27

FunctionAttentionGQA (attention)

Python — Moves matching GQA repeat-interleave branches into a LocalAttention function.

28

FunctionCausalMask (attention)

Python — Fuses a causal-mask index construction into a local function.

29

FunctionCausalMaskMulAdd (attention)

Python — Fuses an additive causal-mask index construction into a local function.

30

FunctionCosSinCache (attention)

Python — Fuses cosine and sine rotary-cache generation into a local function.

31

FunctionHalfRotaryEmbedding (attention)

Python — Fuses the canonical half-rotary decomposition into a local function.

32

GatherConcat (collections)

Python — Simplifies Gather(Concat(..., X, ..., axis=0), cst) into Gather(X, cst - offset) when exactly one Concat input X is non-constant, all others are constants of known size, X is 1-D, and every requested index falls inside X’s slice of the concatenation.

33

GatherGather (collections)

Python — Composes two consecutive axis=0 Gather nodes with constant indices into a single Gather.

34

GatherShape (collections)

Python — Simplifies Gather(Shape(X), indices) into Shape(X, start, end) when indices is a constant int64 scalar or a contiguous ascending 1-D range.

35

GatherSliceToSplit (collections)

Python — Replaces compatible sibling scalar Gather and contiguous Slice ranges covering a complete static axis with one Split. Scalar Gather outputs are restored with Squeeze.

36

GatherToSlice (collections)

Python — Replaces a Gather selecting a constant scalar index, a constant single-element vector index, or a constant arithmetic-progression vector of indices (a “range” with a fixed, strictly ascending step) by an equivalent Slice. Slice is generally cheaper to execute than Gather and, unlike Gather, it never triggers a data-dependent gather kernel.

37

GatherUpstreamPropagation (collections)

Python — Moves a scalar or vector constant-index Gather upstream across one compatible producer node, so that the producer runs on the smaller (already gathered) tensor(s) instead of the original full-size ones.

38

GathersSplit (collections)

Python — Merges several sibling Gather nodes reading consecutive constant indices 0, 1, ..., n-1 on the same axis of a common input into a single Split (followed by Squeeze nodes when the indices are scalars).

39

Gelu (normalization)

Python — Fuses exact Erf-based Gelu and its tanh approximation.

40

GemmOutputTranspose (matmul)

Python — Absorbs a matrix output Transpose into an unbiased Gemm.

41

GemmSumFusion (matmul)

Python — Fuses a two-input Sum following an unbiased Gemm into the Gemm bias input.

42

GemmTranspose (matmul)

Python — Absorbs one or both matrix input Transposes into Gemm transpose flags.

43

GroupedMatMul (matmul)

Python — Fuses per-token expert selection into an opset-29 GroupedMatMul.

44

Identity (canonicalization)

Python — Replaces no-op operations by an Identity node.

45

IfIdenticalBranches (canonicalization)

Python — Inlines an If whose branches are structurally identical up to local names.

46

InitializerUnsqueezeCast (canonicalization)

Python — Folds an initializer’s Unsqueeze and Cast into the initializer consumed by Add.

47

LabelEncoderFusion (traditionalml)

Python — Composes two consecutive ai.onnx.ml::LabelEncoder mappings, including propagation of the first encoder’s default through the second encoder.

48

LayerNormalization (normalization)

Python — Fuses an explicit layer-normalization decomposition.

49

LayerNormalizationScale (normalization)

Python — Folds a following affine transform into LayerNormalization parameters.

50

LeakyRelu (normalization)

Python — Fuses a Where-based LeakyRelu decomposition.

51

LinearAttention (attention)

Python — Fuses a single-token linear-attention recurrence into LinearAttention.

52

MatMulAdd (matmul)

Python — Fuses an Add bias into a MatMul or Gemm.

53

MatMulBatchNormalizationFusion (matmul)

Python — Folds inference BatchNormalization parameters into a constant MatMul weight.

54

MatMulReshape2Of3 (matmul)

Python — Normalizes adjacent Reshapes around a MatMul to the final batch shape.

55

MatMulScaleFusion (matmul)

Python — Absorbs one scalar Mul or safe Div adjacent to a rank-two MatMul.

56

MaxRelu (normalization)

Python — Replaces a maximum with scalar zero by Relu.

57

MulMulMatMul (matmul)

Python — Moves scalar factors from both MatMul inputs to one multiplication after the MatMul.

58

MulMulMulScalar (algebra)

Python — Combines the scalar constants from three nested Mul or Div nodes.

59

MulUnsqueezeUnsqueeze (layout)

Python — Moves equal, unshared Unsqueeze operations after a Mul.

60

NotNot (canonicalization)

Python — Fuses two consecutive Not nodes into an Identity.

61

NotWhere (expand)

Python — Rewrites Where(Not(c), x, y) into Where(c, y, x).

62

PadConv (canonicalization)

Python — Fuses a Pad node followed by a Conv node into a single Conv node whose pads attribute absorbs the spatial padding.

63

PadPadFusion (canonicalization)

Python — Merges two adjacent constant-mode Pad nodes with equal constant values.

64

PadPool (canonicalization)

Python — Fuses zero-valued spatial Pad into AveragePool or UINT8 MaxPool.

65

PreShapeNodeElimination (collections)

Python — Removes a Cast node whose output only feeds Shape consumers, redirecting each such Shape node directly to the Cast’s input.

66

RMSNormalization (normalization)

Python — Fuses an explicit root-mean-square normalization decomposition.

67

RMSNormalizationMul (normalization)

Python — Folds a constant post-scale into RMSNormalization.

68

ReduceArgTopK (algebra)

Python — Fuses matching ReduceMin/ReduceMax and ArgMin/ArgMax nodes into TopK with K=1.

69

ReduceReshape (reshape)

Python — Fuses a dimension-removing Reshape into a reduction.

70

ReduceSumNormalize (algebra)

Python — Moves a Cast-ReduceSum-Mul-Sub-Cast normalization chain to the result type.

71

ReluClipFusion (canonicalization)

Python — Removes a Relu immediately followed by a Clip whose effective minimum is non-negative.

72

Reshape (reshape)

Python — Removes a Reshape whose constant target already equals its input shape.

73

Reshape2Of3 (reshape)

Python — Moves a binary operation to the common outer shape represented by surrounding Reshapes.

74

ReshapeMatMulReshape (matmul)

Python — Removes batch-flattening Reshapes around a MatMul.

75

ReshapeReshape (reshape)

Python — Composes two consecutive Reshapes into one.

76

ReshapeReshapeBinary (reshape)

Python — Moves equal input Reshapes after an element-wise binary operation.

77

ReshapeSqueeze (reshape)

Python — Fuses a Squeeze into the constant target of a preceding Reshape.

78

RotaryConcatPart (attention)

Python — Collapses two zero-padded rotary branches into Split, Neg, and Concat.

79

RotaryEmbedding (attention)

Python — Replaces a half-rotary local function and doubled caches with RotaryEmbedding.

80

STFTFusion (canonicalization)

Python — Fuses a canonical convolution-based DFT into a standard ONNX STFT.

81

SameChildren (algebra)

Python — Merges pairs of identical sibling nodes, and any identical descendant chains.

82

SameChildrenFromInput (algebra)

Python — Merges identical nodes that consume the same graph input.

83

SequenceConstructAt (collections)

Python — Replaces SequenceConstruct(x0, x1, ...) followed by the matching SequenceAt(seq, 0), SequenceAt(seq, 1), … with one Identity per SequenceAt, forwarding the original tensor directly.

84

ShapeBasedConcatExpand (expand)

Python — Simplifies a dynamic Concat used as an Expand target shape.

85

ShapeBasedEditDistanceReshape (reshape)

Python — Materializes a Concat-built Reshape target from inferred input and output shapes.

86

ShapeBasedExpandBroadcast (expand)

Python — Removes dynamic Expand nodes before a broadcasting binary operator.

87

ShapeBasedExpandBroadcastMatMul (expand)

Python — Removes dynamic Expand nodes before MatMul.

88

ShapeBasedExpandCastWhereSwap (expand)

Python — Moves an Expand after Cast and Where.

89

ShapeBasedExpandSwap (expand)

Python — Moves input Expand nodes after a broadcasting binary operator.

90

ShapeBasedIdentity (algebra)

Python — Replaces a shape-preserving Slice by an Identity.

91

ShapeBasedMatMulToMul (matmul)

Python — Replaces a MatMul with unit reduction dimensions by element-wise Mul.

92

ShapeBasedReshapeIsSqueeze (reshape)

Python — Replaces a Reshape or all-one Expand that only inserts or removes unit dimensions.

93

ShapeBasedSameChildren (algebra)

Python — Merges Expand or Reshape siblings whose inferred output shapes are equal.

94

ShapeBasedShapeShapeAdd (algebra)

Python — Recognizes an Add fed by two Shape nodes but performs no rewrite.

95

ShapeBasedStaticExpand (expand)

Python — Replaces a dynamic Expand target with an equivalent constant target.

96

ShapeTranspose (collections)

Python — Replaces Shape(Transpose(X, perm)) by Gather(Shape(X), perm) so the expensive Transpose on the full data tensor is avoided.

97

ShapedBasedReshape (reshape)

Python — Removes a same-rank Reshape whose target copies every dimension but the last.

98

SliceConcatToSpaceToDepth (collections)

Python — Replaces the canonical rank-4 four-phase slicing and channel concatenation used by focus layers with the standard ONNX SpaceToDepth(blocksize=2).

99

SliceElimination (collections)

Python — Replaces a full-range Slice by an Identity.

100

SliceSlice (collections)

Python — Merges two consecutive Slice nodes acting on disjoint axes into a single Slice whose starts / ends / axes (and steps when present) are the concatenation of the two operand vectors.

101

SlicesSplit (collections)

Python — Merges several sibling Slice nodes that partition a common input along a single axis into contiguous, non-overlapping ranges into one Split.

102

SoftmaxCrossEntropyLossCast (normalization)

Python — Fuses a float16 mean cross-entropy loss decomposition.

103

SplitConcat (collections)

Python — Replaces a Split immediately followed by a Concat that re-joins all of its outputs, in order and on the same axis, with a single Identity.

104

SplitToSequenceSequenceAt (collections)

Python — Replaces SplitToSequence(x, [split], axis=a) followed by the matching SequenceAt(seq, 0), SequenceAt(seq, 1), … with a single Split.

105

SqueezeAdd (layout)

Python — Moves equal Squeeze operations after an Add.

106

SqueezeBinaryUnsqueeze (layout)

Python — Cancels a scalar-producing Squeeze/binary/Unsqueeze chain by expanding the scalar right operand instead.

107

SqueezeUnsqueeze (unsqueeze)

Python — Simplifies a Squeeze/Unsqueeze pair into Identity or Squeeze.

108

StaticConcatReshape (reshape)

Python — Replaces the sole dynamic element of a concatenated Reshape target with [-1].

109

Sub1Mul (algebra)

Python — Rewrites multiplication by 1 - x into a product followed by subtraction.

110

SwapExpandReshape (expand)

Python — Swaps an Expand with a following constant-shape Reshape.

111

SwapExpandUnsqueeze (expand)

Python — Swaps an Expand and a following Unsqueeze.

112

SwapRangeAddScalar (algebra)

Python — Moves a shape-[1] second Add input from after Range into its start and limit inputs.

113

SwapUnary (algebra)

Python — Moves a rank-preserving layout operation after a compatible following operation.

114

SwapUnsqueezeTranspose (layout)

Python — Swaps an unshared Unsqueeze and Transpose, remapping both axes and permutation.

115

SwitchOrderBinary (algebra)

Python — Reassociates nested Add or Mul nodes to reduce broadcasting rank.

116

SwitchReshapeActivation (matmul)

Python — Moves an element-wise activation before a Reshape or Transpose.

117

TransposeEqualReshape (layout)

Python — Replaces a Transpose that only repositions size-one axes around at most one other dimension with a Reshape.

118

TransposeGather (transpose)

Python — Removes an unnecessary Transpose feeding a Gather with a scalar index.

119

TransposeMatMul (matmul)

Python — Absorbs rank-two input Transposes into Gemm transpose attributes.

120

TransposeReshapeMatMul (matmul)

Python — Swaps a last-two-dimension Transpose with a following Reshape on one MatMul input.

121

TransposeReshapeTranspose (layout)

Python — Moves a constant Reshape across one of two adjacent Transpose nodes when the input and target dimensions can be aligned by merging or splitting contiguous dimensions.

122

TransposeTranspose (transpose)

Python — Merges two Transpose nodes, optionally separated by Identity nodes.

123

TreeEnsemble (traditionalml)

Python — Replaces classic TreeEnsembleRegressor and TreeEnsembleClassifier nodes with the unified ai.onnx.ml TreeEnsemble operator from opset 5.

124

UnsqueezeEqual (expand)

Python — Moves Equal(x, c) after a compatible sibling Unsqueeze(x, a) and preserves the rank of Equal(Unsqueeze(x, a), Unsqueeze(y, a)).

125

UnsqueezeOrSqueezeReshape (reshape)

Python — Removes a Squeeze or Unsqueeze immediately before a Reshape.

126

UnsqueezeReshape (reshape)

Python — Collapses a specific Unsqueeze-Reshape sequence into one Unsqueeze.

127

UnsqueezeShape (collections)

Python — Replaces Shape(Unsqueeze(X, axes)) by a Concat of Shape(X) slices interleaved with constant [1] tensors at the inserted axis positions.

128

UnsqueezeUnsqueeze (unsqueeze)

Python — Merges two consecutive Unsqueeze nodes into a single one.

129

WhereAdd (expand)

Python — Rewrites an additive mask or factors a common term from Where branches.