Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0ce6eceb
提交
0ce6eceb
authored
7月 14, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
8月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor old global and local optimizers references and type hints
上级
550a6e98
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
23 行增加
和
53 行删除
+23
-53
kanren.py
aesara/graph/kanren.py
+2
-2
opt.py
aesara/graph/opt.py
+0
-0
optdb.py
aesara/graph/optdb.py
+17
-32
basic_opt.py
aesara/tensor/basic_opt.py
+0
-0
basic.py
aesara/tensor/nnet/basic.py
+4
-19
没有找到文件。
aesara/graph/kanren.py
浏览文件 @
0ce6eceb
...
@@ -11,7 +11,7 @@ from aesara.graph.unify import eval_if_etuple
...
@@ -11,7 +11,7 @@ from aesara.graph.unify import eval_if_etuple
class
KanrenRelationSub
(
NodeRewriter
):
class
KanrenRelationSub
(
NodeRewriter
):
r"""A
local optimiz
er that uses `kanren` to match and replace terms.
r"""A
rewrit
er that uses `kanren` to match and replace terms.
See `kanren <https://github.com/pythological/kanren>`__ for more information
See `kanren <https://github.com/pythological/kanren>`__ for more information
miniKanren and the API for constructing `kanren` goals.
miniKanren and the API for constructing `kanren` goals.
...
@@ -56,7 +56,7 @@ class KanrenRelationSub(NodeRewriter):
...
@@ -56,7 +56,7 @@ class KanrenRelationSub(NodeRewriter):
A function that takes an input graph and an output logic variable and
A function that takes an input graph and an output logic variable and
returns a `kanren` goal.
returns a `kanren` goal.
results_filter
results_filter
A function that takes the direct output of `
kanren.run(None, ...)
`
A function that takes the direct output of `
`kanren.run(None, ...)`
`
and returns a single result. The default implementation returns
and returns a single result. The default implementation returns
the first result.
the first result.
node_filter
node_filter
...
...
aesara/graph/opt.py
浏览文件 @
0ce6eceb
差异被折叠。
点击展开。
aesara/graph/optdb.py
浏览文件 @
0ce6eceb
...
@@ -290,55 +290,40 @@ class OptimizationQuery:
...
@@ -290,55 +290,40 @@ class OptimizationQuery:
class
EquilibriumDB
(
OptimizationDatabase
):
class
EquilibriumDB
(
OptimizationDatabase
):
"""
"""A database of rewrites that should be applied until equilibrium is reached.
A set of potential optimizations which should be applied in an arbitrary
order until equilibrium is reached.
Canonicalize, Stabilize, and Specialize are all equilibrium optimizations.
Canonicalize, Stabilize, and Specialize are all equilibrium optimizations.
Parameters
----------
ignore_newtrees
If False, we will apply local opt on new node introduced during local
optimization application. This could result in less fgraph iterations,
but this doesn't mean it will be faster globally.
tracks_on_change_inputs
If True, we will re-apply local opt on nodes whose inputs
changed during local optimization application. This could
result in less fgraph iterations, but this doesn't mean it
will be faster globally.
Notes
Notes
-----
-----
We can use `NodeRewriter` and `GraphRewriter` since `EquilibriumOptimizer`
We can use `NodeRewriter` and `GraphRewriter` since `EquilibriumOptimizer`
supports both.
supports both.
It is probably not a good idea to have
ignore_newtrees=False and
It is probably not a good idea to have
both ``ignore_newtrees == False``
tracks_on_change_inputs=True
and ``tracks_on_change_inputs == True``.
"""
"""
def
__init__
(
self
,
ignore_newtrees
=
True
,
tracks_on_change_inputs
=
False
):
def
__init__
(
self
,
ignore_newtrees
:
bool
=
True
,
tracks_on_change_inputs
:
bool
=
False
):
"""
"""
Parameters
Parameters
==========
----------
ignore_newtrees:
ignore_newtrees
If False, we will apply local opt on new node introduced during local
If ``False``, apply rewrites to new nodes introduced during
optimization application. This could result in less fgraph iterations,
rewriting.
but this doesn't mean it will be faster globally.
tracks_on_change_inputs
tracks_on_change_inputs:
If ``True``, re-apply rewrites on nodes with changed inputs.
If True, we will re-apply local opt on nodes whose inputs
changed during local optimization application. This could
result in less fgraph iterations, but this doesn't mean it
will be faster globally.
"""
"""
super
()
.
__init__
()
super
()
.
__init__
()
self
.
ignore_newtrees
=
ignore_newtrees
self
.
ignore_newtrees
=
ignore_newtrees
self
.
tracks_on_change_inputs
=
tracks_on_change_inputs
self
.
tracks_on_change_inputs
=
tracks_on_change_inputs
self
.
__final__
=
{}
self
.
__final__
:
Dict
[
str
,
aesara_opt
.
Rewriter
]
=
{}
self
.
__cleanup__
=
{}
self
.
__cleanup__
:
Dict
[
str
,
aesara_opt
.
Rewriter
]
=
{}
def
register
(
self
,
name
,
obj
,
*
tags
,
final_opt
=
False
,
cleanup
=
False
,
**
kwargs
):
def
register
(
self
,
name
,
obj
,
*
tags
,
final_opt
=
False
,
cleanup
=
False
,
**
kwargs
):
if
final_opt
and
cleanup
:
if
final_opt
and
cleanup
:
...
...
aesara/tensor/basic_opt.py
浏览文件 @
0ce6eceb
差异被折叠。
点击展开。
aesara/tensor/nnet/basic.py
浏览文件 @
0ce6eceb
...
@@ -1849,16 +1849,6 @@ crossentropy_categorical_1hot = CrossentropyCategorical1Hot()
...
@@ -1849,16 +1849,6 @@ crossentropy_categorical_1hot = CrossentropyCategorical1Hot()
@register_specialize
(
"fast_compile"
)
@register_specialize
(
"fast_compile"
)
@optimizer
@optimizer
def
crossentropy_to_crossentropy_with_softmax_with_bias
(
fgraph
):
def
crossentropy_to_crossentropy_with_softmax_with_bias
(
fgraph
):
"""
This is a stabilization optimization.
Notes
-----
Not a local optimization because we are replacing outputs
from several nodes at once.
"""
def
search_make_one_sub
():
def
search_make_one_sub
():
for
node
in
fgraph
.
toposort
():
for
node
in
fgraph
.
toposort
():
if
node
.
op
==
crossentropy_categorical_1hot
:
if
node
.
op
==
crossentropy_categorical_1hot
:
...
@@ -1887,18 +1877,13 @@ def crossentropy_to_crossentropy_with_softmax_with_bias(fgraph):
...
@@ -1887,18 +1877,13 @@ def crossentropy_to_crossentropy_with_softmax_with_bias(fgraph):
@optimizer
@optimizer
def
crossentropy_to_crossentropy_with_softmax
(
fgraph
):
def
crossentropy_to_crossentropy_with_softmax
(
fgraph
):
"""
"""
This is a stabilization optimization that is more general than
This is a stabilization rewrite that is more general than
crossentropy_to_crossentropy_with_softmax_with_bias.
`crossentropy_to_crossentropy_with_softmax_with_bias`.
It must be executed after local_softmax_with_bias optimization in
specialize.
TODO : This is a stabilization optimization! How to make this more cleanly?
Notes
Notes
-----
-----
Not a local optimization because we are replacing outputs from several
It must be executed after `local_softmax_with_bias` during the
nodes at once
.
specialization passes
.
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论