Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d039a055
提交
d039a055
authored
4月 13, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
4月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unnecessary cloning from push_out_seq_scan
上级
2d2f2979
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
26 行删除
+17
-26
opt.py
aesara/scan/opt.py
+17
-26
没有找到文件。
aesara/scan/opt.py
浏览文件 @
d039a055
...
@@ -410,12 +410,11 @@ def push_out_seq_scan(fgraph, node):
...
@@ -410,12 +410,11 @@ def push_out_seq_scan(fgraph, node):
if
not
isinstance
(
node
.
op
,
Scan
):
if
not
isinstance
(
node
.
op
,
Scan
):
return
False
return
False
# this flag tells if there was any change during the last iterations
node_inputs
,
node_outputs
=
node
.
op
.
inputs
,
node
.
op
.
outputs
clean_inputs
,
clean_outputs
=
reconstruct_graph
(
node
.
op
.
inputs
,
node
.
op
.
outputs
)
local_fgraph_topo
=
io_toposort
(
clean_inputs
,
clean
_outputs
)
local_fgraph_topo
=
io_toposort
(
node_inputs
,
node
_outputs
)
local_fgraph_outs_set
=
set
(
clean
_outputs
)
local_fgraph_outs_set
=
set
(
node
_outputs
)
local_fgraph_outs_map
=
{
v
:
k
for
k
,
v
in
enumerate
(
clean
_outputs
)}
local_fgraph_outs_map
=
{
v
:
k
for
k
,
v
in
enumerate
(
node
_outputs
)}
to_remove_set
=
set
()
to_remove_set
=
set
()
to_replace_set
=
set
()
to_replace_set
=
set
()
...
@@ -433,12 +432,12 @@ def push_out_seq_scan(fgraph, node):
...
@@ -433,12 +432,12 @@ def push_out_seq_scan(fgraph, node):
op
=
node
.
op
op
=
node
.
op
# Construct the list of non_sequences to simplify a few things
# Construct the list of non_sequences to simplify a few things
inner_non_seqs
=
op
.
inner_non_seqs
(
clean
_inputs
)
inner_non_seqs
=
op
.
inner_non_seqs
(
node
_inputs
)
inner_non_seqs_set
=
set
(
inner_non_seqs
)
inner_non_seqs_set
=
set
(
inner_non_seqs
)
inner_non_seqs_map
=
{
v
:
k
for
k
,
v
in
enumerate
(
inner_non_seqs
)}
inner_non_seqs_map
=
{
v
:
k
for
k
,
v
in
enumerate
(
inner_non_seqs
)}
outer_non_seqs
=
op
.
outer_non_seqs
(
node
.
inputs
)
outer_non_seqs
=
op
.
outer_non_seqs
(
node
.
inputs
)
inner_seqs
=
op
.
inner_seqs
(
clean
_inputs
)
inner_seqs
=
op
.
inner_seqs
(
node
_inputs
)
inner_seqs_set
=
set
(
inner_seqs
)
inner_seqs_set
=
set
(
inner_seqs
)
inner_seqs_map
=
{
v
:
k
for
k
,
v
in
enumerate
(
inner_seqs
)}
inner_seqs_map
=
{
v
:
k
for
k
,
v
in
enumerate
(
inner_seqs
)}
...
@@ -467,26 +466,18 @@ def push_out_seq_scan(fgraph, node):
...
@@ -467,26 +466,18 @@ def push_out_seq_scan(fgraph, node):
for
x
in
nd
.
inputs
:
for
x
in
nd
.
inputs
:
if
x
in
inner_non_seqs_set
:
if
x
in
inner_non_seqs_set
:
_idx
=
inner_non_seqs_map
[
x
]
_idx
=
inner_non_seqs_map
[
x
]
outside_ins
.
append
(
outer_non_seqs
[
_idx
])
new_input
=
outer_non_seqs
[
_idx
]
elif
x
in
inner_seqs_set
:
elif
x
in
inner_seqs_set
:
outside_ins
.
append
(
outer_seqs
[
inner_seqs_map
[
x
]])
new_input
=
outer_seqs
[
inner_seqs_map
[
x
]]
depends_on_seqs
=
True
depends_on_seqs
=
True
elif
x
in
to_replace_set
:
elif
x
in
to_replace_set
:
outside_ins
.
append
(
replace_with_out
[
to_replace_map
[
x
]])
new_input
=
replace_with_out
[
to_replace_map
[
x
]]
depends_on_seqs
=
True
depends_on_seqs
=
True
elif
isinstance
(
x
,
Constant
):
outside_ins
.
append
(
x
.
clone
())
else
:
else
:
raise
Exception
(
assert
isinstance
(
x
,
Constant
)
(
new_input
=
x
"Error in the `scan_pushout_seq_"
"operations`. The optimization tries "
outside_ins
.
append
(
new_input
)
"to move some computation from scan "
"which is not allowed to move. Report "
"this on aesara-users list"
),
x
,
)
if
not
depends_on_seqs
:
if
not
depends_on_seqs
:
# Removing this node from the inner graph of scan
# Removing this node from the inner graph of scan
...
@@ -580,15 +571,15 @@ def push_out_seq_scan(fgraph, node):
...
@@ -580,15 +571,15 @@ def push_out_seq_scan(fgraph, node):
clean_to_replace
,
clean_replace_with_in
,
clean_replace_with_out
clean_to_replace
,
clean_replace_with_in
,
clean_replace_with_out
):
):
if
isinstance
(
repl_out
,
Constant
):
if
isinstance
(
repl_out
,
Constant
):
repl_in
=
repl_out
.
clone
()
repl_in
=
repl_out
else
:
else
:
nw_inner
.
append
(
repl_in
)
nw_inner
.
append
(
repl_in
)
nw_outer
.
append
(
repl_out
)
nw_outer
.
append
(
repl_out
)
givens
[
to_repl
]
=
repl_in
givens
[
to_repl
]
=
repl_in
op_outs
=
clone_replace
(
clean
_outputs
,
replace
=
givens
)
op_outs
=
clone_replace
(
node
_outputs
,
replace
=
givens
)
op_ins
=
nw_inner
+
clean
_inputs
op_ins
=
nw_inner
+
node
_inputs
# Reconstruct node
# Reconstruct node
nw_info
=
dataclasses
.
replace
(
op
.
info
,
n_seqs
=
op
.
info
.
n_seqs
+
len
(
nw_inner
))
nw_info
=
dataclasses
.
replace
(
op
.
info
,
n_seqs
=
op
.
info
.
n_seqs
+
len
(
nw_inner
))
...
@@ -621,7 +612,7 @@ def push_out_seq_scan(fgraph, node):
...
@@ -621,7 +612,7 @@ def push_out_seq_scan(fgraph, node):
if
out
in
local_fgraph_outs_set
:
if
out
in
local_fgraph_outs_set
:
x
=
node
.
outputs
[
local_fgraph_outs_map
[
out
]]
x
=
node
.
outputs
[
local_fgraph_outs_map
[
out
]]
_y
=
replace_with_out
[
idx
]
_y
=
replace_with_out
[
idx
]
ls
=
clean
_outputs
ls
=
node
_outputs
if
out
in
op
.
inner_mitsot_outs
(
ls
):
if
out
in
op
.
inner_mitsot_outs
(
ls
):
odx
=
op
.
inner_mitsot_outs
(
ls
)
.
index
(
out
)
odx
=
op
.
inner_mitsot_outs
(
ls
)
.
index
(
out
)
inp
=
op
.
outer_mitsot
(
node
.
inputs
)[
odx
]
inp
=
op
.
outer_mitsot
(
node
.
inputs
)[
odx
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论