Skip to content

Commit c3f5a69

Browse files
committed
NXP backend: Catching the converter failures.
1 parent 6ed10e5 commit c3f5a69

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

backends/nxp/backend/neutron_converter_manager.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
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+
"""
15+
Run neutron_converter on given tflite_model with compilation context cctx.
16+
This routine is supposed to run in a separate process.
17+
If properly finished, the output queue contains the converted model,
18+
otherwise the neutron_converter exits and the output queue is empty.
19+
"""
20+
model_converted = neutron_converter.convertModel(list(tflite_model), cctx)
21+
queue.put(model_converted)
22+
23+
1124
class NeutronConverterManager:
1225
"""
1326
Manager for conversion of TFLite model in flatbuffers format into TFLite model that
@@ -52,6 +65,23 @@ def convert(
5265
cctx.targetOpts = neutron_converter.getNeutronTarget(target)
5366
# New switch since Neutron Converter SDK_25.06
5467
cctx.compilationOpts.minNumOpsPerGraph = 1
55-
model_converted = neutron_converter.convertModel(list(tflite_model), cctx)
5668

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

0 commit comments

Comments
 (0)