elasticai.creator.ir.rewriting.rewriter
#
Module Contents#
Classes#
Use a given mapping to make the data dictionary accessible via node names from graph. |
|
Apply list of |
|
Specifies how |
Functions#
Data#
API#
- elasticai.creator.ir.rewriting.rewriter.N#
‘TypeVar(…)’
- elasticai.creator.ir.rewriting.rewriter.E#
‘TypeVar(…)’
- class elasticai.creator.ir.rewriting.rewriter.RemappedSubImplementation(mapping: dict[str, str], graph: elasticai.creator.graph.Graph[str], data: dict[str, elasticai.creator.ir.base.attribute.Attribute], node_fn: collections.abc.Callable[[str, dict[str, elasticai.creator.ir.base.attribute.Attribute]], elasticai.creator.ir.rewriting.rewriter.N])[source]#
Bases:
typing.Generic
[elasticai.creator.ir.rewriting.rewriter.N
]Use a given mapping to make the data dictionary accessible via node names from graph.
This allows to access the data dictionary using the names from the graph. The provided mapping is used to map the node names of the graph to the node names in the data dictionary. This is used e.g., to initialize new nodes, that were replaced during rewriting. The mapping is assumed to be one-to-one, i.e. each node name in the graph maps to exactly one node name in the data dictionary.
Initialization
- property nodes: collections.abc.Mapping[str, elasticai.creator.ir.rewriting.rewriter.N]#
- elasticai.creator.ir.rewriting.rewriter.remap_sub_implementation(mapping: dict[str, str], graph: elasticai.creator.graph.Graph[str], data: dict[str, elasticai.creator.ir.base.attribute.Attribute], node_fn: collections.abc.Callable[[str, dict[str, elasticai.creator.ir.base.attribute.Attribute]], elasticai.creator.ir.rewriting.rewriter.N] | None = None) elasticai.creator.ir.rewriting.rewriter.RemappedSubImplementation[elasticai.creator.ir.rewriting.rewriter.N] | elasticai.creator.ir.rewriting.rewriter.RemappedSubImplementation[elasticai.creator.ir.core.Node] [source]#
- class elasticai.creator.ir.rewriting.rewriter.Rewriter[source]#
Apply list of
RewriteRule
s to anImplementation
.The result is a new implementation. The original implementation is not modified. The rules are applied in the order they were added. For more information on how to create rules, see
RewriteRule
.Initialization
- add_rule(rule: elasticai.creator.ir.rewriting.rewriter.RewriteRule) Self [source]#
- class elasticai.creator.ir.rewriting.rewriter.RewriteRule(pattern: elasticai.creator.ir.core.Implementation, replacement: collections.abc.Callable[[elasticai.creator.ir.rewriting.rewriter.RemappedSubImplementation], elasticai.creator.ir.core.Implementation], node_constraint: collections.abc.Callable[[elasticai.creator.ir.core.Node, elasticai.creator.ir.core.Node], bool], interface: set[str])[source]#
Specifies how
Rewriter
should create a newImplementation
from an existing one.A rule consists of
a pattern to match in the original implementation. Which attributes these nodes should have depends on your implementation of the
node_constraint
function.a replacement to apply when the pattern is matched. The
Rewriter
will use thereplacement
function to create a newImplementation
. The function receives the matched part of the implementation as an argument, so you can build the replacement based on the parameters found in your matched pattern. The node names in this matched subimplementation are remapped from the original graph to the pattern graph, so you can access the data dictionary using the names from the pattern graph. E.g., if the pattern specifies a node'conv'
you can acces the data of the original implementation that this node corresponds to usingmatched.nodes['conv'].data
.a node constraint to check if a pattern node matches a node in the original implementation
an interface that specifies which nodes are part of the pattern and of the replacement, nodes that are part of the interface are neither replaced nor initialized. Instead they are used to connect the pattern and the replacement.
Initialization