提交 b6f3c469 authored 作者: abergeron's avatar abergeron

Merge pull request #1911 from nouiz/cycle

Fix crash du to opt that introduce cycle in the graph
...@@ -593,8 +593,27 @@ class MergeOptimizer(Optimizer): ...@@ -593,8 +593,27 @@ class MergeOptimizer(Optimizer):
pairs_list = sched.pop() pairs_list = sched.pop()
success = True success = True
for pairs in pairs_list: for pairs in pairs_list:
# We must check again the equivalence, as the graph
# can have changed. If so, doing the replacement can
# introduce node that depend on itself. Doing the
# full check of such cycle everytimes is very time
# consumming. I think this double check is faster then
# doing the full cycle check. The full cycle check is
# skipped by validate() if the graph don't contain
# destroyers.
node = pairs[0][0]
candidate = pairs[0][1]
if node.owner and candidate.owner:
node = node.owner
candidate = candidate.owner
inputs_match = all(node_in is cand_in
for node_in, cand_in in zip(
node.inputs, candidate.inputs))
# No need to compare the op again, as it don't change.
if not inputs_match:
continue
try: try:
fgraph.replace_all_validate(pairs, 'Merge') fgraph.replace_all_validate(pairs, 'MergeOptimizer')
except InconsistencyError: except InconsistencyError:
success = False success = False
nb_fail += 1 nb_fail += 1
......
...@@ -41,19 +41,19 @@ class DB(object): ...@@ -41,19 +41,19 @@ class DB(object):
raise ValueError('The name of the object cannot be an existing' raise ValueError('The name of the object cannot be an existing'
' tag or the name of another existing object.', ' tag or the name of another existing object.',
obj, name) obj, name)
if self.name is not None:
tags = tags + (self.name,)
obj.name = name
# This restriction is there because in many place we suppose that # This restriction is there because in many place we suppose that
# something in the DB is there only once. # something in the DB is there only once.
if getattr(obj, 'name', "") in self.__db__: if obj.name in self.__db__:
raise ValueError('''You can\'t register the same optimization raise ValueError('''You can\'t register the same optimization
multiple time in a DB. Tryed to register "%s" again under the new name "%s". multiple time in a DB. Tryed to register "%s" again under the new name "%s".
Use theano.gof.ProxyDB to work around that''' % (obj.name, name)) Use theano.gof.ProxyDB to work around that''' % (obj.name, name))
if self.name is not None:
tags = tags + (self.name,)
obj.name = name
self.__db__[name] = set([obj]) self.__db__[name] = set([obj])
self._names.add(name) self._names.add(name)
self.__db__[obj.__class__.__name__].add(obj)
self.add_tags(name, *tags) self.add_tags(name, *tags)
def add_tags(self, name, *tags): def add_tags(self, name, *tags):
......
...@@ -204,6 +204,7 @@ if __name__ == "__main__": ...@@ -204,6 +204,7 @@ if __name__ == "__main__":
cuda version 6.0 5.5 5.0 4.2 4.1 4.0 3.2 3.0 # note cuda version 6.0 5.5 5.0 4.2 4.1 4.0 3.2 3.0 # note
gpu gpu
K6000/NOECC 0.06s K6000/NOECC 0.06s
K40 0.07s
K20m/ECC 0.07s K20m/ECC 0.07s
K20/NOECC 0.07s K20/NOECC 0.07s
M2090 0.19s M2090 0.19s
...@@ -213,6 +214,7 @@ if __name__ == "__main__": ...@@ -213,6 +214,7 @@ if __name__ == "__main__":
M2070-Q 0.48s 0.27s 0.32s M2070-Q 0.48s 0.27s 0.32s
M2050(Amazon) 0.25s M2050(Amazon) 0.25s
C1060 0.46s C1060 0.46s
K600 1.04s
GTX Titan Black 0.05s GTX Titan Black 0.05s
GTX Titan(D15U-50) 0.06s 0.06s don't work GTX Titan(D15U-50) 0.06s 0.06s don't work
......
...@@ -115,7 +115,7 @@ class InputToGpuOptimizer(Optimizer): ...@@ -115,7 +115,7 @@ class InputToGpuOptimizer(Optimizer):
if new_input.type == input.type: if new_input.type == input.type:
fgraph.replace_validate(input, new_input, fgraph.replace_validate(input, new_input,
"InputToGpuOptimizer") "InputToGpuOptimizer")
except TypeError: except TypeError:
#as we currently only support float32, this can fail. #as we currently only support float32, this can fail.
#Using try except make that we won't need #Using try except make that we won't need
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论