Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
19f1566f
提交
19f1566f
authored
8月 18, 2021
作者:
Ricardo
提交者:
Thomas Wiecki
8月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove `warn__identify_1pexp_bug` flag
上级
a5b7b68f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
141 行增加
和
174 行删除
+141
-174
configdefaults.py
aesara/configdefaults.py
+0
-8
math_opt.py
aesara/tensor/math_opt.py
+0
-13
test_math_opt.py
tests/tensor/test_math_opt.py
+141
-153
没有找到文件。
aesara/configdefaults.py
浏览文件 @
19f1566f
...
...
@@ -1436,14 +1436,6 @@ def add_deprecated_configvars():
in_c_key
=
False
,
)
# TODO: remove?
config
.
add
(
"warn__identify_1pexp_bug"
,
"Warn if Aesara versions prior to 7987b51 (2011-12-18) could have "
"yielded a wrong result due to a bug in the is_1pexp function"
,
BoolParam
(
_warn_default
(
"0.4.1"
)),
in_c_key
=
False
,
)
# TODO: this setting is not used anywhere
config
.
add
(
"gpu__local_elemwise_fusion"
,
...
...
aesara/tensor/math_opt.py
浏览文件 @
19f1566f
...
...
@@ -3068,19 +3068,6 @@ def is_1pexp(t, only_process_constants=True):
scal_sum
=
scal_sum
+
s
if
np
.
allclose
(
scal_sum
,
1
):
return
False
,
maybe_exp
.
owner
.
inputs
[
0
]
# Before 7987b51 there used to be a bug where *any* constant
# was considered as if it was equal to 1, and thus this
# function would incorrectly identify it as (1 + exp(x)).
if
config
.
warn__identify_1pexp_bug
:
warnings
.
warn
(
"Although your current code is fine, please note that "
"Aesara versions prior to 0.5 (more specifically, "
"prior to commit 7987b51 on 2011-12-18) may have "
"yielded an incorrect result. To remove this warning, "
"either set the `warn__identify_1pexp_bug` config "
"option to False, or `warn__ignore_bug_before` to at "
"least '0.4.1'."
)
return
None
...
...
tests/tensor/test_math_opt.py
浏览文件 @
19f1566f
...
...
@@ -4074,140 +4074,133 @@ class TestSigmoidOpts:
x
=
vector
()
data
=
np
.
random
.
random
((
54
))
.
astype
(
config
.
floatX
)
backup
=
config
.
warn__identify_1pexp_bug
config
.
warn__identify_1pexp_bug
=
False
try
:
# tests exp_over_1_plus_exp
f
=
aesara
.
function
([
x
],
exp
(
x
)
/
(
1
+
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
exp
(
x
)
/
(
2
+
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
exp
(
x
)
/
(
1
-
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
exp
(
x
+
1
)
/
(
1
+
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
# tests inv_1_plus_exp
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
1.0
)
/
(
1
+
exp
(
-
x
)),
mode
=
m
)
# todo: solve issue #4589 first
# assert check_stack_trace(f, ops_to_check=sigmoid)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
1.0
)
/
(
2
+
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
1.0
)
/
(
1
-
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
1.1
)
/
(
1
+
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
# tests inv_1_plus_exp with neg
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
-
1.0
)
/
(
1
+
exp
(
-
x
)),
mode
=
m
)
# todo: solve issue #4589 first
# assert check_stack_trace(
# f, ops_to_check=[sigmoid, neg_inplace])
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
sigmoid
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
-
1.0
)
/
(
1
-
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
-
1.0
)
/
(
2
+
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
-
1.1
)
/
(
1
+
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
inplace
.
neg_inplace
,
]
f
(
data
)
# tests double inv_1_plus_exp with neg
# (-1)(exp(x)) / (1+exp(x))(1+exp(-x))
# = (-1)/(1+exp(-x)) * exp(x)/(1+exp(x))
# = - (sigm(x) * sigm(x))
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
1
+
exp
(
-
x
))),
mode
=
m
,
)
# todo: solve issue #4589 first
# assert check_stack_trace(f, ops_to_check=[sigmoid, mul])
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
sigmoid
,
mul
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.1
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
1
+
exp
(
-
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
2
+
exp
(
x
))
*
(
1
+
exp
(
-
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
2
+
exp
(
-
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
1
+
exp
(
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
2
+
exp
(
-
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
# tests exp_over_1_plus_exp
f
=
aesara
.
function
([
x
],
exp
(
x
)
/
(
1
+
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
exp
(
x
)
/
(
2
+
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
exp
(
x
)
/
(
1
-
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
exp
(
x
+
1
)
/
(
1
+
exp
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
finally
:
# Restore config option.
config
.
warn__identify_1pexp_bug
=
backup
# tests inv_1_plus_exp
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
1.0
)
/
(
1
+
exp
(
-
x
)),
mode
=
m
)
# todo: solve issue #4589 first
# assert check_stack_trace(f, ops_to_check=sigmoid)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
1.0
)
/
(
2
+
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
1.0
)
/
(
1
-
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
1.1
)
/
(
1
+
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
]
f
(
data
)
# tests inv_1_plus_exp with neg
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
-
1.0
)
/
(
1
+
exp
(
-
x
)),
mode
=
m
)
# todo: solve issue #4589 first
# assert check_stack_trace(
# f, ops_to_check=[sigmoid, neg_inplace])
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
sigmoid
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
-
1.0
)
/
(
1
-
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
-
1.0
)
/
(
2
+
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
([
x
],
aet
.
fill
(
x
,
-
1.1
)
/
(
1
+
exp
(
-
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
inplace
.
neg_inplace
,
]
f
(
data
)
# tests double inv_1_plus_exp with neg
# (-1)(exp(x)) / (1+exp(x))(1+exp(-x))
# = (-1)/(1+exp(-x)) * exp(x)/(1+exp(x))
# = - (sigm(x) * sigm(x))
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
1
+
exp
(
-
x
))),
mode
=
m
,
)
# todo: solve issue #4589 first
# assert check_stack_trace(f, ops_to_check=[sigmoid, mul])
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
sigmoid
,
mul
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.1
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
1
+
exp
(
-
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
2
+
exp
(
x
))
*
(
1
+
exp
(
-
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
2
+
exp
(
-
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
1
+
exp
(
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
f
=
aesara
.
function
(
[
x
],
(
aet
.
fill
(
x
,
-
1.0
)
*
exp
(
x
))
/
((
1
+
exp
(
x
))
*
(
2
+
exp
(
-
x
))),
mode
=
m
,
)
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
!=
[
sigmoid
,
mul
,
inplace
.
neg_inplace
,
]
f
(
data
)
def
test_local_1msigmoid
(
self
):
m
=
self
.
get_mode
(
excluding
=
[
"fusion"
,
"inplace"
])
...
...
@@ -4465,26 +4458,21 @@ class TestSigmoidUtils:
]
def
test_is_1pexp
(
self
):
backup
=
config
.
warn__identify_1pexp_bug
config
.
warn__identify_1pexp_bug
=
False
try
:
x
=
vector
(
"x"
)
exp_op
=
exp
assert
is_1pexp
(
1
+
exp_op
(
x
),
False
)
==
(
False
,
x
)
assert
is_1pexp
(
exp_op
(
x
)
+
1
,
False
)
==
(
False
,
x
)
for
neg_
,
exp_arg
in
map
(
lambda
x
:
is_1pexp
(
x
,
only_process_constants
=
False
),
[(
1
+
exp_op
(
-
x
)),
(
exp_op
(
-
x
)
+
1
)],
):
assert
not
neg_
and
is_same_graph
(
exp_arg
,
-
x
)
assert
is_1pexp
(
1
-
exp_op
(
x
),
False
)
is
None
assert
is_1pexp
(
2
+
exp_op
(
x
),
False
)
is
None
assert
is_1pexp
(
exp_op
(
x
)
+
2
,
False
)
is
None
assert
is_1pexp
(
exp_op
(
x
)
-
1
,
False
)
is
None
assert
is_1pexp
(
-
1
+
exp_op
(
x
),
False
)
is
None
assert
is_1pexp
(
1
+
2
*
exp_op
(
x
),
False
)
is
None
finally
:
config
.
warn__identify_1pexp_bug
=
backup
x
=
vector
(
"x"
)
exp_op
=
exp
assert
is_1pexp
(
1
+
exp_op
(
x
),
False
)
==
(
False
,
x
)
assert
is_1pexp
(
exp_op
(
x
)
+
1
,
False
)
==
(
False
,
x
)
for
neg_
,
exp_arg
in
map
(
lambda
x
:
is_1pexp
(
x
,
only_process_constants
=
False
),
[(
1
+
exp_op
(
-
x
)),
(
exp_op
(
-
x
)
+
1
)],
):
assert
not
neg_
and
is_same_graph
(
exp_arg
,
-
x
)
assert
is_1pexp
(
1
-
exp_op
(
x
),
False
)
is
None
assert
is_1pexp
(
2
+
exp_op
(
x
),
False
)
is
None
assert
is_1pexp
(
exp_op
(
x
)
+
2
,
False
)
is
None
assert
is_1pexp
(
exp_op
(
x
)
-
1
,
False
)
is
None
assert
is_1pexp
(
-
1
+
exp_op
(
x
),
False
)
is
None
assert
is_1pexp
(
1
+
2
*
exp_op
(
x
),
False
)
is
None
def
test_log1mexp_stabilization
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论