Skip to content

Commit fce6017

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

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

backends/nxp/backend/neutron_converter_manager.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
# Copyright 2024 NXP
1+
# Copyright 2024-2025 NXP
22
#
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,23 @@ 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)
5662

63+
logger = multiprocessing.log_to_stderr()
64+
logger.setLevel(logging.WARNING)
65+
queue = multiprocessing.Manager().Queue()
66+
67+
process = multiprocessing.Process(
68+
target=convert_unsafe, args=(neutron_converter, tflite_model, cctx, queue)
69+
)
70+
process.start()
71+
process.join() # waits until the subprocess is complete
72+
73+
if queue.empty(): # signals the unsafe task did not run till the end
74+
raise RuntimeError(
75+
f"Neutron converter module terminated unexpectedly with exit code {process.exitcode}"
76+
)
77+
78+
model_converted = queue.get()
79+
80+
process.close()
5781
return bytes(model_converted)

0 commit comments

Comments
 (0)