Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fe5865ef
提交
fe5865ef
authored
12月 05, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove assert in local_useless_alloc
Rewrite was already tagged as "shape_unsafe"
上级
c855a6d8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
19 行删除
+26
-19
basic.py
pytensor/tensor/rewriting/basic.py
+3
-11
test_basic.py
tests/tensor/rewriting/test_basic.py
+23
-8
没有找到文件。
pytensor/tensor/rewriting/basic.py
浏览文件 @
fe5865ef
...
@@ -67,9 +67,7 @@ from pytensor.tensor.basic import (
...
@@ -67,9 +67,7 @@ from pytensor.tensor.basic import (
from
pytensor.tensor.elemwise
import
DimShuffle
,
Elemwise
from
pytensor.tensor.elemwise
import
DimShuffle
,
Elemwise
from
pytensor.tensor.exceptions
import
NotScalarConstantError
from
pytensor.tensor.exceptions
import
NotScalarConstantError
from
pytensor.tensor.extra_ops
import
broadcast_arrays
from
pytensor.tensor.extra_ops
import
broadcast_arrays
from
pytensor.tensor.math
import
Sum
,
add
from
pytensor.tensor.math
import
Sum
,
add
,
eq
from
pytensor.tensor.math
import
all
as
at_all
from
pytensor.tensor.math
import
eq
from
pytensor.tensor.shape
import
Shape_i
,
shape_padleft
from
pytensor.tensor.shape
import
Shape_i
,
shape_padleft
from
pytensor.tensor.sort
import
TopKOp
from
pytensor.tensor.sort
import
TopKOp
from
pytensor.tensor.type
import
DenseTensorType
,
TensorType
from
pytensor.tensor.type
import
DenseTensorType
,
TensorType
...
@@ -266,6 +264,7 @@ def local_elemwise_alloc(fgraph, node):
...
@@ -266,6 +264,7 @@ def local_elemwise_alloc(fgraph, node):
introduces them as a canonicalization of `Alloc`'s with leading
introduces them as a canonicalization of `Alloc`'s with leading
broadcastable dimensions.
broadcastable dimensions.
"""
"""
# This is handled by local_alloc_unary
if
len
(
node
.
inputs
)
==
1
:
if
len
(
node
.
inputs
)
==
1
:
return
None
return
None
...
@@ -465,14 +464,7 @@ def local_useless_alloc(fgraph, node):
...
@@ -465,14 +464,7 @@ def local_useless_alloc(fgraph, node):
inp
.
type
.
dtype
==
output
.
type
.
dtype
inp
.
type
.
dtype
==
output
.
type
.
dtype
and
inp
.
type
.
broadcastable
==
output
.
type
.
broadcastable
and
inp
.
type
.
broadcastable
==
output
.
type
.
broadcastable
):
):
if
inp
.
ndim
==
0
:
return
[
inp
]
return
[
inp
]
else
:
return
[
Assert
(
"Shapes must be equal"
)(
inp
,
at_all
(
eq
(
inp
.
shape
,
node
.
inputs
[
1
:]))
)
]
@register_specialize
@register_specialize
...
...
tests/tensor/rewriting/test_basic.py
浏览文件 @
fe5865ef
...
@@ -272,21 +272,36 @@ class TestLocalCanonicalizeAlloc:
...
@@ -272,21 +272,36 @@ class TestLocalCanonicalizeAlloc:
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
self
.
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
def
test_inconsistent_shared
(
self
):
@pytest.mark.parametrize
(
"shape_unsafe"
,
(
True
,
False
))
def
test_inconsistent_shared
(
self
,
shape_unsafe
):
# These shapes don't match!
# These shapes don't match!
x
=
shared
(
self
.
rng
.
standard_normal
((
3
,
7
)))
x
=
shared
(
self
.
rng
.
standard_normal
((
3
,
7
)))
a
=
at
.
alloc
(
x
,
6
,
7
)
a
=
at
.
alloc
(
x
,
6
,
7
)
assert
a
.
owner
and
isinstance
(
a
.
owner
.
op
,
Alloc
)
assert
a
.
owner
and
isinstance
(
a
.
owner
.
op
,
Alloc
)
f
=
function
([],
a
,
mode
=
rewrite_mode
)
mode
=
rewrite_mode
if
shape_unsafe
else
rewrite_mode
.
excluding
(
"shape_unsafe"
)
f
=
function
([],
a
,
mode
=
mode
)
# The rewrite should then be applied, and remove Alloc
has_alloc
=
any
(
assert
not
any
(
isinstance
(
node
.
op
,
Alloc
)
for
node
in
f
.
maker
.
fgraph
.
toposort
())
isinstance
(
node
.
op
,
Alloc
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()
assert
any
(
isinstance
(
node
.
op
,
Assert
)
for
node
in
f
.
maker
.
fgraph
.
toposort
())
)
if
shape_unsafe
:
with
pytest
.
raises
(
AssertionError
):
assert
not
has_alloc
f
()
# Error raised by SpecifyShape that is introduced due to static shape inference
with
pytest
.
raises
(
AssertionError
,
match
=
"SpecifyShape: dim 0 of input has shape 3, expected 6."
,
):
f
()
else
:
assert
has_alloc
# Error raised by Alloc Op
with
pytest
.
raises
(
ValueError
,
match
=
r"could not broadcast input array from shape \(3,7\) into shape \(6,7\)"
,
):
f
()
good_x_val
=
self
.
rng
.
standard_normal
((
6
,
7
))
good_x_val
=
self
.
rng
.
standard_normal
((
6
,
7
))
x
.
set_value
(
good_x_val
)
x
.
set_value
(
good_x_val
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论