experimental_experiment.xoptim.patterns.onnx_functions

class experimental_experiment.xoptim.patterns.onnx_functions.GeluPattern(verbose: int = 0, priority: int = 0, min_opset: int = 20, domain: str = '')[source]

Detects the decomposed version of Gelu with Tanh

y = \frac{x}{2}
\left(1 + \tanh\left(\sqrt{\frac{2}{\pi}} (x + 0.044715 * x^3)\right)\right)

apply_pattern(g: GraphBuilder, x, c3, c04, cpi, one, c2)[source]

Applies the replacement.

match_pattern(g: GraphBuilder, x, c3, c04, cpi, one, c2)[source]

Builds the pattern to match.

validate_mapping(g: GraphBuilderPatternOptimization, deleted_nodes: List[NodeProto], pattern_nodes: List[NodeProto] | None = None) bool[source]

Validates the mapping.

Parameters:
  • g – GraphBuilder

  • deleted_nodes – matched nodes from the model (to be deleted)

  • pattern_nodes – matched nodes coming from the pattern

Returns:

validate the mapping or not, default is True

class experimental_experiment.xoptim.patterns.onnx_functions.LeakyReluPattern(verbose: int = 0, priority: int = 0, min_opset: int = 6)[source]

Detects the decomposed version of LeakyRelu.

apply_pattern(g: GraphBuilder, x, zero, slope)[source]

Applies the replacement.

match_pattern(g: GraphBuilder, x, zero, slope)[source]

Builds the pattern to match.

validate_mapping(g: GraphBuilderPatternOptimization, deleted_nodes: List[NodeProto], pattern_nodes: List[NodeProto] | None = None) bool[source]

Validates the mapping.

Parameters:
  • g – GraphBuilder

  • deleted_nodes – matched nodes from the model (to be deleted)

  • pattern_nodes – matched nodes coming from the pattern

Returns:

validate the mapping or not, default is True

class experimental_experiment.xoptim.patterns.onnx_functions.SoftmaxCrossEntropyLossCastPattern(verbose: int = 0, priority: int = 0, min_opset: int = 14, domain: str = '')[source]

Detects one decomposed version of SoftmaxCrossEntropyLoss.

classmethod apply_pattern(g: GraphBuilder, X, indices, axis, zerof, zeroi, b)[source]

Applies the replacement.

match_pattern(g: GraphBuilder, X, indices, axis, zerof, zeroi, b)[source]

Builds the pattern to match.

validate_mapping(g: GraphBuilderPatternOptimization, deleted_nodes: List[NodeProto], pattern_nodes: List[NodeProto] | None = None) bool[source]

Validates the mapping.

Parameters:
  • g – GraphBuilder

  • deleted_nodes – matched nodes from the model (to be deleted)

  • pattern_nodes – matched nodes coming from the pattern

Returns:

validate the mapping or not, default is True