-
Notifications
You must be signed in to change notification settings - Fork 747
NXP backend: Catching the converter failures. #14117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,26 @@ | ||
| # Copyright 2024 NXP | ||
| # Copyright 2024-2025 NXP | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
| import importlib | ||
| import logging | ||
| import multiprocessing | ||
| import pkgutil | ||
|
|
||
| from executorch.backends.nxp.backend.ir.converter.node_converter import Target | ||
|
|
||
|
|
||
| def convert_unsafe(neutron_converter, tflite_model, cctx, queue): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A documentation comment would be useful here.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jirioc, can you please add it?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| """ | ||
| Run neutron_converter on given tflite_model with compilation context cctx. | ||
| This routine is supposed to run in a separate process. | ||
| If properly finished, the output queue contains the converted model, | ||
| otherwise the neutron_converter exits and the output queue is empty. | ||
| """ | ||
| model_converted = neutron_converter.convertModel(list(tflite_model), cctx) | ||
| queue.put(model_converted) | ||
|
|
||
|
|
||
| class NeutronConverterManager: | ||
| """ | ||
| Manager for conversion of TFLite model in flatbuffers format into TFLite model that | ||
|
|
@@ -52,6 +65,23 @@ def convert( | |
| cctx.targetOpts = neutron_converter.getNeutronTarget(target) | ||
| # New switch since Neutron Converter SDK_25.06 | ||
| cctx.compilationOpts.minNumOpsPerGraph = 1 | ||
| model_converted = neutron_converter.convertModel(list(tflite_model), cctx) | ||
|
|
||
| logger = multiprocessing.log_to_stderr() | ||
| logger.setLevel(logging.WARNING) | ||
| queue = multiprocessing.Manager().Queue() | ||
|
|
||
| process = multiprocessing.Process( | ||
| target=convert_unsafe, args=(neutron_converter, tflite_model, cctx, queue) | ||
| ) | ||
| process.start() | ||
| process.join() # waits until the subprocess is complete | ||
|
|
||
| if queue.empty(): # signals the unsafe task did not run till the end | ||
| raise RuntimeError( | ||
| f"Neutron converter module terminated unexpectedly with exit code {process.exitcode}" | ||
| ) | ||
|
|
||
| model_converted = queue.get() | ||
|
|
||
| process.close() | ||
| return bytes(model_converted) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Copyright 2024-2025 NXPThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed ✅