提交 a1a805c9 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Fix spurious warning from FusionOptimizer

上级 4730d0cb
...@@ -692,6 +692,11 @@ class FusionOptimizer(GraphRewriter): ...@@ -692,6 +692,11 @@ class FusionOptimizer(GraphRewriter):
fuseable_clients: FUSEABLE_MAPPING = defaultdict(list) fuseable_clients: FUSEABLE_MAPPING = defaultdict(list)
unfuseable_clients: UNFUSEABLE_MAPPING = defaultdict(set) unfuseable_clients: UNFUSEABLE_MAPPING = defaultdict(set)
for out, clients in fg.clients.items(): for out, clients in fg.clients.items():
# Old FunctionGraph nodes remain in the clients dictionary
# even after they are removed by rewrites
if not clients:
continue
out_maybe_fuseable = ( out_maybe_fuseable = (
out.owner out.owner
and isinstance(out.owner.op, Elemwise) and isinstance(out.owner.op, Elemwise)
......
import warnings
import numpy as np import numpy as np
import pytest import pytest
...@@ -36,6 +38,7 @@ from pytensor.tensor.math import ( ...@@ -36,6 +38,7 @@ from pytensor.tensor.math import (
invert, invert,
iround, iround,
log, log,
log1mexp,
log2, log2,
log10, log10,
mul, mul,
...@@ -1370,6 +1373,21 @@ class TestFusion: ...@@ -1370,6 +1373,21 @@ class TestFusion:
assert benchmark(rewrite_func) == 103 assert benchmark(rewrite_func) == 103
def test_no_warning_from_old_client(self):
# There used to be a warning issued when creating fuseable mapping
# for nodes that are no longer in the FunctionGraph
with warnings.catch_warnings():
warnings.simplefilter("error")
# The -2 integer array cannot be passed directly to the C method
# of log1mexp as that can only handle floats. There is a rewrite
# that casts it to a float, but the FunctionGraph client retains
# the original log1mexp of the integer input, which caused
# a misleading warning for non C implementation in the FusionRewrite
assert np.isclose(
log1mexp(np.array(-2, dtype="int64")).eval(),
np.log(1 - np.exp(-2)),
)
class TimesN(aes.basic.UnaryScalarOp): class TimesN(aes.basic.UnaryScalarOp):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论