提交 5b13a73a authored 作者: Frederic's avatar Frederic

Add comments/docstring

上级 4cbd9ff5
...@@ -200,7 +200,7 @@ optdb.register('merge1', gof.MergeOptimizer(), ...@@ -200,7 +200,7 @@ optdb.register('merge1', gof.MergeOptimizer(),
# rearranges elemwise expressions # rearranges elemwise expressions
optdb.register('canonicalize', gof.EquilibriumDB(ignore_newtrees=False), optdb.register('canonicalize', gof.EquilibriumDB(ignore_newtrees=False),
1, 'fast_run', 'fast_compile') 1, 'fast_run', 'fast_compile')
# Register in the canonizer Equilibrium as a local opt the merge opt. # Register in the canonizer Equilibrium as a clean up opt the merge opt.
# Without this, as the equilibrium have ignore_newtrees=False, we # Without this, as the equilibrium have ignore_newtrees=False, we
# won't merge all nodes if it is set as a global optimizer with # won't merge all nodes if it is set as a global optimizer with
# final_opt=True. # final_opt=True.
......
...@@ -547,6 +547,7 @@ class CLinker(link.Linker): ...@@ -547,6 +547,7 @@ class CLinker(link.Linker):
if no_recycling is None: if no_recycling is None:
no_recycling = [] no_recycling = []
if self.fgraph is not None and self.fgraph is not fgraph: if self.fgraph is not None and self.fgraph is not fgraph:
# A linker can be tied to only one FunctionGraph.
return type(self)(self.schedule).accept(fgraph, no_recycling) return type(self)(self.schedule).accept(fgraph, no_recycling)
self.fgraph = fgraph self.fgraph = fgraph
self.fetch_variables() self.fetch_variables()
...@@ -1750,14 +1751,13 @@ class OpWiseCLinker(link.LocalLinker): ...@@ -1750,14 +1751,13 @@ class OpWiseCLinker(link.LocalLinker):
if no_recycling is None: if no_recycling is None:
no_recycling = [] no_recycling = []
if self.fgraph is not None and self.fgraph is not fgraph: if self.fgraph is not None and self.fgraph is not fgraph:
# A linker can be tied to only one FunctionGraph.
return type(self)( return type(self)(
fallback_on_perform=self.fallback_on_perform, fallback_on_perform=self.fallback_on_perform,
allow_gc=self.allow_gc, allow_gc=self.allow_gc,
nice_errors=self.nice_errors, nice_errors=self.nice_errors,
schedule=self.schedule, schedule=self.schedule,
).accept(fgraph, no_recycling) ).accept(fgraph, no_recycling)
# raise Exception("Cannot accept from a Linker that is
# already tied to another FunctionGraph.")
self.fgraph = fgraph self.fgraph = fgraph
self.no_recycling = no_recycling self.no_recycling = no_recycling
return self return self
......
...@@ -1981,13 +1981,22 @@ class EquilibriumOptimizer(NavigatorOptimizer): ...@@ -1981,13 +1981,22 @@ class EquilibriumOptimizer(NavigatorOptimizer):
Parameters Parameters
---------- ----------
optimizers optimizers : list or set
List or set of local or global optimizations to apply until equilibrium. Local or global optimizations to apply until equilibrium.
max_use_ratio The global optimizer will be run at the start of each iteration before
the local optimizer.
max_use_ratio : int or float
Each optimizer can be applied at most (size of graph * this number) Each optimizer can be applied at most (size of graph * this number)
times. times.
ignore_newtrees ignore_newtrees
See EquilibriumDB ignore_newtrees parameter definition. See EquilibriumDB ignore_newtrees parameter definition.
final_optimizers
Global optimizers that will be run after each iteration.
cleanup_optimizers
Global optimizers that apply a list of pre determined optimization.
They must not traverse the graph as they are called very frequently.
The MergeOptimizer is one example of optimization that respect this.
They are applied after all global optimizer, then when one local optimizer is applied, then after all final optimizer.
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论