Skip to content

Commit 6b0cb03

Browse files
committed
NXP backend: Add visualization support to aot_neutron_compile.py.
1 parent e0b49e6 commit 6b0cb03

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

examples/nxp/aot_neutron_compile.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
from executorch.backends.nxp.neutron_partitioner import NeutronPartitioner
2222
from executorch.backends.nxp.nxp_backend import generate_neutron_compile_spec
2323
from executorch.backends.nxp.quantizer.neutron_quantizer import NeutronQuantizer
24+
from executorch.devtools.visualization.visualization_utils import (
25+
visualize_with_clusters,
26+
)
2427
from executorch.examples.models import MODEL_NAME_TO_MODEL
2528
from executorch.examples.models.model_factory import EagerModelFactory
2629
from executorch.exir import (
@@ -210,6 +213,12 @@ def _get_batch_size(data):
210213
nargs="*",
211214
help="List of operators not to delegate. E.g., --operators_not_to_delegate aten::convolution aten::mm",
212215
)
216+
parser.add_argument(
217+
"--visualize",
218+
choices=["show", "store"],
219+
help="Visualize the lowered program. `show` launches a browser tab with the visualization. `store` stores the "
220+
"visualization in a json file for later inspection. See `docs/source/visualize-with-clusters.md` for details.",
221+
)
213222

214223
args = parser.parse_args()
215224

@@ -237,7 +246,7 @@ def _get_batch_size(data):
237246
module = post_training_quantize(module, calibration_inputs)
238247

239248
if args.so_library is not None:
240-
logging.debug(f"Loading libraries: {args.so_library} and {args.portable_lib}")
249+
logging.debug(f"Loading libraries: {args.so_library}")
241250
torch.ops.load_library(args.so_library)
242251

243252
if args.test:
@@ -284,7 +293,7 @@ def _get_batch_size(data):
284293
raise RuntimeError(
285294
e.args[0]
286295
+ ".\nThis likely due to an external so library not being loaded. Supply a path to it with the "
287-
"--portable_lib flag."
296+
"--so_library flag."
288297
).with_traceback(e.__traceback__) from None
289298
else:
290299
raise e
@@ -301,3 +310,13 @@ def executorch_program_to_str(ep, verbose=False):
301310
"_nxp_delegate" if args.delegate is True else ""
302311
)
303312
save_pte_program(exec_prog, model_name)
313+
314+
# 7. Optionally visualize the model.
315+
if args.visualize == "show":
316+
visualize_with_clusters(exec_prog.exported_program())
317+
elif args.visualize == "store":
318+
file_name = f"{args.model_name}-visualization.json"
319+
logging.info(
320+
f"Saved the graph visualization in `{file_name}`. It can be opened using the ModelExplorer."
321+
)
322+
visualize_with_clusters(exec_prog.exported_program(), file_name)

examples/nxp/setup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ set -u
88

99
# Install neutron-converter
1010
pip install --index-url https://eiq.nxp.com/repository neutron_converter_SDK_25_09
11+
12+
# Get the directory of the current script
13+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14+
15+
# Install the required visualization dependencies.
16+
"${SCRIPT_DIR}/../../devtools/install_requirements.sh"

0 commit comments

Comments
 (0)