提交 32ec7810 authored 作者: ricardoV94's avatar ricardoV94 提交者: Ricardo Vieira

Fail gracefully in unconditional_constant_fold if Op can't be evaluated at all

上级 0b4d684f
...@@ -1165,9 +1165,13 @@ def unconditional_constant_folding(fgraph, node): ...@@ -1165,9 +1165,13 @@ def unconditional_constant_folding(fgraph, node):
) )
required = thunk() required = thunk()
except NotImplementedError: except NotImplementedError:
# Not all Ops have a python implementation try:
thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[]) # Not all Ops have a python implementation
required = thunk() thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
required = thunk()
except NotImplementedError:
# And some Ops (like dummy Ops) can never be evaluated
return None
# A node whose inputs are all provided should always return successfully # A node whose inputs are all provided should always return successfully
assert not required assert not required
......
...@@ -784,10 +784,11 @@ class TestConstantFolding: ...@@ -784,10 +784,11 @@ class TestConstantFolding:
fg = FunctionGraph(outputs=[out], clone=False) fg = FunctionGraph(outputs=[out], clone=False)
# Default constant_folding will raise # Default constant_folding will raise
with pytest.raises(NotImplementedError): topo_constant_folding.apply(fg)
topo_constant_folding.apply(fg) assert not isinstance(fg.outputs[0], Constant)
assert isinstance(fg.outputs[0].owner.op, OpNoPerform)
# Unconditional constant folding will be silent # Default and Unconditional constant folding will be silent
topo_unconditional_constant_folding.apply(fg) topo_unconditional_constant_folding.apply(fg)
assert not isinstance(fg.outputs[0], Constant) assert not isinstance(fg.outputs[0], Constant)
assert isinstance(fg.outputs[0].owner.op, OpNoPerform) assert isinstance(fg.outputs[0].owner.op, OpNoPerform)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论