Skip to content

Commit 62ab20c

Browse files
jiriocStrycekSimon
authored andcommitted
NXP backend: Catching the converter failures.
1 parent 245630a commit 62ab20c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

backends/nxp/backend/neutron_converter_manager.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55
import importlib
6+
import logging
7+
import multiprocessing
68
import pkgutil
79

810
from executorch.backends.nxp.backend.ir.converter.node_converter import Target
911

1012

13+
def convert_unsafe(neutron_converter, tflite_model, cctx, queue):
14+
model_converted = neutron_converter.convertModel(list(tflite_model), cctx)
15+
queue.put(model_converted)
16+
17+
1118
class NeutronConverterManager:
1219
"""
1320
Manager for conversion of TFLite model in flatbuffers format into TFLite model that
@@ -52,6 +59,25 @@ def convert(
5259
cctx.targetOpts = neutron_converter.getNeutronTarget(target)
5360
# New switch since Neutron Converter SDK_25.06
5461
cctx.compilationOpts.minNumOpsPerGraph = 1
55-
model_converted = neutron_converter.convertModel(list(tflite_model), cctx)
62+
# Don't merge `Transpose` operators, to avoid creating unsupported permutations.
63+
cctx.compilationOpts.excludeGraphPasses = "MergeTranspose"
64+
65+
logger = multiprocessing.log_to_stderr()
66+
logger.setLevel(logging.WARNING)
67+
queue = multiprocessing.Manager().Queue()
68+
69+
process = multiprocessing.Process(
70+
target=convert_unsafe, args=(neutron_converter, tflite_model, cctx, queue)
71+
)
72+
process.start()
73+
process.join() # waits until the subprocess is complete
74+
75+
if queue.empty(): # signals the unsafe task did not run till the end
76+
raise RuntimeError(
77+
f"Neutron converter module terminated unexpectedly with exit code {process.exitcode}"
78+
)
79+
80+
model_converted = queue.get()
5681

82+
process.close()
5783
return bytes(model_converted)

0 commit comments

Comments
 (0)