.. index:: pair: page; Supported Fusion Patterns .. _doxid-dev_guide_graph_fusion_patterns: Supported Fusion Patterns ========================= :target:`doxid-dev_guide_graph_fusion_patterns_1fusion_patterns` Fusion Patterns ~~~~~~~~~~~~~~~ The following fusion patterns are subgraphs that the oneDNN Graph API recognizes as candidate for fusion. The patterns are described using oneDNN Graph operation (op) names with the following convention. .. note:: oneDNN Graph performs limited input validation to minimize the performance overheads. The application is responsible for sanitizing inputs passed to the library. For large u8 or s8 inputs may lead to accumulator overflow, you can use floating point patterns instead of quantized patterns. ``"+"`` describes a chain of two ops. The preceding op produces an output tensor, which is consumed by the following op as its first operand. ``"[]"`` describes a component of the overall pattern description. For example, it could include a subgraph or all the op choices within the bracket. ``"|"`` describes choices of multiple operations, say A+[B\|C] means the graph partition contains A followed by B or C. ``","`` describes a graph composed of multiple subgraphs, each subgraph marks its output tensor explicitly, which is consumed by other subgraphs. ``Superscript`` denotes the numbers of repetition pattern. For example, A+[B\|C] :math:`^{3}` means the graph partition contains A followed by three ops, each of them is either B or C. The superscript could be a range of number meaning allowing a range of repetition. If the range is between 0 and 1, we use superscript ``"?"``. ``Subscript`` denotes the input and output tensors which need to explicitly mark the producer and consumer relation within one graph partition. For example, A :math:`_{>t1}` +B+C :math:`_{"`` refers to the output tensor, and ``"<"`` for input tensor. Input and output tensor between neighbor ops are not explicitly marked, for example, B consumes t1 implicitly in the example above. Subscript ``"out"`` marks the output tensor of a certain op to be the output of a graph partition. For example, in A :math:`_{>t1}` +B :math:`_{>out}` +C :math:`_{out}`, B's output and C's output are marked as output tensors. Subscript ``"in"`` marks the input tensor of a certain op to be the input of a graph partition. For example, in A :math:`_{t1}` +B+C :math:`_{out}` This pattern is widely used in Convolution Neural Networks, for example ResNet, ResNext, SSD, etc. ConvTranspose + BiasAdd :math:`^?` + [Unary | Binary] :math:`^{0-3}` :math:`_{>out}` This pattern is widely used in Generative Adversarial Networks. Interpolate + [Unary | Binary] :math:`^{0-3}` :math:`_{>out}` This pattern is widely used for image processing. MatMul + BiasAdd :math:`^?` + [Unary | Binary] :math:`^{0-3}` + Select :math:`^?` :math:`_{>out}` This pattern is widely used in language models and recommendation models, for example BERT, DLRM, etc. Reduction + [Unary | Binary] :math:`^{0-3}` :math:`_{>out}` This pattern is widely used for data processing, for example loss reduction. Unary + Binary :math:`^{0-3}` :math:`_{>out}` This pattern is widely used in Convolution Neural Networks. Binary + [Unary | Binary] :math:`^{0-3}` :math:`_{>out}` This pattern is widely used in Generative Adversarial Networks, for example ParallelWaveGAN. [AvgPool | MaxPool] + Binary :math:`^{0-3}` :math:`_{>out}` This pattern is widely used in Convolution Neural Networks. BatchNormInference + ReLU :math:`_{>out}` This pattern is widely used in Convolution Neural Networks, for example DenseNet. Reciprocal + Multiply :math:`_{>out}` N/A Reorder + Add :math:`_{>out}` N/A =================================================================================================================== ======================================================================================================= Quantized Patterns ++++++++++++++++++ ================================================================================================================================================================================================================================================================= ============ Pattern Description ================================================================================================================================================================================================================================================================= ============ Quantize :math:`^?` + Dequantize :math:`_{>t1}` , Dequantize :math:`_{>t2}` :math:`^{0-3}` , Dequantize + Convolution :math:`_{out}` N/A Quantize :math:`^?` + Dequantize :math:`_{>t1}` , Dequantize :math:`_{>t2}` :math:`^{0-3}` , Dequantize + ConvTranspose :math:`_{out}` N/A Quantize :math:`^?` + Dequantize :math:`_{>t1}` , Dequantize :math:`_{>t2}` :math:`^{0-3}` , Dequantize + MatMul :math:`_{out}` N/A Dequantize + [AvgPool | MaxPool] + Quantize :math:`_{>out}` N/A Dequantize :math:`_{>t1}` , Dequantize + [AvgPool | MaxPool] + Add :math:`_{out}` N/A Dequantize + Reorder + Quantize :math:`_{>out}` N/A Dequantize :math:`_{>t1}` , Dequantize + Reorder + Add :math:`_{out}` N/A ================================================================================================================================================================================================================================================================= ============ Training -------- ============================================================= ============ Pattern Description ============================================================= ============ ConvolutionBackwardWeights + BiasAddBackward :math:`_{>out}` N/A ReLUBackward + BatchNormTrainingBackward :math:`_{>out}` N/A ============================================================= ============ All the above fusion patterns are supported by default. Aggressive Fusion Patterns ~~~~~~~~~~~~~~~~~~~~~~~~~~ Aggressive fusion patterns also follow the pattern description convention defined in the :ref:`Fusion Patterns ` section. .. note:: Aggressive fusion patterns are only supported when :ref:`Graph Compiler ` is enabled. The following categories will also be used to describe aggressive fusion patterns. * ReshapeTranspose = [StaticReshape + StaticTranspose :math:`^{1-2}`] * Activation = [ReLU \| Sigmoid \| GELU] * ActivationBackward = [ReLUBackward \| SigmoidBackward \| GELUBackward] Inference --------- Floating Point Patterns +++++++++++++++++++++++ ============================================================================================================================================================================================================================= ========================================================================================================================================================== Pattern Description ============================================================================================================================================================================================================================= ========================================================================================================================================================== MatMul + [Multiply | Divide] + Add + Softmax + MatMul + StaticTranspose + Reorder :math:`_{>out}` Multi-head Attention. This pattern is widely used in models containing encoder-decoder structures, for example BERT. ReshapeTranspose :math:`_{>t1}` , ReshapeTranspose :math:`_{>t2}` , ReshapeTranspose + MatMul :math:`_{out}` Multi-head Attention. MatMul + Activation :math:`_{>t1}` , [MatMul :math:`_{t1}` ] :math:`^{0-4}` , MatMul :math:`_{out}` Multi-layer Perceptron. This pattern is widely used in recommendation models, for example DLRM. [Convolution + BiasAdd :math:`^{?}` + ReLU] :math:`^{1-3}` + Convolution + BiasAdd :math:`^{?}` + Add + ReLU :math:`_{>out}` Identical Bottleneck. Enabled only in single thread runtime scenario. This pattern is widely used in Convolution Neural Networks, for example ResNet. Convolution + BiasAdd :math:`^{?}` :math:`_{>t1}` , [Convolution + BiasAdd :math:`^{?}` + ReLU] :math:`^{1-3}` + Convolution + BiasAdd :math:`^{?}` + Add :math:`_{out}` Convolutional Bottleneck. Enabled only in single thread runtime scenario. This pattern is widely used in Convolution Neural Networks, for example ResNet. ============================================================================================================================================================================================================================= ========================================================================================================================================================== Quantized Patterns ++++++++++++++++++ ======================================================================================================================================================================================================================================================================================================================================================================================================================== ==================================================================================== Pattern Description ======================================================================================================================================================================================================================================================================================================================================================================================================================== ==================================================================================== Dequantize :math:`_{>t1}` , Dequantize :math:`_{>t2}` , Dequantize + MatMul :math:`_{out}` Quantized Multi-head Attention. Dequantize + ReshapeTranspose :math:`_{>t1}` , Dequantize + ReshapeTranspose :math:`_{>t2}` , Dequantize + MatMul :math:`_{out}` Quantized Multi-head Attention. Dequantize :math:`_{>t1}` , Dequantize + MatMul :math:`_{t2}` , [Dequantize :math:`_{>t3}` , Dequantize :math:`_{t2}` ] :math:`^{0-4}` , Dequantize :math:`_{>t4}` , Dequantize :math:`_{out}` Quantized Multi-layer Perceptron. Dequantize :math:`_{>t2}` , Dequantize :math:`_{>t3}` , [Dequantize :math:`_{>t1}` , Dequantize + Convolution :math:`_{out}` Quantized Identical Bottleneck. Enabled only in single thread runtime scenario. [Dequantize :math:`_{>t1}` , Dequantize + Convolution :math:`_{t2}` , Dequantize :math:`_{>t4}` , [Dequantize :math:`_{>t3}` , Dequantize + Convolution :math:`_{out}` Quantized Convolutional Bottleneck. Enabled only in single thread runtime scenario. ======================================================================================================================================================================================================================================================================================================================================================================================================================== ==================================================================================== Training -------- ===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================== ==================================================== Pattern Description ===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================== ==================================================== Dequantize :math:`_{>t1}` , Dequantize :math:`_{>t2}` , Dequantize + MatMul :math:`_{out}` Multi-head Attention Training Forward Pattern. StaticReshape + StaticTranspose :math:`_{>t1}` + MatMul + Multiply :math:`_{>t2}` + Subtract :math:`_{t4}` + MatMul :math:`_{>out1}` , Multiply :math:`_{t3}` , MatMul :math:`_{out2}` , MatMul :math:`_{out3}` Multi-head Attention Training Backward Pattern. MatMul :math:`_{>out1}` + Activation :math:`_{>t1,>out2}` , [MatMul :math:`_{out3}` + Activation :math:`_{>t1,>out4}` ] :math:`^{0-4}` , MatMul :math:`_{out5}` + Activation :math:`_{>out6}` Multi-layer Perceptron Training Forward Pattern. StaticTranspose :math:`^{?}` :math:`_{>t0}` , ActivationBackward :math:`_{>t2}` + MatMul :math:`_{t1}` , ReduceSum :math:`^{?}` :math:`_{out1}` , StaticTranspose :math:`^{?}` + MatMul :math:`_{out2}` , [StaticTranspose :math:`^{?}` :math:`_{>t3}` , ActivationBackward :math:`_{>t4,t1}` , ReduceSum :math:`^{?}` :math:`_{out3}` , StaticTranspose :math:`^{?}` + MatMul :math:`_{out4}` ] :math:`^{0-4}` , StaticTranspose :math:`^{?}` :math:`_{>t5}` , ActivationBackward :math:`_{>t6,out5}` , ReduceSum :math:`^{?}` :math:`_{out6}` , StaticTranspose :math:`^{?}` + MatMul :math:`_{out7}` Multi-layer Perceptron Training Backward Pattern. Convolution :math:`_{>out1}` + BatchNormForwardTraining :math:`_{>out2}` + ReLU :math:`_{>out3}` + Convolution :math:`_{>out4}` + BatchNormForwardTraining :math:`_{>out5}` + ReLU :math:`_{>out6}` + Convolution :math:`_{>out7}` + BatchNormForwardTraining :math:`_{>out8}` + Add + ReLU :math:`_{>out9}` Identical Bottleneck Training Forward Pattern. Convolution :math:`_{>out1}` + BatchNormForwardTraining :math:`_{>t1,>out2}` , Convolution :math:`_{>out3}` + BatchNormForwardTraining :math:`_{>out4}` + ReLU :math:`_{>out5}` + Convolution :math:`_{>out6}` + BatchNormForwardTraining :math:`_{>out7}` + ReLU :math:`_{>out8}` + Convolution :math:`_{>out9}` + BatchNormForwardTraining :math:`_{>out10}` + Add :math:`_{out11}` Convolutional Bottleneck Training Forward Pattern. ReLUBackward :math:`_{>t1}` + BatchNormTrainingBackward :math:`_{>t2,>out1}` + ConvolutionBackwardData + ReLUBackward + BatchNormTrainingBackward :math:`_{>t3,>out2}` + ConvolutionBackwardData + ReLUBackward + BatchNormTrainingBackward :math:`_{>t4,>out3}` + ConvolutionBackwardData + Add :math:`_{out4}` , ConvolutionBackwardWeights :math:`_{out5}` , ConvolutionBackwardWeights :math:`_{out6}` , ConvolutionBackwardWeights :math:`_{out7}` Identical Bottleneck Training Backward Pattern. ReLUBackward :math:`_{>t1}` + BatchNormTrainingBackward :math:`_{>t2,>out1}` + ConvolutionBackwardData + ReLUBackward + BatchNormTrainingBackward :math:`_{>t3,>out2}` + ConvolutionBackwardData + ReLUBackward + BatchNormTrainingBackward :math:`_{>t4,>out3}` + ConvolutionBackwardData + Add :math:`_{out4}` , BatchNormTrainingBackward :math:`_{t5,>out5}` + ConvolutionBackwardData :math:`_{>t6}` , ConvolutionBackwardWeights :math:`_{out6}` , ConvolutionBackwardWeights :math:`_{out7}` , ConvolutionBackwardWeights :math:`_{out8}` , ConvolutionBackwardWeights :math:`_{out9}` Convolutional Bottleneck Training Backward Pattern. ===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================== ====================================================