Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
70694957
提交
70694957
authored
1月 11, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
1月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused _find_bad_optimizations* functions
上级
8cbd9840
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
1 行增加
和
114 行删除
+1
-114
debugmode.py
aesara/compile/debugmode.py
+1
-114
没有找到文件。
aesara/compile/debugmode.py
浏览文件 @
70694957
...
@@ -695,7 +695,7 @@ def _lessbroken_deepcopy(a):
...
@@ -695,7 +695,7 @@ def _lessbroken_deepcopy(a):
return
rval
return
rval
def
_find_bad_optimizations
0
(
order
,
reasons
,
r_vals
):
def
_find_bad_optimizations
(
order
,
reasons
,
r_vals
):
"""
"""
Use a simple algorithm to find broken optimizations.
Use a simple algorithm to find broken optimizations.
...
@@ -736,119 +736,6 @@ def _find_bad_optimizations0(order, reasons, r_vals):
...
@@ -736,119 +736,6 @@ def _find_bad_optimizations0(order, reasons, r_vals):
)
)
def
_find_bad_optimizations1
(
order
,
reasons
,
r_vals
):
# iterate over variables looking for values that don't match the
# values of the variables they replaced. This is the sign of a
# broken optimization.
# identify sets of variables that are supposed to be equivalent
equivalence_sets
=
{}
program_position
=
{}
# node -> order idx
for
i
,
node
in
enumerate
(
order
):
program_position
[
node
]
=
i
for
new_r
in
node
.
outputs
:
equivalence_sets
.
setdefault
(
new_r
,
{
new_r
})
for
reason
,
r
,
old_graph_str
,
new_graph_str
in
reasons
[
new_r
]:
equivalence_sets
[
new_r
]
.
update
(
equivalence_sets
.
setdefault
(
r
,
{
r
}))
for
er
in
equivalence_sets
[
r
]:
equivalence_sets
[
er
]
=
equivalence_sets
[
new_r
]
# identify equivalence sets that are broken
equivalence_sets_broken
=
{}
# id(set) -> Bool
there_is_a_problem
=
False
for
r
,
r_equiv
in
equivalence_sets
.
items
():
if
id
(
r_equiv
)
not
in
equivalence_sets_broken
:
equivalence_sets_broken
[
id
(
r_equiv
)]
=
False
# loop over the variables in the set comparing them to be
# equal enough
re0
=
None
for
re
in
r_equiv
:
if
re0
:
new_r_val
=
r_vals
[
re
]
r_val
=
r_vals
[
re0
]
assert
re
.
type
==
re0
.
type
if
not
re
.
type
.
values_eq_approx
(
r_val
,
new_r_val
):
equivalence_sets_broken
[
id
(
r_equiv
)]
=
True
there_is_a_problem
=
True
re0
=
re
if
there_is_a_problem
:
# which broken equivalence set has the earliest-occurring element?
first_broken_set
=
None
for
i
,
node
in
enumerate
(
order
):
for
r
in
node
.
outputs
:
r_equiv
=
equivalence_sets
[
r
]
if
equivalence_sets_broken
[
id
(
r_equiv
)]:
first_broken_set
=
r_equiv
# TODO finish this to produce good diagnostic information
print
(
first_broken_set
)
raise
Exception
(
"broken"
)
def
_find_bad_optimizations2
(
order
,
reasons
,
r_vals
):
"""
Use a simple algorithm to find broken optimizations.
This algorithm is simple to understand, but sometimes when there's
a problem it identifies the wrong optimization as the culprit.
The problem stems from the fact that results are not evaluated in
chronological order (looking at when they were introduced to the
graph).
"""
checked_variables
=
set
()
def
check_variable_norec
(
new_r
):
"""
Verify that `r` has the same value as the results it replaces.
"""
for
reason
,
r
,
old_graph_str
,
new_graph_str
in
reasons
[
new_r
]:
new_r_val
=
r_vals
[
new_r
]
r_val
=
r_vals
[
r
]
if
(
r
.
type
!=
new_r
.
type
)
or
(
not
r
.
type
.
values_eq_approx
(
r_val
,
new_r_val
)
):
raise
BadOptimization
(
old_r
=
r
,
new_r
=
new_r
,
old_r_val
=
r_val
,
new_r_val
=
new_r_val
,
reason
=
reason
,
old_graph
=
old_graph_str
,
new_graph
=
new_graph_str
,
)
def
check_variable
(
r
):
if
r
in
checked_variables
:
return
checked_variables
.
add
(
r
)
# (recursively) first check all the variables that could make
# r look bad:
list_of_vars
=
[
old_r
for
(
reason
,
old_r
,
olds
,
news
)
in
reasons
[
r
]]
if
None
is
not
r
.
owner
:
list_of_vars
+=
r
.
owner
.
inputs
for
var_that_could_make_r_look_bad
in
list_of_vars
:
check_variable
(
var_that_could_make_r_look_bad
)
check_variable_norec
(
r
)
# iterate over variables looking for values that don't match the
# values of the variables they replaced. This is the sign of a
# broken optimization.
for
i
,
node
in
enumerate
(
order
):
for
new_r
in
node
.
outputs
:
check_variable
(
new_r
)
_find_bad_optimizations
=
_find_bad_optimizations0
def
_get_preallocated_maps
(
def
_get_preallocated_maps
(
node
,
node
,
thunk
,
thunk
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论