-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mlek: Increase build speed with reduced use case resource metadata (#59)
Patch the library to provide a reduced set of metadata to download and optimize when building applications. The only models specified in the use case resources files (depending on the application) are asr and kws. Those are the only models required by the FRI applications. The build time for the ML applications have been reduced by 40%. Signed-off-by: Hugues Kamba-Mpiana <[email protected]>
- Loading branch information
1 parent
148e59d
commit 7ff0f59
Showing
10 changed files
with
152 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
applications/keyword_detection/resources/use_case_resources.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"name": "kws", | ||
"url_prefix": [ | ||
"https://github.com/ARM-software/ML-zoo/raw/9f506fe52b39df545f0e6c5ff9223f671bc5ae00/models/keyword_spotting/micronet_medium/tflite_int8/" | ||
], | ||
"resources": [ | ||
{"name": "ifm0.npy", "url": "{url_prefix:0}testing_input/input/0.npy"}, | ||
{"name": "ofm0.npy", "url": "{url_prefix:0}testing_output/Identity/0.npy"}, | ||
{ | ||
"name": "kws_micronet_m.tflite", | ||
"url": "{url_prefix:0}kws_micronet_m.tflite" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
applications/speech_recognition/resources/use_case_resources.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"name": "asr", | ||
"url_prefix": [ | ||
"https://github.com/ARM-software/ML-zoo/raw/eb2170aac1317f00b128ab82bdb159cfcca36ea6/models/speech_recognition/tiny_wav2letter/tflite_pruned_int8/" | ||
], | ||
"resources": [ | ||
{ | ||
"name": "tiny_wav2letter_pruned_int8.tflite", | ||
"url": "{url_prefix:0}tiny_wav2letter_pruned_int8.tflite" | ||
}, | ||
{ | ||
"name": "ifm0.npy", | ||
"url": "{url_prefix:0}testing_input/input_1_int8/0.npy" | ||
}, | ||
{ | ||
"name": "ofm0.npy", | ||
"url": "{url_prefix:0}testing_output/Identity_int8/0.npy" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
...n_kit/integration/patches/0001-resources-Replace-model-wav2letter-with-tiny_wav2let.patch
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
...tion_kit/integration/patches/0001-use-case-resources-Enabled-user-provided-metadata.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
From f3f30b50769f5c3cf3c32f1b715acefd6ba0b8bc Mon Sep 17 00:00:00 2001 | ||
From: Hugues Kamba-Mpiana <[email protected]> | ||
Date: Mon, 4 Mar 2024 16:01:55 +0000 | ||
Subject: [PATCH] use-case-resources: Enabled user provided metadata | ||
|
||
An optional argument has been added to the `set_up_default_resources.py` | ||
Python script to allow passing of a user defined use case resources | ||
metadata JSON file. | ||
This shortens the build time by only downloading the resources the | ||
end user is interested in. It also shortens the optimization part | ||
which takes additional minutes as it is done for all models and for | ||
all the specified NPU configurations. | ||
|
||
|
||
Signed-off-by: Hugues Kamba-Mpiana <[email protected]> | ||
--- | ||
set_up_default_resources.py | 23 ++++++++++++++++++----- | ||
1 file changed, 18 insertions(+), 5 deletions(-) | ||
|
||
diff --git a/set_up_default_resources.py b/set_up_default_resources.py | ||
index f5cd0ac..5bbb5e9 100755 | ||
--- a/set_up_default_resources.py | ||
+++ b/set_up_default_resources.py | ||
@@ -96,21 +96,24 @@ class UseCase: | ||
MPS3_MAX_SRAM_SZ = 2 * 1024 * 1024 # 2 MiB (2 banks of 1 MiB each) | ||
|
||
|
||
-def load_use_case_resources(current_file_dir: Path) -> typing.List[UseCase]: | ||
+def load_use_case_resources( | ||
+ current_file_dir: Path, use_case_resources_file: Path | ||
+) -> typing.List[UseCase]: | ||
""" | ||
Load use case metadata resources | ||
|
||
Parameters | ||
---------- | ||
current_file_dir: Directory of the current script | ||
+ use_case_resources_file: Path to a JSON file containing the use case | ||
+ metadata resources. | ||
|
||
Returns | ||
------- | ||
The use cases resources object parsed to a dict | ||
""" | ||
|
||
- resources_path = current_file_dir / "scripts" / "py" / "use_case_resources.json" | ||
- with open(resources_path, encoding="utf8") as f: | ||
+ with open(use_case_resources_file, encoding="utf8") as f: | ||
use_cases = json.load(f) | ||
return [ | ||
UseCase( | ||
@@ -579,7 +582,8 @@ def set_up_resources( | ||
additional_npu_config_names: tuple = (), | ||
arena_cache_size: int = 0, | ||
check_clean_folder: bool = False, | ||
- additional_requirements_file: Path = "" | ||
+ additional_requirements_file: Path = "", | ||
+ use_case_resources_file: Path = "", | ||
) -> Path: | ||
""" | ||
Helpers function that retrieve the output from a command. | ||
@@ -597,6 +601,8 @@ def set_up_resources( | ||
additional_requirements_file (str): Path to a requirements.txt file if | ||
additional packages need to be | ||
installed. | ||
+ use_case_resources_file (str): Path to a JSON file containing the use case | ||
+ metadata resources. | ||
|
||
Returns | ||
------- | ||
@@ -619,7 +625,7 @@ def set_up_resources( | ||
) | ||
logging.info("Using Python version: %s", sys.version_info) | ||
|
||
- json_uc_res = load_use_case_resources(current_file_dir) | ||
+ json_uc_res = load_use_case_resources(current_file_dir, use_case_resources_file) | ||
setup_script_hash = get_md5sum_for_file(Path(__file__).resolve()) | ||
|
||
metadata_dict, setup_script_hash_verified = initialize_resources_directory( | ||
@@ -706,6 +712,12 @@ if __name__ == "__main__": | ||
type=str, | ||
default=Path(__file__).parent.resolve() / 'scripts' / 'py' / 'requirements.txt' | ||
) | ||
+ parser.add_argument( | ||
+ "--use-case-resources-file", | ||
+ help="Path to the use case resources file", | ||
+ type=str, | ||
+ default=Path(__file__).parent.resolve() / 'scripts' / 'py' / 'use_case_resources.json' | ||
+ ) | ||
|
||
args = parser.parse_args() | ||
|
||
@@ -724,4 +736,5 @@ if __name__ == "__main__": | ||
args.arena_cache_size, | ||
args.clean, | ||
args.requirements_file, | ||
+ args.use_case_resources_file, | ||
) | ||
-- | ||
2.34.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mlek: Reduce build time with reduced use case resources metadata |