Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
316cfd1d
提交
316cfd1d
authored
10月 11, 2022
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
2月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Disable invalid inplace logic for multiple-output Composites
上级
390a8d67
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
2 行删除
+39
-2
elemwise.py
pytensor/tensor/rewriting/elemwise.py
+10
-2
test_elemwise.py
tests/tensor/rewriting/test_elemwise.py
+29
-0
没有找到文件。
pytensor/tensor/rewriting/elemwise.py
浏览文件 @
316cfd1d
...
@@ -59,6 +59,14 @@ class InplaceElemwiseOptimizer(GraphRewriter):
...
@@ -59,6 +59,14 @@ class InplaceElemwiseOptimizer(GraphRewriter):
for
n
in
sorted
(
ndim
.
keys
()):
for
n
in
sorted
(
ndim
.
keys
()):
print
(
blanc
,
n
,
ndim
[
n
],
file
=
stream
)
print
(
blanc
,
n
,
ndim
[
n
],
file
=
stream
)
def
candidate_input_idxs
(
self
,
node
):
if
isinstance
(
node
.
op
.
scalar_op
,
aes
.
Composite
)
and
len
(
node
.
outputs
)
>
1
:
# TODO: Implement specialized InplaceCompositeOptimizer with logic
# needed to correctly assign inplace for multi-output Composites
return
[]
else
:
return
range
(
len
(
node
.
outputs
))
def
apply
(
self
,
fgraph
):
def
apply
(
self
,
fgraph
):
r"""
r"""
...
@@ -149,7 +157,7 @@ class InplaceElemwiseOptimizer(GraphRewriter):
...
@@ -149,7 +157,7 @@ class InplaceElemwiseOptimizer(GraphRewriter):
baseline
=
op
.
inplace_pattern
baseline
=
op
.
inplace_pattern
candidate_outputs
=
[
candidate_outputs
=
[
i
for
i
in
range
(
len
(
node
.
outputs
)
)
if
i
not
in
baseline
i
for
i
in
self
.
candidate_input_idxs
(
node
)
if
i
not
in
baseline
]
]
# node inputs that are Constant, already destroyed,
# node inputs that are Constant, already destroyed,
# or fgraph protected inputs and fgraph outputs can't be used as
# or fgraph protected inputs and fgraph outputs can't be used as
...
@@ -167,7 +175,7 @@ class InplaceElemwiseOptimizer(GraphRewriter):
...
@@ -167,7 +175,7 @@ class InplaceElemwiseOptimizer(GraphRewriter):
]
]
else
:
else
:
baseline
=
[]
baseline
=
[]
candidate_outputs
=
list
(
range
(
len
(
node
.
outputs
))
)
candidate_outputs
=
self
.
candidate_input_idxs
(
node
)
# node inputs that are Constant, already destroyed,
# node inputs that are Constant, already destroyed,
# fgraph protected inputs and fgraph outputs can't be used as inplace
# fgraph protected inputs and fgraph outputs can't be used as inplace
# target.
# target.
...
...
tests/tensor/rewriting/test_elemwise.py
浏览文件 @
316cfd1d
...
@@ -4,6 +4,7 @@ import numpy as np
...
@@ -4,6 +4,7 @@ import numpy as np
import
pytest
import
pytest
import
pytensor
import
pytensor
from
pytensor
import
In
from
pytensor
import
scalar
as
aes
from
pytensor
import
scalar
as
aes
from
pytensor
import
shared
from
pytensor
import
shared
from
pytensor
import
tensor
as
at
from
pytensor
import
tensor
as
at
...
@@ -1024,6 +1025,34 @@ class TestFusion:
...
@@ -1024,6 +1025,34 @@ class TestFusion:
np
.
random
.
random
((
5
,
5
)),
np
.
random
.
random
((
5
,
5
)),
np
.
random
.
random
((
5
,
5
))
np
.
random
.
random
((
5
,
5
)),
np
.
random
.
random
((
5
,
5
)),
np
.
random
.
random
((
5
,
5
))
)
)
def
test_fusion_multiout_inplace
(
self
):
x
=
vector
(
"x"
)
# Create Composite where inplacing the first non-constant output would corrupt the second output
xs
=
aes
.
float64
(
"xs"
)
outs
=
(
Elemwise
(
Composite
([
xs
],
[
xs
+
1
,
aes
.
cos
(
xs
+
1
)
+
xs
]))
.
make_node
(
x
)
.
outputs
)
f
=
pytensor
.
function
(
[
In
(
x
,
mutable
=
True
)],
outs
,
mode
=
self
.
mode
.
including
(
"inplace"
),
)
(
composite_node
,)
=
f
.
maker
.
fgraph
.
apply_nodes
# Destroy map must be None or the last toposorted output
destroy_map
=
composite_node
.
op
.
destroy_map
assert
(
destroy_map
==
{})
or
(
destroy_map
==
{
1
:
[
composite_node
.
inputs
.
index
(
x
)]}
)
res
=
f
([
0
,
1
,
2
])
assert
np
.
allclose
(
res
[
0
],
[
1
,
2
,
3
])
assert
np
.
allclose
(
res
[
1
],
np
.
cos
([
1
,
2
,
3
])
+
np
.
array
([
0
,
1
,
2
]))
@pytest.mark.skipif
(
not
config
.
cxx
,
reason
=
"No cxx compiler"
)
@pytest.mark.skipif
(
not
config
.
cxx
,
reason
=
"No cxx compiler"
)
def
test_no_c_code
(
self
):
def
test_no_c_code
(
self
):
r"""Make sure we avoid fusions for `Op`\s without C code implementations."""
r"""Make sure we avoid fusions for `Op`\s without C code implementations."""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论