提交 19f1566f authored 作者: Ricardo's avatar Ricardo 提交者: Thomas Wiecki

Remove `warn__identify_1pexp_bug` flag

上级 a5b7b68f
......@@ -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",
......
......@@ -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
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论