From 2fde02034c160544d77c8fb30936451e35d37b28 Mon Sep 17 00:00:00 2001 From: Yoni Yang <76271912+yoni13@users.noreply.github.com> Date: Thu, 24 Apr 2025 17:03:30 +0000 Subject: [PATCH 1/5] init support for rknn_blocked_ops --- immich_model_exporter/exporters/constants.py | 1 + immich_model_exporter/exporters/rknn.py | 11 ++++++++++- immich_model_exporter/run.py | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/immich_model_exporter/exporters/constants.py b/immich_model_exporter/exporters/constants.py index 45e08a5..4f47c9f 100644 --- a/immich_model_exporter/exporters/constants.py +++ b/immich_model_exporter/exporters/constants.py @@ -35,6 +35,7 @@ class SourceMetadata(NamedTuple): } RKNN_SOCS = ["rk3566", "rk3568", "rk3576", "rk3588"] +RKNN_BLOCKED_OPS = ["CumSum"] # glob to delete old UUID blobs when reuploading models diff --git a/immich_model_exporter/exporters/rknn.py b/immich_model_exporter/exporters/rknn.py index c45c4a6..7622594 100644 --- a/immich_model_exporter/exporters/rknn.py +++ b/immich_model_exporter/exporters/rknn.py @@ -1,6 +1,6 @@ from pathlib import Path -from .constants import RKNN_SOCS +from .constants import RKNN_SOCS, RKNN_BLOCKED_OPS def _export_platform( @@ -36,6 +36,15 @@ def _export_platform( ret = rknn.build(do_quantization=False) + if "textual" in input_path: + ret = rknn.accuracy_analysis(inputs=["rand.npy"]) + if ret != 0: + RuntimeError("Accuracy analysis failed!") + analysis_result= open("./snapshot/error_analysis.txt","r") + for ops in RKNN_BLOCKED_OPS: + if ops in analysis_result.read(): + raise RuntimeError("ONNX Model contains Unsupported OPs!") + if ret != 0: raise RuntimeError("Build failed!") diff --git a/immich_model_exporter/run.py b/immich_model_exporter/run.py index 7e69a21..afda59a 100644 --- a/immich_model_exporter/run.py +++ b/immich_model_exporter/run.py @@ -1,5 +1,6 @@ import subprocess from pathlib import Path +import numpy as np from exporters.constants import ModelSource @@ -105,6 +106,8 @@ def export_models(models: list[str], source: ModelSource) -> None: if __name__ == "__main__": + rand = np.random.rand(1,77) + np.save("randtextualinput.npy",rand) export_models(mclip, ModelSource.MCLIP) export_models(openclip, ModelSource.OPENCLIP) export_models(insightface, ModelSource.INSIGHTFACE) From e86d85d15935af50204b3e1b0367133f335f27f7 Mon Sep 17 00:00:00 2001 From: Yoni Yang <76271912+yoni13@users.noreply.github.com> Date: Thu, 24 Apr 2025 17:29:59 +0000 Subject: [PATCH 2/5] return str --- immich_model_exporter/exporters/rknn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/immich_model_exporter/exporters/rknn.py b/immich_model_exporter/exporters/rknn.py index 7622594..b267476 100644 --- a/immich_model_exporter/exporters/rknn.py +++ b/immich_model_exporter/exporters/rknn.py @@ -36,7 +36,7 @@ def _export_platform( ret = rknn.build(do_quantization=False) - if "textual" in input_path: + if "textual" in input_path.as_posix(): ret = rknn.accuracy_analysis(inputs=["rand.npy"]) if ret != 0: RuntimeError("Accuracy analysis failed!") From b8da4a16b6c2c8e75061fb97d2300b151c4ab537 Mon Sep 17 00:00:00 2001 From: Yoni Yang <76271912+yoni13@users.noreply.github.com> Date: Thu, 24 Apr 2025 17:33:17 +0000 Subject: [PATCH 3/5] fix name --- immich_model_exporter/exporters/rknn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/immich_model_exporter/exporters/rknn.py b/immich_model_exporter/exporters/rknn.py index b267476..9229384 100644 --- a/immich_model_exporter/exporters/rknn.py +++ b/immich_model_exporter/exporters/rknn.py @@ -37,7 +37,7 @@ def _export_platform( ret = rknn.build(do_quantization=False) if "textual" in input_path.as_posix(): - ret = rknn.accuracy_analysis(inputs=["rand.npy"]) + ret = rknn.accuracy_analysis(inputs=["randtextualinput.npy"]) if ret != 0: RuntimeError("Accuracy analysis failed!") analysis_result= open("./snapshot/error_analysis.txt","r") From 0894b85c1ff21cd23b40b08342d1d693cc7dc751 Mon Sep 17 00:00:00 2001 From: Yoni Yang <76271912+yoni13@users.noreply.github.com> Date: Fri, 25 Apr 2025 05:15:13 +0000 Subject: [PATCH 4/5] add randtextualinput.npy while exporting clip models --- immich_model_exporter/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/immich_model_exporter/__init__.py b/immich_model_exporter/__init__.py index 64f3ae7..4d9531e 100644 --- a/immich_model_exporter/__init__.py +++ b/immich_model_exporter/__init__.py @@ -1,7 +1,7 @@ import json import resource from pathlib import Path - +import numpy as np import typer from tenacity import retry, stop_after_attempt, wait_fixed from typing_extensions import Annotated @@ -53,6 +53,8 @@ def export( output_dir = output_dir / model_name match model_source: case ModelSource.MCLIP | ModelSource.OPENCLIP: + rand = np.random.rand(1,77) + np.save("randtextualinput.npy",rand) output_dir.mkdir(parents=True, exist_ok=True) onnx_export(hf_model_name, model_source, output_dir, cache=cache) case ModelSource.INSIGHTFACE: From 379e896ece45270a3877e2f7cc3f4786eeafd6d3 Mon Sep 17 00:00:00 2001 From: Yoni Yang <76271912+yoni13@users.noreply.github.com> Date: Fri, 25 Apr 2025 05:30:19 +0000 Subject: [PATCH 5/5] some cleanup --- immich_model_exporter/__init__.py | 1 + immich_model_exporter/exporters/rknn.py | 2 +- immich_model_exporter/run.py | 3 --- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/immich_model_exporter/__init__.py b/immich_model_exporter/__init__.py index 4d9531e..244d99f 100644 --- a/immich_model_exporter/__init__.py +++ b/immich_model_exporter/__init__.py @@ -1,6 +1,7 @@ import json import resource from pathlib import Path + import numpy as np import typer from tenacity import retry, stop_after_attempt, wait_fixed diff --git a/immich_model_exporter/exporters/rknn.py b/immich_model_exporter/exporters/rknn.py index 9229384..47dca78 100644 --- a/immich_model_exporter/exporters/rknn.py +++ b/immich_model_exporter/exporters/rknn.py @@ -1,6 +1,6 @@ from pathlib import Path -from .constants import RKNN_SOCS, RKNN_BLOCKED_OPS +from .constants import RKNN_BLOCKED_OPS, RKNN_SOCS def _export_platform( diff --git a/immich_model_exporter/run.py b/immich_model_exporter/run.py index afda59a..7e69a21 100644 --- a/immich_model_exporter/run.py +++ b/immich_model_exporter/run.py @@ -1,6 +1,5 @@ import subprocess from pathlib import Path -import numpy as np from exporters.constants import ModelSource @@ -106,8 +105,6 @@ def export_models(models: list[str], source: ModelSource) -> None: if __name__ == "__main__": - rand = np.random.rand(1,77) - np.save("randtextualinput.npy",rand) export_models(mclip, ModelSource.MCLIP) export_models(openclip, ModelSource.OPENCLIP) export_models(insightface, ModelSource.INSIGHTFACE)