提交 a04ac4bc authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Rename SeqOptimizer to SequentialGraphRewriter

上级 89655604
...@@ -231,13 +231,13 @@ def inplace_graph_rewriter(f): ...@@ -231,13 +231,13 @@ def inplace_graph_rewriter(f):
return rval return rval
class SeqOptimizer(GraphRewriter, UserList): class SequentialGraphRewriter(GraphRewriter, UserList):
"""A `GraphRewriter` that applies a list of optimizers sequentially.""" """A `GraphRewriter` that applies a list of optimizers sequentially."""
@staticmethod @staticmethod
def warn(exc, self, optimizer): def warn(exc, self, optimizer):
"""Default ``failure_callback`` for `SeqOptimizer`.""" """Default ``failure_callback`` for `SequentialGraphRewriter`."""
_logger.error(f"SeqOptimizer apply {optimizer}") _logger.error(f"SequentialGraphRewriter apply {optimizer}")
_logger.error("Traceback:") _logger.error("Traceback:")
_logger.error(traceback.format_exc()) _logger.error(traceback.format_exc())
if config.on_opt_error == "raise": if config.on_opt_error == "raise":
...@@ -378,7 +378,7 @@ class SeqOptimizer(GraphRewriter, UserList): ...@@ -378,7 +378,7 @@ class SeqOptimizer(GraphRewriter, UserList):
blanc = " " * level blanc = " " * level
print(blanc, "SeqOptimizer", end=" ", file=stream) print(blanc, "SequentialGraphRewriter", end=" ", file=stream)
if hasattr(opts, "name"): if hasattr(opts, "name"):
print(blanc, opts.name, end=" ", file=stream) print(blanc, opts.name, end=" ", file=stream)
elif hasattr(opts, "__name__"): elif hasattr(opts, "__name__"):
...@@ -487,7 +487,7 @@ class SeqOptimizer(GraphRewriter, UserList): ...@@ -487,7 +487,7 @@ class SeqOptimizer(GraphRewriter, UserList):
new_l.append(l) new_l.append(l)
new_sub_profile.append(p[6][idx]) new_sub_profile.append(p[6][idx])
new_opt = SeqOptimizer(*new_l) new_opt = SequentialGraphRewriter(*new_l)
new_nb_nodes = [] new_nb_nodes = []
for p1, p2 in zip(prof1[8], prof2[8]): for p1, p2 in zip(prof1[8], prof2[8]):
new_nb_nodes.append((p1[0] + p2[0], p1[1] + p2[1])) new_nb_nodes.append((p1[0] + p2[0], p1[1] + p2[1]))
...@@ -3153,6 +3153,11 @@ DEPRECATED_NAMES = [ ...@@ -3153,6 +3153,11 @@ DEPRECATED_NAMES = [
"`LocalMetaOptimizer` is deprecated: use `MetaNodeRewriter` instead.", "`LocalMetaOptimizer` is deprecated: use `MetaNodeRewriter` instead.",
MetaNodeRewriter, MetaNodeRewriter,
), ),
(
"SeqOptimizer",
"`SeqOptimizer` is deprecated: use `SequentialGraphRewriter` instead.",
SequentialGraphRewriter,
),
] ]
......
...@@ -353,22 +353,20 @@ class EquilibriumDB(OptimizationDatabase): ...@@ -353,22 +353,20 @@ class EquilibriumDB(OptimizationDatabase):
class SequenceDB(OptimizationDatabase): class SequenceDB(OptimizationDatabase):
"""A sequence of potential optimizations. """A sequence of potential rewrites.
Retrieve a sequence of optimizations (a SeqOptimizer) by calling query(). Retrieve a sequence of rewrites as a `SequentialGraphRewriter` by calling
`SequenceDB.query`.
Each potential optimization is registered with a floating-point position. Each potential optimization is registered with a floating-point position.
No matter which optimizations are selected by a query, they are carried No matter which optimizations are selected by a query, they are carried
out in order of increasing position. out in order of increasing position.
The optdb itself (`aesara.compile.mode.optdb`), from which (among many
other tags) fast_run and fast_compile optimizers are drawn is a SequenceDB.
""" """
seq_opt = aesara_opt.SeqOptimizer seq_opt = aesara_opt.SequentialGraphRewriter
def __init__(self, failure_callback=aesara_opt.SeqOptimizer.warn): def __init__(self, failure_callback=aesara_opt.SequentialGraphRewriter.warn):
super().__init__() super().__init__()
self.__position__ = {} self.__position__ = {}
self.failure_callback = failure_callback self.failure_callback = failure_callback
......
...@@ -747,7 +747,7 @@ two or more states and nothing will get done. ...@@ -747,7 +747,7 @@ two or more states and nothing will get done.
:obj:`optdb` structure :obj:`optdb` structure
---------------------- ----------------------
:obj:`optdb` contains the following :class:`Optimizer`\s and sub-DBs, with the given :obj:`optdb` contains the following :class:`Rewriters`\s and sub-DBs, with the given
priorities and tags: priorities and tags:
+-------+---------------------+------------------------------+ +-------+---------------------+------------------------------+
...@@ -855,7 +855,7 @@ This will output something like this: ...@@ -855,7 +855,7 @@ This will output something like this:
Optimizer Profile Optimizer Profile
----------------- -----------------
SeqOptimizer OPT_FAST_RUN time 1.152s for 123/50 nodes before/after optimization SequentialGraphRewriter OPT_FAST_RUN time 1.152s for 123/50 nodes before/after optimization
0.028s for fgraph.validate() 0.028s for fgraph.validate()
0.131s for callback 0.131s for callback
time - (name, class, index) - validate time time - (name, class, index) - validate time
...@@ -924,8 +924,8 @@ This will output something like this: ...@@ -924,8 +924,8 @@ This will output something like this:
0.000s - local_subtensor_of_alloc 0.000s - local_subtensor_of_alloc
0.000s - local_subtensor_of_dot 0.000s - local_subtensor_of_dot
0.000s - local_subtensor_merge 0.000s - local_subtensor_merge
0.101733s - ('elemwise_fusion', 'SeqOptimizer', 13) - 0.000s 0.101733s - ('elemwise_fusion', 'SequentialGraphRewriter', 13) - 0.000s
SeqOptimizer elemwise_fusion time 0.102s for 78/50 nodes before/after optimization SequentialGraphRewriter elemwise_fusion time 0.102s for 78/50 nodes before/after optimization
0.000s for fgraph.validate() 0.000s for fgraph.validate()
0.004s for callback 0.004s for callback
0.095307s - ('composite_elemwise_fusion', 'FusionOptimizer', 1) - 0.000s 0.095307s - ('composite_elemwise_fusion', 'FusionOptimizer', 1) - 0.000s
...@@ -945,8 +945,8 @@ This will output something like this: ...@@ -945,8 +945,8 @@ This will output something like this:
callback_time 0.000783205032349 callback_time 0.000783205032349
time_toposort 0.0035240650177 time_toposort 0.0035240650177
0.090089s - ('inplace_elemwise_optimizer', 'FromFunctionGraphRewriter', 30) - 0.019s 0.090089s - ('inplace_elemwise_optimizer', 'FromFunctionGraphRewriter', 30) - 0.019s
0.048993s - ('BlasOpt', 'SeqOptimizer', 8) - 0.000s 0.048993s - ('BlasOpt', 'SequentialGraphRewriter', 8) - 0.000s
SeqOptimizer BlasOpt time 0.049s for 81/80 nodes before/after optimization SequentialGraphRewriter BlasOpt time 0.049s for 81/80 nodes before/after optimization
0.000s for fgraph.validate() 0.000s for fgraph.validate()
0.003s for callback 0.003s for callback
0.035997s - ('gemm_optimizer', 'GemmOptimizer', 1) - 0.000s 0.035997s - ('gemm_optimizer', 'GemmOptimizer', 1) - 0.000s
...@@ -1042,21 +1042,21 @@ This will output something like this: ...@@ -1042,21 +1042,21 @@ This will output something like this:
To understand this profile here is some explanation of how optimizations work: To understand this profile here is some explanation of how optimizations work:
* Optimizations are organized in an hierarchy. At the top level, there * Optimizations are organized in an hierarchy. At the top level, there
is a :class:`SeqOptimizer`. It contains other optimizers, is a :class:`SequentialGraphRewriter`. It contains other optimizers,
and applies them in the order they were specified. Those sub-optimizers can be and applies them in the order they were specified. Those sub-optimizers can be
of other types, but are all *global* optimizers. of other types, but are all *global* optimizers.
* Each :class:`Optimizer` in the hierarchy will print some stats about * Each :class:`Rewriter` in the hierarchy will print some stats about
itself. The information that it prints depends of the type of the itself. The information that it prints depends of the type of the
optimizer. optimizer.
* The :class:`SeqOptimizer` will print some stats at the start: * The :class:`SequentialGraphRewriter` will print some stats at the start:
.. code-block:: none .. code-block:: none
Optimizer Profile Optimizer Profile
----------------- -----------------
SeqOptimizer OPT_FAST_RUN time 1.152s for 123/50 nodes before/after optimization SequentialGraphRewriter OPT_FAST_RUN time 1.152s for 123/50 nodes before/after optimization
0.028s for fgraph.validate() 0.028s for fgraph.validate()
0.131s for callback 0.131s for callback
time - (name, class, index) - validate time time - (name, class, index) - validate time
...@@ -1071,12 +1071,12 @@ To understand this profile here is some explanation of how optimizations work: ...@@ -1071,12 +1071,12 @@ To understand this profile here is some explanation of how optimizations work:
* 0.028s means it spent that time calls to ``fgraph.validate()`` * 0.028s means it spent that time calls to ``fgraph.validate()``
* 0.131s means it spent that time for callbacks. This is a mechanism that can trigger other execution when there is a change to the FunctionGraph. * 0.131s means it spent that time for callbacks. This is a mechanism that can trigger other execution when there is a change to the FunctionGraph.
* ``time - (name, class, index) - validate time`` tells how the information for each sub-optimizer get printed. * ``time - (name, class, index) - validate time`` tells how the information for each sub-optimizer get printed.
* All other instances of :class:`SeqOptimizer` are described like this. In * All other instances of :class:`SequentialGraphRewriter` are described like this. In
particular, some sub-optimizer from ``OPT_FAST_RUN`` that are also particular, some sub-optimizer from ``OPT_FAST_RUN`` that are also
:class:`SeqOptimizer`. :class:`SequentialGraphRewriter`.
* The :class:`SeqOptimizer` will print some stats at the start: * The :class:`SequentialGraphRewriter` will print some stats at the start:
.. code-block:: none .. code-block:: none
...@@ -1147,11 +1147,11 @@ To understand this profile here is some explanation of how optimizations work: ...@@ -1147,11 +1147,11 @@ To understand this profile here is some explanation of how optimizations work:
0.000s - local_subtensor_merge 0.000s - local_subtensor_merge
* ``0.751816s - ('canonicalize', 'EquilibriumOptimizer', 4) - 0.004s`` * ``0.751816s - ('canonicalize', 'EquilibriumOptimizer', 4) - 0.004s``
This line is from :class:`SeqOptimizer`, and indicates information related This line is from :class:`SequentialGraphRewriter`, and indicates information related
to a sub-optimizer. It means that this sub-optimizer took to a sub-optimizer. It means that this sub-optimizer took
a total of .7s. Its name is ``'canonicalize'``. It is an a total of .7s. Its name is ``'canonicalize'``. It is an
:class:`EquilibriumOptimizer`. It was executed at index 4 by the :class:`EquilibriumOptimizer`. It was executed at index 4 by the
:class:`SeqOptimizer`. It spent 0.004s in the *validate* phase. :class:`SequentialGraphRewriter`. It spent 0.004s in the *validate* phase.
* All other lines are from the profiler of the :class:`EquilibriumOptimizer`. * All other lines are from the profiler of the :class:`EquilibriumOptimizer`.
* An :class:`EquilibriumOptimizer` does multiple passes on the Apply nodes from * An :class:`EquilibriumOptimizer` does multiple passes on the Apply nodes from
......
...@@ -53,7 +53,7 @@ class TestDB: ...@@ -53,7 +53,7 @@ class TestDB:
res = seq_db.query("+a") res = seq_db.query("+a")
assert isinstance(res, opt.SeqOptimizer) assert isinstance(res, opt.SequentialGraphRewriter)
assert res.data == [] assert res.data == []
seq_db.register("b", TestOpt(), position=1) seq_db.register("b", TestOpt(), position=1)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论