提交 0900b662 authored 作者: abergeron's avatar abergeron

Merge pull request #4013 from Sentient07/issue-3573

Assert to never reintroduce Apply node in fgraph
......@@ -273,6 +273,8 @@ class ReplaceValidate(History, Validator):
if hasattr(fgraph, attr):
raise AlreadyThere("ReplaceValidate feature is already present"
" or in conflict with another plugin.")
self._nodes_removed = set()
self.fail_validate = False
History.on_attach(self, fgraph)
Validator.on_attach(self, fgraph)
self.unpickle(fgraph)
......@@ -289,6 +291,7 @@ class ReplaceValidate(History, Validator):
def on_detach(self, fgraph):
History.on_detach(self, fgraph)
Validator.on_detach(self, fgraph)
del self._nodes_removed
del fgraph.replace_validate
del fgraph.replace_all_validate
del fgraph.replace_all_validate_remove
......@@ -347,6 +350,7 @@ class ReplaceValidate(History, Validator):
"""
chk = fgraph.replace_all_validate(replacements, reason)
self._nodes_removed.update(remove)
for rm in remove:
if rm in fgraph.apply_nodes or rm in fgraph.variables:
fgraph.revert(chk)
......@@ -369,6 +373,15 @@ class ReplaceValidate(History, Validator):
del d["history"]
return d
def on_import(self, fgraph, node, reason):
if node in self._nodes_removed:
self.fail_validate = True
def validate(self, fgraph):
if self.fail_validate:
self.fail_validate = False
raise theano.gof.InconsistencyError("Trying to reintroduce a removed node")
class NodeFinder(Bookkeeper):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论