Skip to content

Commit 0e69758

Browse files
Merge pull request #11 from google-ai-edge:cleanup-copyright
PiperOrigin-RevId: 913290422
2 parents 929db22 + 3f4e1e3 commit 0e69758

1 file changed

Lines changed: 63 additions & 39 deletions

File tree

test_scripts/litert_cli.ipynb

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
{
22
"cells": [
3+
{
4+
"id": "cdbfc46c",
5+
"cell_type": "raw",
6+
"source": [
7+
"# Copyright 2026 The LiteRT CLI Authors.\n",
8+
"#\n",
9+
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
10+
"# you may not use this file except in compliance with the License.\n",
11+
"# You may obtain a copy of the License at\n",
12+
"#\n",
13+
"# http://www.apache.org/licenses/LICENSE-2.0\n",
14+
"#\n",
15+
"# Unless required by applicable law or agreed to in writing, software\n",
16+
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
17+
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
18+
"# See the License for the specific language governing permissions and\n",
19+
"# limitations under the License.\n",
20+
"# =============================================================================="
21+
],
22+
"metadata": {},
23+
"execution_count": null
24+
},
325
{
426
"id": "90c3deda",
527
"cell_type": "markdown",
@@ -8,15 +30,17 @@
830
"\n",
931
"This notebook demonstrates how to use the `litert-cli` tool to convert a PyTorch model, quantize it and run it."
1032
],
11-
"metadata": {}
33+
"metadata": {},
34+
"execution_count": null
1235
},
1336
{
1437
"id": "19270446",
1538
"cell_type": "markdown",
1639
"source": [
17-
"## \ud83d\udee0\ufe0f 1. Environment Setup & Installation"
40+
"## 🛠️ 1. Environment Setup \u0026 Installation"
1841
],
19-
"metadata": {}
42+
"metadata": {},
43+
"execution_count": null
2044
},
2145
{
2246
"id": "d34739df",
@@ -34,16 +58,16 @@
3458
"!sudo ./llvm.sh 18 all"
3559
],
3660
"metadata": {},
37-
"execution_count": null,
38-
"outputs": []
61+
"execution_count": null
3962
},
4063
{
4164
"id": "1dd1eb34",
4265
"cell_type": "markdown",
4366
"source": [
44-
"## \ud83d\udcdd 2. Prepare PyTorch Model Script"
67+
"## 📝 2. Prepare PyTorch Model Script"
4568
],
46-
"metadata": {}
69+
"metadata": {},
70+
"execution_count": null
4771
},
4872
{
4973
"id": "5e40f66c",
@@ -53,27 +77,27 @@
5377
"import torch\n",
5478
"import torchvision\n",
5579
"\n",
56-
"def get_model() -> torch.nn.Module:\n",
80+
"def get_model() -\u003e torch.nn.Module:\n",
5781
" model = torchvision.models.resnet18(\n",
5882
" weights=torchvision.models.ResNet18_Weights.IMAGENET1K_V1\n",
5983
" )\n",
6084
" model.eval()\n",
6185
" return model\n",
6286
"\n",
63-
"def get_args() -> tuple[torch.Tensor, ...]:\n",
87+
"def get_args() -\u003e tuple[torch.Tensor, ...]:\n",
6488
" return (torch.randn(1, 3, 224, 224),)"
6589
],
6690
"metadata": {},
67-
"execution_count": null,
68-
"outputs": []
91+
"execution_count": null
6992
},
7093
{
7194
"id": "427dca8a",
7295
"cell_type": "markdown",
7396
"source": [
74-
"## \ud83d\udd04 3. Model Conversion (PyTorch -> LiteRT)"
97+
"## 🔄 3. Model Conversion (PyTorch -\u003e LiteRT)"
7598
],
76-
"metadata": {}
99+
"metadata": {},
100+
"execution_count": null
77101
},
78102
{
79103
"id": "578cc653",
@@ -83,16 +107,16 @@
83107
"!litert convert resnet18.py --output resnet18"
84108
],
85109
"metadata": {},
86-
"execution_count": null,
87-
"outputs": []
110+
"execution_count": null
88111
},
89112
{
90113
"id": "606efd4f",
91114
"cell_type": "markdown",
92115
"source": [
93-
"## \ud83d\udcc9 4. Model Quantization"
116+
"## 📉 4. Model Quantization"
94117
],
95-
"metadata": {}
118+
"metadata": {},
119+
"execution_count": null
96120
},
97121
{
98122
"id": "c589c711",
@@ -103,17 +127,17 @@
103127
"!litert quantize resnet18/resnet18.tflite --type int8_weight_only --output resnet18/resnet18_int8_weight_only.tflite"
104128
],
105129
"metadata": {},
106-
"execution_count": null,
107-
"outputs": []
130+
"execution_count": null
108131
},
109132
{
110133
"id": "b3ae9ddc",
111134
"cell_type": "markdown",
112135
"source": [
113-
"## \ud83d\ude80 5. Run Inference\n",
114-
"### \ud83d\udda5\ufe0f 5.1 CPU Inference"
136+
"## 🚀 5. Run Inference\n",
137+
"### 🖥️ 5.1 CPU Inference"
115138
],
116-
"metadata": {}
139+
"metadata": {},
140+
"execution_count": null
117141
},
118142
{
119143
"id": "ea93a1db",
@@ -124,16 +148,16 @@
124148
"!litert run resnet18/resnet18_int8_dynamic.tflite --desktop --cpu --iterations 1"
125149
],
126150
"metadata": {},
127-
"execution_count": null,
128-
"outputs": []
151+
"execution_count": null
129152
},
130153
{
131154
"id": "9d748475",
132155
"cell_type": "markdown",
133156
"source": [
134-
"### \ud83c\udfae 5.2 GPU Inference"
157+
"### 🎮 5.2 GPU Inference"
135158
],
136-
"metadata": {}
159+
"metadata": {},
160+
"execution_count": null
137161
},
138162
{
139163
"id": "00b026b2",
@@ -144,16 +168,16 @@
144168
"!litert run resnet18/resnet18_int8_dynamic.tflite --desktop --gpu --iterations 1"
145169
],
146170
"metadata": {},
147-
"execution_count": null,
148-
"outputs": []
171+
"execution_count": null
149172
},
150173
{
151174
"id": "eaa972bc",
152175
"cell_type": "markdown",
153176
"source": [
154-
"## \u2699\ufe0f 6. NPU Offline Compilation (AOT)"
177+
"## ⚙️ 6. NPU Offline Compilation (AOT)"
155178
],
156-
"metadata": {}
179+
"metadata": {},
180+
"execution_count": null
157181
},
158182
{
159183
"id": "d0a61181",
@@ -163,24 +187,24 @@
163187
"# TIP: Only support running on Linux and it might take a few minutes, given download large SDKs from SOCs.\n",
164188
"# TIP: It depends on Clang, and please make sure your Clang has version `18.x.x` or above when running\n",
165189
"# `clang --version`. To update, choose one of below: \n",
166-
"# a) `sudo apt update && sudo apt upgrade -y`\n",
190+
"# a) `sudo apt update \u0026\u0026 sudo apt upgrade -y`\n",
167191
"# b) wget https://apt.llvm.org/llvm.sh\n",
168192
"# chmod +x llvm.sh\n",
169193
"# sudo ./llvm.sh 18 all\n",
170194
"#\n",
171195
"!litert compile resnet18/resnet18.tflite --target sm8750"
172196
],
173197
"metadata": {},
174-
"execution_count": null,
175-
"outputs": []
198+
"execution_count": null
176199
},
177200
{
178201
"id": "2da953c9",
179202
"cell_type": "markdown",
180203
"source": [
181-
"## \ud83c\udfc1 7. Benchmark in Google AI Edge Portal"
204+
"## 🏁 7. Benchmark in Google AI Edge Portal"
182205
],
183-
"metadata": {}
206+
"metadata": {},
207+
"execution_count": null
184208
},
185209
{
186210
"id": "a9a19e48",
@@ -192,15 +216,14 @@
192216
"!gcloud auth login\n",
193217
"\n",
194218
"# Benchmark on Google AI Edge Portal\n",
195-
"# Please specify you own GCP project: --gcp-project <your-own-gcp-project-id>\n",
219+
"# Please specify you own GCP project: --gcp-project \u003cyour-own-gcp-project-id\u003e\n",
196220
"# Or set a default environment variable: LITERT_GCP_PROJECT\n",
197221
"!litert benchmark model.tflite --gcp --device \"pixel 7\" --cpu --gcp-project aep-e2e-test\n",
198222
"!litert benchmark model.tflite --gcp --device \"pixel 7\" --gpu --gcp-project aep-e2e-test\n",
199223
"!litert benchmark model.tflite --gcp --devices \"pixel 7, sm-s931u1\" --gpu"
200224
],
201225
"metadata": {},
202-
"execution_count": null,
203-
"outputs": []
226+
"execution_count": null
204227
},
205228
{
206229
"id": "2685b076",
@@ -219,7 +242,8 @@
219242
"```\n",
220243
"These are not executed in this notebook as Colab does not have access to a physical Android device by default."
221244
],
222-
"metadata": {}
245+
"metadata": {},
246+
"execution_count": null
223247
}
224248
],
225249
"metadata": {

0 commit comments

Comments
 (0)