yobx.xoptim.patterns_exp.constant_of_shape_scatter_nd#
- class yobx.xoptim.patterns_exp.constant_of_shape_scatter_nd.ConstantOfShapeScatterNDPattern(verbose: int = 0, priority: int = 1, min_opset: int = 1)[source]#
Replaces ConstantOfShape + ScatterND with ScatterNDOfShape.
Model with nodes to be fused:
graph TD classDef ioNode fill:#dfd,stroke:#333,color:#333 classDef initNode fill:#cccc00,stroke:#333,color:#333 classDef constNode fill:#f9f,stroke:#333,stroke-width:2px,color:#333 classDef opNode fill:#bbf,stroke:#333,stroke-width:2px,color:#333 I_indices(["indices INT64(DIM1, DIM2, 1)"]) I_shape(["shape INT64(DIM)"]) I_masked_updates(["masked_updates FLOAT(DIM1^DIM3, DIM2^DIM4, DIM5)"]) ConstantOfShape_0[["ConstantOfShape(.)"]] ScatterND_1[["ScatterND(., ., .)"]] I_shape -->|"INT64(DIM)"| ConstantOfShape_0 ConstantOfShape_0 --> ScatterND_1 I_indices -->|"INT64(DIM1, DIM2, 1)"| ScatterND_1 I_masked_updates -->|"FLOAT(DIM1^DIM3, DIM2^DIM4, DIM5)"| ScatterND_1 O_y(["y FLOAT(DIM6, DIM7)"]) ScatterND_1 --> O_y class I_indices,I_shape,I_masked_updates,O_y ioNode class ConstantOfShape_0,ScatterND_1 opNodeOutcome of the fusion:
graph TD classDef ioNode fill:#dfd,stroke:#333,color:#333 classDef initNode fill:#cccc00,stroke:#333,color:#333 classDef constNode fill:#f9f,stroke:#333,stroke-width:2px,color:#333 classDef opNode fill:#bbf,stroke:#333,stroke-width:2px,color:#333 I_indices(["indices INT64(DIM1, DIM2, 1)"]) I_shape(["shape INT64(DIM)"]) I_masked_updates(["masked_updates FLOAT(DIM1^DIM3, DIM2^DIM4, DIM5)"]) ScatterNDOfShape_0[["onnx_extended.ortops.optim.cuda.ScatterNDOfShape(., ., .)"]] I_shape -->|"INT64(DIM)"| ScatterNDOfShape_0 I_indices -->|"INT64(DIM1, DIM2, 1)"| ScatterNDOfShape_0 I_masked_updates -->|"FLOAT(DIM1^DIM3, DIM2^DIM4, DIM5)"| ScatterNDOfShape_0 O_y(["y FLOAT(DIM6, DIM7)"]) ScatterNDOfShape_0 --> O_y class I_indices,I_shape,I_masked_updates,O_y ioNode class ScatterNDOfShape_0 opNode- apply(g: GraphBuilder, node_before: NodeProto, node: NodeProto) List[NodeProto][source]#
The method does the rewriting. It assumes it can happen. It takes a list of nodes impacted by the rewriting assumes no other pattern optimizer will be modify them. It receives the list of nodes returned by method apply. Since it is a list of argument, method match can include None values. The method returns the new nodes. The optimizer considers that any node given to this function is removed from the graph, and any node returned by it are added. If a received node must be kept, it must be added to the list of returned node.
- Parameters:
nodes – nodes returned by method match, there are then removed
- Returns:
nodes to add to graph.
- match(g: GraphBuilderPatternOptimization, node: NodeProto, matched: List[MatchResult]) MatchResult | None[source]#
Determines nodes around node which can be rewritten.
- Parameters:
g – is a
GraphBuilderPatternOptimization, it holds all the existing nodes, is able to return any information about type, shape, the node before, the node after another one.node – the matching must determine if some nodes around this one are part of set of nodes this pattern optimizer can rewrite. From there, the function explores wherever it needs, checking any condition it needs.
matched – usually unused, it returns of nodes already matching a pattern
The method must not modify the graph. The method returns None if no match is found or an instance of class
MatchResult. It must contain:a list of nodes involved in the rewriting. It does not mean all of them will be removed but all of them are needed to do the rewriting and must not be impacted by other pattern optimizer.
A function doing the rewriting (usually method apply of the pattern class).
An existing node where the rewritten nodes can be inserted. Knowing it makes it faster to rewriter. If not specified, the optimizer will automatically determine the position of the new nodes.
- class yobx.xoptim.patterns_exp.constant_of_shape_scatter_nd.MaskedShapeScatterNDPattern(verbose: int = 0, priority: int = 1, min_opset: int = 1)[source]#
Replaces Equal, Where, ScatterNDOfShape by MaskedScatterNDOfShape.
Model with nodes to be fused:
graph TD classDef ioNode fill:#dfd,stroke:#333,color:#333 classDef initNode fill:#cccc00,stroke:#333,color:#333 classDef constNode fill:#f9f,stroke:#333,stroke-width:2px,color:#333 classDef opNode fill:#bbf,stroke:#333,stroke-width:2px,color:#333 I_updates(["updates FLOAT(DIM3, DIM4, DIM5)"]) I_indices(["indices INT64(DIM1, DIM2, 1)"]) I_shape(["shape INT64(DIM)"]) ScatterNDOfShape_0[["onnx_extended.ortops.optim.cuda.ScatterNDOfShape(., ., .)"]] Where_1[["Where(., [0.0], .)"]] Equal_2[["Equal(., [-1])"]] I_shape -->|"INT64(DIM)"| ScatterNDOfShape_0 I_indices -->|"INT64(DIM1, DIM2, 1)"| ScatterNDOfShape_0 Where_1 --> ScatterNDOfShape_0 Equal_2 -->|"BOOL(DIM1, DIM2, 1)"| Where_1 I_updates -->|"FLOAT(DIM3, DIM4, DIM5)"| Where_1 I_indices -->|"INT64(DIM1, DIM2, 1)"| Equal_2 O_y(["y FLOAT(DIM6, DIM7)"]) ScatterNDOfShape_0 --> O_y class I_updates,I_indices,I_shape,O_y ioNode class ScatterNDOfShape_0,Where_1,Equal_2 opNodeOutcome of the fusion:
graph TD classDef ioNode fill:#dfd,stroke:#333,color:#333 classDef initNode fill:#cccc00,stroke:#333,color:#333 classDef constNode fill:#f9f,stroke:#333,stroke-width:2px,color:#333 classDef opNode fill:#bbf,stroke:#333,stroke-width:2px,color:#333 I_updates(["updates FLOAT(DIM3, DIM4, DIM5)"]) I_indices(["indices INT64(DIM1, DIM2, 1)"]) I_shape(["shape INT64(DIM)"]) MaskedScatterNDOfShape_0[["onnx_extended.ortops.optim.cuda.MaskedScatterNDOfShape( ., ., .)"]] I_shape -->|"INT64(DIM)"| MaskedScatterNDOfShape_0 I_indices -->|"INT64(DIM1, DIM2, 1)"| MaskedScatterNDOfShape_0 I_updates -->|"FLOAT(DIM3, DIM4, DIM5)"| MaskedScatterNDOfShape_0 O_y(["y FLOAT(DIM6, DIM7)"]) MaskedScatterNDOfShape_0 --> O_y class I_updates,I_indices,I_shape,O_y ioNode class MaskedScatterNDOfShape_0 opNode- apply(g: GraphBuilder, scatter_node: NodeProto, where_node: NodeProto, equal_node: NodeProto) List[NodeProto][source]#
The method does the rewriting. It assumes it can happen. It takes a list of nodes impacted by the rewriting assumes no other pattern optimizer will be modify them. It receives the list of nodes returned by method apply. Since it is a list of argument, method match can include None values. The method returns the new nodes. The optimizer considers that any node given to this function is removed from the graph, and any node returned by it are added. If a received node must be kept, it must be added to the list of returned node.
- Parameters:
nodes – nodes returned by method match, there are then removed
- Returns:
nodes to add to graph.
- match(g: GraphBuilderPatternOptimization, node: NodeProto, matched: List[MatchResult]) MatchResult | None[source]#
Determines nodes around node which can be rewritten.
- Parameters:
g – is a
GraphBuilderPatternOptimization, it holds all the existing nodes, is able to return any information about type, shape, the node before, the node after another one.node – the matching must determine if some nodes around this one are part of set of nodes this pattern optimizer can rewrite. From there, the function explores wherever it needs, checking any condition it needs.
matched – usually unused, it returns of nodes already matching a pattern
The method must not modify the graph. The method returns None if no match is found or an instance of class
MatchResult. It must contain:a list of nodes involved in the rewriting. It does not mean all of them will be removed but all of them are needed to do the rewriting and must not be impacted by other pattern optimizer.
A function doing the rewriting (usually method apply of the pattern class).
An existing node where the rewritten nodes can be inserted. Knowing it makes it faster to rewriter. If not specified, the optimizer will automatically determine the position of the new nodes.