litert-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- examples/litert_cli.ipynb +313 -0
- examples/models/presets/default.py +19 -0
- examples/run_cli_demo.sh +38 -0
- examples/run_cli_npu.sh +89 -0
- examples/run_commands.sh +67 -0
- examples/run_models.sh +63 -0
- examples/run_smoke_tests.sh +58 -0
- examples/utils.ps1 +163 -0
- examples/utils.sh +184 -0
- litert_cli/__init__.py +15 -0
- litert_cli/commands/benchmark/__init__.py +16 -0
- litert_cli/commands/benchmark/android.py +212 -0
- litert_cli/commands/benchmark/cli.py +294 -0
- litert_cli/commands/benchmark/desktop.py +228 -0
- litert_cli/commands/benchmark/gcp.py +336 -0
- litert_cli/commands/clean.py +73 -0
- litert_cli/commands/compile.py +211 -0
- litert_cli/commands/convert/__init__.py +20 -0
- litert_cli/commands/convert/cli.py +255 -0
- litert_cli/commands/convert/generic.py +211 -0
- litert_cli/commands/convert/huggingface.py +175 -0
- litert_cli/commands/delete.py +56 -0
- litert_cli/commands/download.py +274 -0
- litert_cli/commands/import.py +124 -0
- litert_cli/commands/list.py +132 -0
- litert_cli/commands/lm.py +74 -0
- litert_cli/commands/quantize.py +193 -0
- litert_cli/commands/run/__init__.py +16 -0
- litert_cli/commands/run/android.py +394 -0
- litert_cli/commands/run/cli.py +297 -0
- litert_cli/commands/run/desktop.py +340 -0
- litert_cli/commands/visualize.py +234 -0
- litert_cli/core/android_utils.py +304 -0
- litert_cli/core/android_utils_test.py +236 -0
- litert_cli/core/constants.py +131 -0
- litert_cli/core/deps.py +180 -0
- litert_cli/core/deps_test.py +101 -0
- litert_cli/core/inputs.py +203 -0
- litert_cli/core/inputs_test.py +176 -0
- litert_cli/core/log_filters.py +50 -0
- litert_cli/core/models.py +96 -0
- litert_cli/core/npu_utils.py +382 -0
- litert_cli/core/targets_manager.py +192 -0
- litert_cli/core/utils.py +58 -0
- litert_cli/litert.py +119 -0
- litert_cli/litert_help_test.py +51 -0
- litert_cli/litert_test.py +88 -0
- litert_cli/models/__init__.py +145 -0
- litert_cli/models/asr/__init__.py +15 -0
- litert_cli/models/asr/asr_model.py +108 -0
- litert_cli/models/asr/parakeet_ctc.py +165 -0
- litert_cli/models/asr/runner.py +482 -0
- litert_cli/models/base.py +57 -0
- litert_cli/test_data/dummy_calib_data.py +26 -0
- litert_cli/test_data/dummy_cv_model.py +52 -0
- litert_cli/test_data/dummy_cv_model.tflite +0 -0
- litert_cli/test_data/generate_test_inputs.py +51 -0
- litert_cli/test_data/mobilenet_v3_calib_data.py +25 -0
- litert_cli/test_data/quantize_recipe.json +16 -0
- litert_cli/test_data/resnet18.py +31 -0
- litert_cli-0.1.0.dist-info/METADATA +38 -0
- litert_cli-0.1.0.dist-info/RECORD +67 -0
- litert_cli-0.1.0.dist-info/WHEEL +5 -0
- litert_cli-0.1.0.dist-info/entry_points.txt +2 -0
- litert_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
- litert_cli-0.1.0.dist-info/top_level.txt +3 -0
- tools/build_wheels.py +122 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "markdown",
|
|
5
|
+
"id": "28580e8c",
|
|
6
|
+
"metadata": {
|
|
7
|
+
"colab_type": "text",
|
|
8
|
+
"id": "view-in-github"
|
|
9
|
+
},
|
|
10
|
+
"source": [
|
|
11
|
+
"<a href=\"https://colab.research.google.com/github/google-ai-edge/LiteRT-CLI/blob/main/examples/litert_cli.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"cell_type": "markdown",
|
|
16
|
+
"id": "6a6c4940",
|
|
17
|
+
"metadata": {
|
|
18
|
+
"id": "litert-cli-copyright"
|
|
19
|
+
},
|
|
20
|
+
"source": [
|
|
21
|
+
"##### Copyright 2026 The LiteRT CLI Authors."
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"cell_type": "code",
|
|
26
|
+
"execution_count": null,
|
|
27
|
+
"id": "218b9c57",
|
|
28
|
+
"metadata": {
|
|
29
|
+
"cellView": "form",
|
|
30
|
+
"id": "litert-cli-license"
|
|
31
|
+
},
|
|
32
|
+
"outputs": [],
|
|
33
|
+
"source": [
|
|
34
|
+
"# @title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
|
35
|
+
"# you may not use this file except in compliance with the License.\n",
|
|
36
|
+
"# You may obtain a copy of the License at\n",
|
|
37
|
+
"#\n",
|
|
38
|
+
"# http://www.apache.org/licenses/LICENSE-2.0\n",
|
|
39
|
+
"#\n",
|
|
40
|
+
"# Unless required by applicable law or agreed to in writing, software\n",
|
|
41
|
+
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
|
42
|
+
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
|
43
|
+
"# See the License for the specific language governing permissions and\n",
|
|
44
|
+
"# limitations under the License.\n",
|
|
45
|
+
"# =============================================================================="
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"cell_type": "markdown",
|
|
50
|
+
"id": "90c3deda",
|
|
51
|
+
"metadata": {},
|
|
52
|
+
"source": [
|
|
53
|
+
"# LiteRT CLI Demo\n",
|
|
54
|
+
"\n",
|
|
55
|
+
"This notebook demonstrates how to use the `litert-cli` tool to convert a PyTorch model, quantize it and run it."
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"cell_type": "markdown",
|
|
60
|
+
"id": "19270446",
|
|
61
|
+
"metadata": {},
|
|
62
|
+
"source": [
|
|
63
|
+
"## 🛠️ 1. Environment Setup & Installation"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"cell_type": "code",
|
|
68
|
+
"execution_count": null,
|
|
69
|
+
"id": "d34739df",
|
|
70
|
+
"metadata": {},
|
|
71
|
+
"outputs": [],
|
|
72
|
+
"source": [
|
|
73
|
+
"# Update protobuf version\n",
|
|
74
|
+
"!pip install -U protobuf\n",
|
|
75
|
+
"# Install required packages\n",
|
|
76
|
+
"!pip install torch torchvision\n",
|
|
77
|
+
"# Default torchao is \n",
|
|
78
|
+
"!pip install -U torchao\n",
|
|
79
|
+
"\n",
|
|
80
|
+
"# Install litert-cli\n",
|
|
81
|
+
"!pip install litert-cli-nightly\n",
|
|
82
|
+
"\n",
|
|
83
|
+
"# 'litert compile' depends on Clang, and below make sure your Clang has version `18.x.x` or above\n",
|
|
84
|
+
"!wget https://apt.llvm.org/llvm.sh\n",
|
|
85
|
+
"!chmod +x llvm.sh\n",
|
|
86
|
+
"!sudo ./llvm.sh 18 all"
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"cell_type": "markdown",
|
|
91
|
+
"id": "1dd1eb34",
|
|
92
|
+
"metadata": {},
|
|
93
|
+
"source": [
|
|
94
|
+
"## 📝 2. Prepare PyTorch Model Script"
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"cell_type": "code",
|
|
99
|
+
"execution_count": null,
|
|
100
|
+
"id": "5e40f66c",
|
|
101
|
+
"metadata": {},
|
|
102
|
+
"outputs": [],
|
|
103
|
+
"source": [
|
|
104
|
+
"%%writefile resnet18.py\n",
|
|
105
|
+
"import torch\n",
|
|
106
|
+
"import torchvision\n",
|
|
107
|
+
"\n",
|
|
108
|
+
"def get_model(batch_size: int = 1) -> torch.nn.Module:\n",
|
|
109
|
+
" model = torchvision.models.resnet18(\n",
|
|
110
|
+
" weights=torchvision.models.ResNet18_Weights.IMAGENET1K_V1\n",
|
|
111
|
+
" )\n",
|
|
112
|
+
" model.eval()\n",
|
|
113
|
+
" return model\n",
|
|
114
|
+
"\n",
|
|
115
|
+
"def get_args(batch_size: int = 1) -> tuple[torch.Tensor, ...]:\n",
|
|
116
|
+
" return (torch.randn(batch_size, 3, 224, 224),)"
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"cell_type": "markdown",
|
|
121
|
+
"id": "427dca8a",
|
|
122
|
+
"metadata": {},
|
|
123
|
+
"source": [
|
|
124
|
+
"## 🔄 3. Model Conversion (PyTorch -> LiteRT)"
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"cell_type": "code",
|
|
129
|
+
"execution_count": null,
|
|
130
|
+
"id": "578cc653",
|
|
131
|
+
"metadata": {},
|
|
132
|
+
"outputs": [],
|
|
133
|
+
"source": [
|
|
134
|
+
"# Convert PyTorch ResNet18 model to LiteRT\n",
|
|
135
|
+
"!litert convert resnet18.py --output resnet18"
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"cell_type": "markdown",
|
|
140
|
+
"id": "606efd4f",
|
|
141
|
+
"metadata": {},
|
|
142
|
+
"source": [
|
|
143
|
+
"## 📉 4. Model Quantization"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"cell_type": "code",
|
|
148
|
+
"execution_count": null,
|
|
149
|
+
"id": "c589c711",
|
|
150
|
+
"metadata": {},
|
|
151
|
+
"outputs": [],
|
|
152
|
+
"source": [
|
|
153
|
+
"# Quantize the ResNet18 model\n",
|
|
154
|
+
"!litert quantize resnet18/resnet18.tflite --recipe dynamic_wi8_afp32 --output resnet18/resnet18_int8_dynamic.tflite\n",
|
|
155
|
+
"!litert quantize resnet18/resnet18.tflite --recipe weight_only_wi8_afp32 --output resnet18/resnet18_int8_weight_only.tflite"
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"cell_type": "markdown",
|
|
160
|
+
"id": "b3ae9ddc",
|
|
161
|
+
"metadata": {},
|
|
162
|
+
"source": [
|
|
163
|
+
"## 🚀 5. Run Inference\n",
|
|
164
|
+
"### 🖥️ 5.1 CPU Inference"
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"cell_type": "code",
|
|
169
|
+
"execution_count": null,
|
|
170
|
+
"id": "ea93a1db",
|
|
171
|
+
"metadata": {},
|
|
172
|
+
"outputs": [],
|
|
173
|
+
"source": [
|
|
174
|
+
"# Run Inference on Desktop (Colab VM CPU)\n",
|
|
175
|
+
"!litert run resnet18/resnet18.tflite\n",
|
|
176
|
+
"!litert run resnet18/resnet18_int8_dynamic.tflite --desktop --cpu --iterations 1\n",
|
|
177
|
+
"\n",
|
|
178
|
+
"# Download EfficientNet-B1 model directly from HuggingFace (No conversion needed)\n",
|
|
179
|
+
"!litert download litert-community/efficientnet_b1 --file \"*.tflite\" --output efficientnet\n",
|
|
180
|
+
"\n",
|
|
181
|
+
"# Run Inference for EfficientNet on Desktop CPU\n",
|
|
182
|
+
"!litert run efficientnet/efficientnet_b1.tflite"
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"cell_type": "markdown",
|
|
187
|
+
"id": "9d748475",
|
|
188
|
+
"metadata": {},
|
|
189
|
+
"source": [
|
|
190
|
+
"### 🎮 5.2 GPU Inference"
|
|
191
|
+
]
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"cell_type": "code",
|
|
195
|
+
"execution_count": null,
|
|
196
|
+
"id": "00b026b2",
|
|
197
|
+
"metadata": {},
|
|
198
|
+
"outputs": [],
|
|
199
|
+
"source": [
|
|
200
|
+
"# Run Inference on Desktop with GPU (Colab VM GPU), and please make you connect to a machine\n",
|
|
201
|
+
"# with GPU. You can click \"change runtime type\" to find options there.\n",
|
|
202
|
+
"!litert run resnet18/resnet18.tflite\n",
|
|
203
|
+
"!litert run resnet18/resnet18_int8_dynamic.tflite --desktop --gpu --iterations 1 --print-tensors\n",
|
|
204
|
+
"\n",
|
|
205
|
+
"# Run Inference for EfficientNet on Desktop GPU\n",
|
|
206
|
+
"!litert run efficientnet/efficientnet_b1.tflite --gpu"
|
|
207
|
+
]
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"cell_type": "markdown",
|
|
211
|
+
"id": "eaa972bc",
|
|
212
|
+
"metadata": {},
|
|
213
|
+
"source": [
|
|
214
|
+
"## ⚙️ 6. NPU Offline Compilation (AOT)"
|
|
215
|
+
]
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"cell_type": "code",
|
|
219
|
+
"execution_count": null,
|
|
220
|
+
"id": "d0a61181",
|
|
221
|
+
"metadata": {},
|
|
222
|
+
"outputs": [],
|
|
223
|
+
"source": [
|
|
224
|
+
"# Compile the model for qualcomm NPU: SM8750\n",
|
|
225
|
+
"# TIP: Only support running on Linux and it might take a few minutes, given download large SDKs from SOCs.\n",
|
|
226
|
+
"#\n",
|
|
227
|
+
"!litert compile resnet18/resnet18.tflite --target sm8750\n",
|
|
228
|
+
"\n",
|
|
229
|
+
"# Compile EfficientNet model for Qualcomm NPU: SM8750\n",
|
|
230
|
+
"!litert compile efficientnet/efficientnet_b1.tflite --target sm8750"
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"cell_type": "markdown",
|
|
235
|
+
"id": "2da953c9",
|
|
236
|
+
"metadata": {},
|
|
237
|
+
"source": [
|
|
238
|
+
"## 🏁 7. Benchmark in Google AI Edge Portal"
|
|
239
|
+
]
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"cell_type": "code",
|
|
243
|
+
"execution_count": null,
|
|
244
|
+
"id": "a9a19e48",
|
|
245
|
+
"metadata": {
|
|
246
|
+
"cellView": "form"
|
|
247
|
+
},
|
|
248
|
+
"outputs": [],
|
|
249
|
+
"source": [
|
|
250
|
+
"# @title Login to Google Cloud & Configure GCP Project\n",
|
|
251
|
+
"# @markdown Please login into Google Cloud and make sure you have joined the EAP for Google AI Edge Portal. Check: https://ai.google.dev/edge/ai-edge-portal\n",
|
|
252
|
+
"# @markdown ---\n",
|
|
253
|
+
"# @markdown **GCP Configuration**\n",
|
|
254
|
+
"# @markdown Please specify your GCP Project ID. If `gcp_bucket` is left blank, a default bucket `<gcp_project>-litert-models` will be used.\n",
|
|
255
|
+
"gcp_project = \"your-own-gcp-project-id\" # @param {type:\"string\"}\n",
|
|
256
|
+
"gcp_bucket = \"\" # @param {type:\"string\"}\n",
|
|
257
|
+
"\n",
|
|
258
|
+
"if not gcp_project or gcp_project == \"your-own-gcp-project-id\":\n",
|
|
259
|
+
" raise ValueError(\"Error: Please specify a valid GCP Project ID in the form above.\")\n",
|
|
260
|
+
"\n",
|
|
261
|
+
"if not gcp_bucket:\n",
|
|
262
|
+
" gcp_bucket = f\"{gcp_project}-litert-models\"\n",
|
|
263
|
+
"\n",
|
|
264
|
+
"print(f\"Configured GCP Project: {gcp_project}\")\n",
|
|
265
|
+
"print(f\"Configured GCS Bucket: gs://{gcp_bucket}\")\n",
|
|
266
|
+
"\n",
|
|
267
|
+
"# Install gcloud and login\n",
|
|
268
|
+
"!pip install gcloud\n",
|
|
269
|
+
"!gcloud auth login\n",
|
|
270
|
+
"\n",
|
|
271
|
+
"# Benchmark ResNet18 on Google AI Edge Portal\n",
|
|
272
|
+
"!litert benchmark resnet18/resnet18.tflite --gcp --device \"pixel 7\" --cpu --gcp-project {gcp_project}\n",
|
|
273
|
+
"!litert benchmark resnet18/resnet18.tflite --gcp --devices \"pixel 7, sm-s931u1\" --gpu --gcp-project {gcp_project} --gcp-bucket {gcp_bucket}\n",
|
|
274
|
+
"\n",
|
|
275
|
+
"# Benchmark EfficientNet on Google AI Edge Portal with CPU and NPU\n",
|
|
276
|
+
"!litert benchmark efficientnet/efficientnet_b1.tflite --gcp --device \"pixel 7\" --cpu --gcp-project {gcp_project}\n",
|
|
277
|
+
"!litert benchmark efficientnet/efficientnet_b1.tflite --gcp --device \"sm-s931u1\" --npu --soc-model SM8750 --gcp-project {gcp_project} --gcp-bucket {gcp_bucket}"
|
|
278
|
+
]
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
"cell_type": "markdown",
|
|
282
|
+
"id": "2685b076",
|
|
283
|
+
"metadata": {},
|
|
284
|
+
"source": [
|
|
285
|
+
"## Advanced Usage\n",
|
|
286
|
+
"\n",
|
|
287
|
+
"### Android Deployment\n",
|
|
288
|
+
"To run or benchmark on Android, you need an ADB connected device. These commands typically look like:\n",
|
|
289
|
+
"```bash\n",
|
|
290
|
+
"# Run on Android\n",
|
|
291
|
+
"!litert run resnet18/resnet18.tflite --android --cpu\n",
|
|
292
|
+
"\n",
|
|
293
|
+
"# Benchmark on Android\n",
|
|
294
|
+
"!litert benchmark resnet18/resnet18.tflite --android\n",
|
|
295
|
+
"```\n",
|
|
296
|
+
"These are not executed in this notebook as Colab does not have access to a physical Android device by default."
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
"metadata": {
|
|
301
|
+
"kernelspec": {
|
|
302
|
+
"display_name": ".venv",
|
|
303
|
+
"language": "python",
|
|
304
|
+
"name": "python3"
|
|
305
|
+
},
|
|
306
|
+
"language_info": {
|
|
307
|
+
"name": "python",
|
|
308
|
+
"version": "3.13.12"
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
"nbformat": 4,
|
|
312
|
+
"nbformat_minor": 5
|
|
313
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright 2026 The LiteRT CLI Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
|
|
16
|
+
# System Preset for SmolLM2
|
|
17
|
+
system_instruction = (
|
|
18
|
+
"You are a concise AI assistant. Answer in two sentences or less."
|
|
19
|
+
)
|
examples/run_cli_demo.sh
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Copyright 2026 The LiteRT CLI Authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
# LiteRT CLI Comprehensive E2E Demo Script
|
|
18
|
+
#
|
|
19
|
+
# Usage:
|
|
20
|
+
# Run all command and model demo scripts sequentially:
|
|
21
|
+
# ./examples/run_cli_demo.sh
|
|
22
|
+
set -e
|
|
23
|
+
|
|
24
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
25
|
+
|
|
26
|
+
echo "=================================================================="
|
|
27
|
+
echo ">>> LiteRT CLI Comprehensive E2E Demo"
|
|
28
|
+
echo "=================================================================="
|
|
29
|
+
|
|
30
|
+
echo -e "\n>>> 1. Running Command-Specific Demos..."
|
|
31
|
+
bash "$SCRIPT_DIR/run_commands.sh" --all
|
|
32
|
+
|
|
33
|
+
echo -e "\n>>> 2. Running Model-Specific Demos..."
|
|
34
|
+
bash "$SCRIPT_DIR/run_models.sh" --all
|
|
35
|
+
|
|
36
|
+
echo -e "\n=================================================================="
|
|
37
|
+
echo ">>> All LiteRT CLI E2E Demos Completed Successfully!"
|
|
38
|
+
echo "=================================================================="
|
examples/run_cli_npu.sh
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Copyright 2026 The LiteRT CLI Authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
# LiteRT CLI NPU Focus Demo Script
|
|
18
|
+
#
|
|
19
|
+
# Usage:
|
|
20
|
+
# Run NPU-focused end-to-end compilation and execution demo:
|
|
21
|
+
# ./examples/run_cli_npu.sh
|
|
22
|
+
set -e
|
|
23
|
+
|
|
24
|
+
# Source shared utilities relative to script
|
|
25
|
+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
|
|
26
|
+
|
|
27
|
+
setup_test_env "npu_test" "NPU Focus Demo" "compile"
|
|
28
|
+
|
|
29
|
+
# --- 1. Download EfficientNet-B1 model ---
|
|
30
|
+
run_case "Download: EfficientNet-B1 from HuggingFace" \
|
|
31
|
+
litert download litert-community/efficientnet_b1 --file "*.tflite" --output "models/efficientnet"
|
|
32
|
+
|
|
33
|
+
EFFICIENTNET_TFLITE="models/efficientnet/efficientnet_b1.tflite"
|
|
34
|
+
|
|
35
|
+
# --- 2. Detect Target SoC ---
|
|
36
|
+
echo -e "\n${YELLOW}Detecting Target SoC from connected device...${NC}"
|
|
37
|
+
if ! has_android_device; then
|
|
38
|
+
echo -e "${YELLOW}No Android device detected or authorized. Skipping on-device NPU execution.${NC}"
|
|
39
|
+
TARGET_SOC="sm8750" # Fallback to default Snapdragon 8 Elite for offline compilation
|
|
40
|
+
else
|
|
41
|
+
# Use python to call our helper function to get the mapped SoC name
|
|
42
|
+
TARGET_SOC=$(python3 -c "from litert_cli.core import npu_utils; print(npu_utils.get_soc_target_model())")
|
|
43
|
+
echo -e "Detected Target SoC: ${GREEN}$TARGET_SOC${NC}"
|
|
44
|
+
|
|
45
|
+
if [ "$TARGET_SOC" == "unknown" ]; then
|
|
46
|
+
echo -e "${YELLOW}Could not map detected SoC to a supported target. Fallback to sm8750.${NC}"
|
|
47
|
+
TARGET_SOC="sm8750"
|
|
48
|
+
else
|
|
49
|
+
# --- 3. Run and Benchmark Original Model on NPU ---
|
|
50
|
+
run_case "Run Original Model on NPU" \
|
|
51
|
+
litert run "$EFFICIENTNET_TFLITE" --android --npu --iterations 1
|
|
52
|
+
|
|
53
|
+
run_case "Benchmark Original Model on NPU" \
|
|
54
|
+
litert benchmark "$EFFICIENTNET_TFLITE" --android --npu
|
|
55
|
+
fi
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
# --- 4. Compile for Detected Target ---
|
|
59
|
+
if [[ "$(uname)" != "Linux" ]]; then
|
|
60
|
+
echo -e "\n${YELLOW}Skipping compilation and dependent tests on non-Linux platform ($(uname)). Offline AOT compilation requires Linux.${NC}"
|
|
61
|
+
print_summary_report "NPU Tests"
|
|
62
|
+
exit 0
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
mkdir -p "models/compiled"
|
|
66
|
+
|
|
67
|
+
run_case "Compile for Target ($TARGET_SOC)" \
|
|
68
|
+
litert compile "$EFFICIENTNET_TFLITE" --target "$TARGET_SOC" --output-dir "models/compiled"
|
|
69
|
+
|
|
70
|
+
# --- 5. Run and Benchmark Compiled Model ---
|
|
71
|
+
if has_android_device; then
|
|
72
|
+
echo -e "\n${YELLOW}Looking for compiled model...${NC}"
|
|
73
|
+
COMPILED_MODEL=$(find "models/compiled" -name "*.tflite" | head -n 1)
|
|
74
|
+
|
|
75
|
+
if [ -z "$COMPILED_MODEL" ]; then
|
|
76
|
+
echo -e "${RED}Error: Compiled model not found.${NC}"
|
|
77
|
+
exit 1
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
echo -e "Found compiled model: ${GREEN}$COMPILED_MODEL${NC}"
|
|
81
|
+
|
|
82
|
+
run_case "Run Compiled Model on NPU" \
|
|
83
|
+
litert run "$COMPILED_MODEL" --android --npu --iterations 1
|
|
84
|
+
|
|
85
|
+
run_case "Benchmark Compiled Model on NPU" \
|
|
86
|
+
litert benchmark "$COMPILED_MODEL" --android --npu
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
print_summary_report "NPU Tests"
|
examples/run_commands.sh
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Copyright 2026 The LiteRT CLI Authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
# LiteRT CLI Command Demo Driver Script
|
|
18
|
+
#
|
|
19
|
+
# Usage:
|
|
20
|
+
# 1. Run all command demo scripts sequentially (default):
|
|
21
|
+
# ./examples/run_commands.sh [ --all ]
|
|
22
|
+
#
|
|
23
|
+
# 2. Run specific command demo scripts (comma-separated):
|
|
24
|
+
# ./examples/run_commands.sh download,compile,quantize
|
|
25
|
+
set -e
|
|
26
|
+
|
|
27
|
+
TARGET_COMMANDS=${1:-"--all"}
|
|
28
|
+
export TARGET_COMMANDS
|
|
29
|
+
|
|
30
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
31
|
+
export LITERT_CLI_SHARED_VENV="true"
|
|
32
|
+
|
|
33
|
+
echo "Running LiteRT CLI command demo(s) with shared virtual environment..."
|
|
34
|
+
|
|
35
|
+
if [ "$TARGET_COMMANDS" == "--all" ] || [ -z "$1" ]; then
|
|
36
|
+
echo "Executing all command test scripts under commands/ directory..."
|
|
37
|
+
for test_script in "$SCRIPT_DIR/commands/"*_test.sh; do
|
|
38
|
+
if [[ "$test_script" == *"benchmark_gcp_test"* ]]; then
|
|
39
|
+
echo -e "\n[Note: $(basename "$test_script") is excluded from default execution. Please run it manually.]\n"
|
|
40
|
+
continue
|
|
41
|
+
fi
|
|
42
|
+
echo -e "\n=================================================================="
|
|
43
|
+
echo ">>> Executing $test_script..."
|
|
44
|
+
echo -e "==================================================================\n"
|
|
45
|
+
bash "$test_script"
|
|
46
|
+
done
|
|
47
|
+
echo -e "\nAll LiteRT CLI command demos completed successfully!"
|
|
48
|
+
else
|
|
49
|
+
# Split comma-separated string into array
|
|
50
|
+
IFS=',' read -ra CMD_ARRAY <<< "$TARGET_COMMANDS"
|
|
51
|
+
|
|
52
|
+
for cmd in "${CMD_ARRAY[@]}"; do
|
|
53
|
+
target_script="$SCRIPT_DIR/commands/${cmd}_test.sh"
|
|
54
|
+
if [ ! -f "$target_script" ]; then
|
|
55
|
+
echo -e "\nError: Command test script not found: $target_script"
|
|
56
|
+
echo "Available command scripts under commands/:"
|
|
57
|
+
ls -1 "$SCRIPT_DIR/commands/"*_test.sh | sed -e "s#.*/##" -e "s#_test.sh##" | sed -e "s/^/ - /"
|
|
58
|
+
exit 1
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
echo -e "\n=================================================================="
|
|
62
|
+
echo ">>> Executing $target_script..."
|
|
63
|
+
echo -e "==================================================================\n"
|
|
64
|
+
bash "$target_script"
|
|
65
|
+
done
|
|
66
|
+
echo -e "\nLiteRT CLI command demo(s) for '$TARGET_COMMANDS' completed successfully!"
|
|
67
|
+
fi
|
examples/run_models.sh
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Copyright 2026 The LiteRT CLI Authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
# LiteRT CLI Model Demo Driver Script
|
|
18
|
+
#
|
|
19
|
+
# Usage:
|
|
20
|
+
# 1. Run all model demos sequentially (default):
|
|
21
|
+
# ./examples/run_models.sh [ --all ]
|
|
22
|
+
#
|
|
23
|
+
# 2. Run specific model demos (comma-separated):
|
|
24
|
+
# ./examples/run_models.sh efficientnet,resnet,yamnet
|
|
25
|
+
set -e
|
|
26
|
+
|
|
27
|
+
TARGET_MODELS=${1:-"--all"}
|
|
28
|
+
export TARGET_MODELS
|
|
29
|
+
|
|
30
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
31
|
+
export LITERT_CLI_SHARED_VENV="true"
|
|
32
|
+
|
|
33
|
+
echo "Running LiteRT CLI model demo(s) with shared virtual environment..."
|
|
34
|
+
|
|
35
|
+
if [ "$TARGET_MODELS" == "--all" ] || [ -z "$1" ]; then
|
|
36
|
+
echo "Executing all model test scripts under models/ directory..."
|
|
37
|
+
for model_script in "$SCRIPT_DIR/models/"*.sh; do
|
|
38
|
+
echo -e "\n=================================================================="
|
|
39
|
+
echo ">>> Executing $model_script..."
|
|
40
|
+
echo -e "==================================================================\n"
|
|
41
|
+
bash "$model_script"
|
|
42
|
+
done
|
|
43
|
+
echo -e "\nAll LiteRT CLI model demos completed successfully!"
|
|
44
|
+
else
|
|
45
|
+
# Split comma-separated string into array
|
|
46
|
+
IFS=',' read -ra MODEL_ARRAY <<< "$TARGET_MODELS"
|
|
47
|
+
|
|
48
|
+
for model in "${MODEL_ARRAY[@]}"; do
|
|
49
|
+
target_script="$SCRIPT_DIR/models/${model}.sh"
|
|
50
|
+
if [ ! -f "$target_script" ]; then
|
|
51
|
+
echo -e "\nError: Model test script not found: $target_script"
|
|
52
|
+
echo "Available model scripts under models/:"
|
|
53
|
+
ls -1 "$SCRIPT_DIR/models/"*.sh | sed -e "s#.*/##" -e "s#.sh##" | sed -e "s/^/ - /"
|
|
54
|
+
exit 1
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
echo -e "\n=================================================================="
|
|
58
|
+
echo ">>> Executing $target_script..."
|
|
59
|
+
echo -e "==================================================================\n"
|
|
60
|
+
bash "$target_script"
|
|
61
|
+
done
|
|
62
|
+
echo -e "\nLiteRT CLI model demo(s) for '$TARGET_MODELS' completed successfully!"
|
|
63
|
+
fi
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Copyright 2026 The LiteRT CLI Authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
set -ex
|
|
18
|
+
|
|
19
|
+
# Get current repo root
|
|
20
|
+
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
21
|
+
echo "Using REPO_ROOT: $REPO_ROOT"
|
|
22
|
+
|
|
23
|
+
# Portable test runner
|
|
24
|
+
export LITERT_CLI_SMOKE_TEST_ROOT="/tmp/litert_cli_smoke_test"
|
|
25
|
+
rm -rf "$LITERT_CLI_SMOKE_TEST_ROOT"
|
|
26
|
+
mkdir -p "$LITERT_CLI_SMOKE_TEST_ROOT"
|
|
27
|
+
cd "$LITERT_CLI_SMOKE_TEST_ROOT"
|
|
28
|
+
pwd
|
|
29
|
+
|
|
30
|
+
# Create venv
|
|
31
|
+
python3 -m venv venv_smoke_test
|
|
32
|
+
source venv_smoke_test/bin/activate
|
|
33
|
+
|
|
34
|
+
# Upgrade setuptools and pip to satisfy PEP 517 build requirements
|
|
35
|
+
pip install -i https://pypi.org/simple --upgrade pip setuptools wheel
|
|
36
|
+
|
|
37
|
+
# Install package with optional dependencies
|
|
38
|
+
cd "$REPO_ROOT"
|
|
39
|
+
pip install -i https://pypi.org/simple -e .[test,lm]
|
|
40
|
+
|
|
41
|
+
# Set PYTHONPATH dynamically to resolve internal root and litert_cli imports
|
|
42
|
+
INTERNAL_ROOT="$(cd "$REPO_ROOT/../../../../" && pwd)"
|
|
43
|
+
export PYTHONPATH="$INTERNAL_ROOT:$PYTHONPATH"
|
|
44
|
+
|
|
45
|
+
# Run a subset of CLI commands to verify they load
|
|
46
|
+
litert --help
|
|
47
|
+
litert download --help
|
|
48
|
+
litert quantize --help
|
|
49
|
+
litert run --help
|
|
50
|
+
litert benchmark --help
|
|
51
|
+
litert lm --help
|
|
52
|
+
litert clean --help
|
|
53
|
+
|
|
54
|
+
# Find and run all tests automatically in litert_cli directory
|
|
55
|
+
for test_file in $(find litert_cli -name "*_test.py"); do
|
|
56
|
+
echo "Running test: $test_file"
|
|
57
|
+
python3 "$test_file"
|
|
58
|
+
done
|