Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
29b1ff7b
提交
29b1ff7b
authored
2月 26, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
5月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor updates-related code in aesara.compile.function.types
上级
a22da800
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
22 行删除
+31
-22
types.py
aesara/compile/function/types.py
+31
-22
没有找到文件。
aesara/compile/function/types.py
浏览文件 @
29b1ff7b
...
...
@@ -183,12 +183,14 @@ def std_fgraph(
update_mapping
[
out_idx
]
=
idx
out_idx
+=
1
if
fgraph
:
if
fgraph
.
update_mapping
is
None
:
fgraph
.
update_mapping
=
update_mapping
for
update
in
updates
:
fgraph
.
add_output
(
update
,
reason
=
"std_fgraph"
)
else
:
found_updates
=
[]
if
fgraph
and
fgraph
.
update_mapping
is
None
:
fgraph
.
update_mapping
=
update_mapping
for
update
in
updates
:
fgraph
.
add_output
(
update
,
reason
=
"std_fgraph"
)
found_updates
.
extend
(
map
(
SymbolicOutput
,
updates
))
elif
fgraph
is
None
:
input_vars
=
[]
# If one of the inputs is non-atomic (i.e. has a non-`None` `Variable.owner`),
...
...
@@ -209,7 +211,7 @@ def std_fgraph(
clone
=
clone
,
)
additional_outputs
=
list
(
map
(
SymbolicOutput
,
updates
))
found_updates
.
extend
(
map
(
SymbolicOutput
,
updates
))
for
node
in
fgraph
.
apply_nodes
:
if
node
.
op
.
destroy_map
:
...
...
@@ -235,7 +237,7 @@ def std_fgraph(
for
feature
in
features
:
fgraph
.
attach_feature
(
feature
())
return
fgraph
,
additional_output
s
return
fgraph
,
found_update
s
class
AliasedMemoryError
(
Exception
):
...
...
@@ -675,7 +677,11 @@ class Function:
# Re initialize Outs and swap update and variable in Ins
# By doing this, we can pass FunctionMaker.check_unused_inputs()
outs
=
list
(
map
(
SymbolicOutput
,
fg_cpy
.
outputs
[:
len
(
maker
.
outputs
)]))
if
delete_updates
:
outs
=
list
(
map
(
SymbolicOutput
,
fg_cpy
.
outputs
[:
len
(
maker
.
outputs
)]))
else
:
outs
=
list
(
map
(
SymbolicOutput
,
fg_cpy
.
outputs
))
for
out_ori
,
out_cpy
in
zip
(
maker
.
outputs
,
outs
):
out_cpy
.
borrow
=
out_ori
.
borrow
...
...
@@ -712,14 +718,17 @@ class Function:
fg_cpy
.
replace
(
in_v
,
swap_sv
,
reason
=
"Swap SV"
)
# Delete update if needed
update_i
=
len
(
outs
)
for
i
,
in_var
in
zip
(
ins
,
fg_cpy
.
inputs
):
i
.
variable
=
in_var
if
not
delete_updates
and
i
.
update
is
not
None
:
i
.
update
=
fg_cpy
.
outputs
[
update_i
]
update_i
+=
1
rev_update_mapping
=
{
v
:
k
for
k
,
v
in
fg_cpy
.
update_mapping
.
items
()}
for
n
,
(
inp
,
in_var
)
in
enumerate
(
zip
(
ins
,
fg_cpy
.
inputs
)
):
i
np
.
variable
=
in_var
if
not
delete_updates
and
i
np
.
update
is
not
None
:
out_idx
=
rev_update_mapping
[
n
]
inp
.
update
=
fg_cpy
.
outputs
[
out_idx
]
else
:
i
.
update
=
None
inp
.
update
=
None
if
delete_updates
:
fg_cpy
.
update_mapping
=
{}
# Construct new storage_map that map new variable to old storage,
# so that the ensuing function shares storage with the original one
...
...
@@ -1518,7 +1527,7 @@ class FunctionMaker:
indices
=
[[
input
,
None
,
[
input
]]
for
input
in
inputs
]
fgraph
,
additional_output
s
=
std_fgraph
(
fgraph
,
found_update
s
=
std_fgraph
(
inputs
,
outputs
,
accept_inplace
,
fgraph
=
fgraph
)
...
...
@@ -1531,16 +1540,16 @@ class FunctionMaker:
if
not
no_fgraph_prep
:
self
.
prepare_fgraph
(
inputs
,
outputs
,
additional_output
s
,
fgraph
,
optimizer
,
linker
,
profile
inputs
,
outputs
,
found_update
s
,
fgraph
,
optimizer
,
linker
,
profile
)
# the 'no_borrow' outputs are the ones for which that we can't
# return the internal storage pointer.
assert
len
(
fgraph
.
outputs
)
==
len
(
outputs
+
additional_outputs
)
assert
len
(
fgraph
.
outputs
)
==
len
(
outputs
+
found_updates
)
# The 'no_borrow' outputs are the ones for which that we can't
# return the internal storage pointer.
no_borrow
=
[
output
for
output
,
spec
in
zip
(
fgraph
.
outputs
,
outputs
+
additional_output
s
)
for
output
,
spec
in
zip
(
fgraph
.
outputs
,
outputs
+
found_update
s
)
if
not
spec
.
borrow
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论