Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
27d2bfe3
提交
27d2bfe3
authored
2月 26, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
5月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make NoOutputFromInplace take arbitrary collections
上级
beb510e6
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
21 行增加
和
9 行删除
+21
-9
features.py
aesara/graph/features.py
+11
-4
op.py
aesara/scan/op.py
+1
-1
test_mode.py
tests/compile/test_mode.py
+9
-4
没有找到文件。
aesara/graph/features.py
浏览文件 @
27d2bfe3
...
...
@@ -742,15 +742,20 @@ class PreserveVariableAttributes(Feature):
class
NoOutputFromInplace
(
Feature
):
"""Prevent `FunctionGraph` outputs within a range from being altered in-place."""
def
__init__
(
self
,
first_output_idx
=
0
,
last_output_idx
=
None
):
self
.
first_idx
=
first_output_idx
self
.
last_idx
=
last_output_idx
def
__init__
(
self
,
protected_out_ids
):
self
.
protected_out_ids
=
tuple
(
protected_out_ids
)
def
on_attach
(
self
,
fgraph
):
if
hasattr
(
fgraph
,
"_no_output_from_inplace"
):
raise
AlreadyThere
(
f
"InnerGraphWatcher is already attached to {fgraph}."
)
fgraph
.
_no_output_from_inplace
=
self
def
validate
(
self
,
fgraph
):
if
not
hasattr
(
fgraph
,
"destroyers"
):
return
True
for
out
in
fgraph
.
outputs
[
self
.
first_idx
:
self
.
last_idx
]
:
for
out
in
tuple
(
fgraph
.
outputs
[
i
]
for
i
in
self
.
protected_out_ids
)
:
node
=
out
.
owner
...
...
@@ -768,3 +773,5 @@ class NoOutputFromInplace(Feature):
f
"operations. This has prevented the output {out} from "
"being computed by modifying another variable in-place."
)
return
True
aesara/scan/op.py
浏览文件 @
27d2bfe3
...
...
@@ -877,7 +877,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
mitsot_start
=
info
.
n_mit_mot_outs
-
len
(
self
.
preallocated_mitmot_outs
)
nitsot_end
=
mitsot_start
+
info
.
n_mit_sot
+
info
.
n_sit_sot
+
info
.
n_nit_sot
features
.
append
(
NoOutputFromInplace
(
mitsot_start
,
nitsot_end
))
features
.
append
(
NoOutputFromInplace
(
range
(
mitsot_start
,
nitsot_end
)
))
self
.
fgraph
=
FunctionGraph
(
inputs
,
...
...
tests/compile/test_mode.py
浏览文件 @
27d2bfe3
...
...
@@ -15,25 +15,30 @@ def test_Mode_basic():
assert
str
(
mode
)
.
startswith
(
"Mode(linker=py, optimizer=OptimizationQuery"
)
def
test_
no_output_from_im
place
():
def
test_
NoOutputFromIn
place
():
x
=
matrix
()
y
=
matrix
()
a
=
dot
(
x
,
y
)
b
=
tanh
(
a
)
c
=
tanh
(
dot
(
2
*
x
,
y
))
# Ensure that the elemwise op that produces the output is inplace when
# using a mode that does not include the optimization
fct_no_opt
=
function
([
x
,
y
],
b
,
mode
=
"FAST_RUN"
)
fct_no_opt
=
function
([
x
,
y
],
[
b
,
c
]
,
mode
=
"FAST_RUN"
)
op
=
fct_no_opt
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
op
assert
op
.
destroy_map
and
0
in
op
.
destroy_map
op
=
fct_no_opt
.
maker
.
fgraph
.
outputs
[
1
]
.
owner
.
op
assert
op
.
destroy_map
and
0
in
op
.
destroy_map
# Ensure that the elemwise op that produces the output is not inplace when
# using a mode that includes the optimization
opt
=
AddFeatureOptimizer
(
NoOutputFromInplace
())
opt
=
AddFeatureOptimizer
(
NoOutputFromInplace
(
[
1
]
))
mode_opt
=
Mode
(
linker
=
"py"
,
optimizer
=
"fast_run"
)
.
register
((
opt
,
49.9
))
fct_opt
=
function
([
x
,
y
],
b
,
mode
=
mode_opt
)
fct_opt
=
function
([
x
,
y
],
[
b
,
c
]
,
mode
=
mode_opt
)
op
=
fct_opt
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
op
assert
op
.
destroy_map
and
0
in
op
.
destroy_map
op
=
fct_opt
.
maker
.
fgraph
.
outputs
[
1
]
.
owner
.
op
assert
not
op
.
destroy_map
or
0
not
in
op
.
destroy_map
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论