Skip to content

Commit 190ad96

Browse files
committed
fix random failures: remove iteration based conversion, get back to original design
1 parent 261818a commit 190ad96

File tree

1 file changed

+42
-46
lines changed

1 file changed

+42
-46
lines changed

tf2onnx/tfonnx.py

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,53 +2242,49 @@ def tensorflow_onnx_mapping(g, continue_on_error, custom_op_handlers):
22422242
custom_opset = {k: v for k, v in custom_op_handlers.items()}
22432243
ops_mapping.update(custom_opset)
22442244

2245-
has_update = True
2246-
while has_update:
2247-
has_update = False
2248-
ops = g.get_nodes()
2249-
for node in ops:
2250-
if node.need_skip():
2251-
log.debug("explictly skip node " + node.name)
2245+
ops = [n for n in g.get_nodes()]
2246+
for node in ops:
2247+
if node.need_skip():
2248+
log.debug("explictly skip node " + node.name)
2249+
continue
2250+
2251+
op = node.type
2252+
map_info = ops_mapping.get(op)
2253+
if map_info is None:
2254+
if continue_on_error:
2255+
unmapped_op[op] += 1
22522256
continue
2253-
has_update = True
2254-
op = node.type
2255-
map_info = ops_mapping.get(op)
2256-
if map_info is None:
2257-
if continue_on_error:
2258-
unmapped_op[op] += 1
2259-
continue
2260-
else:
2261-
raise ValueError("tensorflow op " + op + " is not supported")
2262-
mapped_op[op] += 1
2263-
func, args = map_info
2264-
onnx_node = None
2265-
if args:
2266-
node.type = args[0]
2267-
args = args[1:]
2268-
try:
2269-
body_graphs = node.get_body_graphs()
2270-
if body_graphs:
2271-
for attr, b_g in body_graphs.items():
2272-
log.debug("start handling subgraph of %s's attribute %s", node.name, attr)
2273-
b_g.topological_sort(b_g.get_nodes())
2274-
# we assume only ONNX nodes have subgraph defined in pre-rewriters.
2275-
# that means, if we create node having subgraphs in this step, the
2276-
# created subgraphs' nodes won't be mapped.
2277-
m_ops, unm_ops = tensorflow_onnx_mapping(b_g, continue_on_error, custom_op_handlers)
2278-
mapped_op += m_ops
2279-
unmapped_op += unm_ops
2280-
log.debug("finish handling subgraph of %s's attribute %s", node.name, attr)
2281-
2282-
func(g, node, node.name, args)
2283-
node.skip_conversion = True
2284-
except Exception as ex:
2285-
type_, value_, traceback_ = sys.exc_info()
2286-
log.error("node %s: exception %s" % (node.name, ex))
2287-
ex_ext = traceback.format_exception(type_, value_, traceback_)
2288-
if continue_on_error:
2289-
log.info(ex_ext)
2290-
else:
2291-
raise ex
2257+
else:
2258+
raise ValueError("tensorflow op " + op + " is not supported")
2259+
mapped_op[op] += 1
2260+
func, args = map_info
2261+
if args:
2262+
node.type = args[0]
2263+
args = args[1:]
2264+
try:
2265+
body_graphs = node.get_body_graphs()
2266+
if body_graphs:
2267+
for attr, b_g in body_graphs.items():
2268+
log.debug("start handling subgraph of %s's attribute %s", node.name, attr)
2269+
b_g.topological_sort(b_g.get_nodes())
2270+
# we assume only ONNX nodes have subgraph defined in pre-rewriters.
2271+
# that means, if we create node having subgraphs in this step, the
2272+
# created subgraphs' nodes won't be mapped.
2273+
m_ops, unm_ops = tensorflow_onnx_mapping(b_g, continue_on_error, custom_op_handlers)
2274+
mapped_op += m_ops
2275+
unmapped_op += unm_ops
2276+
log.debug("finish handling subgraph of %s's attribute %s", node.name, attr)
2277+
2278+
func(g, node, node.name, args)
2279+
node.skip_conversion = True
2280+
except Exception as ex:
2281+
type_, value_, traceback_ = sys.exc_info()
2282+
log.error("node %s: exception %s" % (node.name, ex))
2283+
ex_ext = traceback.format_exception(type_, value_, traceback_)
2284+
if continue_on_error:
2285+
log.info(ex_ext)
2286+
else:
2287+
raise ex
22922288

22932289
return mapped_op, unmapped_op
22942290

0 commit comments

Comments
 (0)