Skip to content

Commit 020d843

Browse files
Merge pull request #14 from google-ai-edge:test_windows_0511
PiperOrigin-RevId: 913950211
2 parents 6bd1363 + 841da8e commit 020d843

5 files changed

Lines changed: 700 additions & 0 deletions

File tree

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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+
# LiteRT CLI EfficientNet Demo & Test Script for Windows
17+
18+
# --- Environment Setup ---
19+
$SCRIPT_DIR = $PSScriptRoot
20+
$REPO_ROOT = (Resolve-Path "$SCRIPT_DIR/../..").Path
21+
$LITERT_CLI_ROOT = Join-Path $env:TEMP "litert_cli_efficientnet"
22+
23+
# Source shared utilities
24+
. (Join-Path $SCRIPT_DIR "utils.ps1")
25+
26+
Write-Host "${BLUE}${BOLD}==================================================================${NC}"
27+
Write-Host "${BLUE}${BOLD}>>> LiteRT CLI EfficientNet Demo Script${NC}"
28+
Write-Host "${BLUE}${BOLD}==================================================================${NC}"
29+
30+
# Clean up and create work directory
31+
Write-Host ""
32+
Write-Host "${YELLOW}Setting up workspace at: $LITERT_CLI_ROOT...${NC}"
33+
if (Test-Path $LITERT_CLI_ROOT) {
34+
Remove-Item -Recurse -Force $LITERT_CLI_ROOT
35+
}
36+
New-Item -ItemType Directory -Force -Path $LITERT_CLI_ROOT | Out-Null
37+
Set-Location $LITERT_CLI_ROOT
38+
39+
# Create Python virtual environment
40+
Write-Host "${YELLOW}Creating Python virtual environment...${NC}"
41+
python -m venv venv_efficientnet
42+
. .\venv_efficientnet\Scripts\Activate.ps1
43+
44+
# Create output directories
45+
$MODEL_DIR = Join-Path $LITERT_CLI_ROOT "models"
46+
New-Item -ItemType Directory -Force -Path $MODEL_DIR | Out-Null
47+
48+
# Test data directory
49+
$TEST_DATA_DIR = "$REPO_ROOT/litert_cli/test_data"
50+
51+
# Install litert-cli from source
52+
Write-Host "${YELLOW}Installing litert-cli from source...${NC}"
53+
pip install -e "$REPO_ROOT"
54+
55+
# --- 1. Download EfficientNet-B1 model ---
56+
Run-Case "Download: EfficientNet-B1 from HuggingFace" {
57+
litert download litert-community/efficientnet_b1 --file "*.tflite" --output "$MODEL_DIR/efficientnet"
58+
}
59+
60+
# Verify the downloaded model exists
61+
$EFFICIENTNET_TFLITE = Join-Path $MODEL_DIR "efficientnet/efficientnet_b1.tflite"
62+
if (-not (Test-Path $EFFICIENTNET_TFLITE -PathType Leaf)) {
63+
Write-Host "${RED}Error: Downloaded model not found at $EFFICIENTNET_TFLITE${NC}"
64+
Exit 1
65+
}
66+
67+
# --- 2. Quantize the EfficientNet model ---
68+
Run-Case "Quantize: EfficientNet Dynamic Range INT8" {
69+
litert quantize "$EFFICIENTNET_TFLITE" --type int8_dynamic --output "$MODEL_DIR/efficientnet/efficientnet_b1_int8_dynamic.tflite"
70+
}
71+
72+
Run-Case "Quantize: EfficientNet Weight-Only INT8" {
73+
litert quantize "$EFFICIENTNET_TFLITE" --type int8_weight_only --output "$MODEL_DIR/efficientnet/efficientnet_b1_int8_weight_only.tflite"
74+
}
75+
76+
# --- 3. Run Inference (Desktop & Android) ---
77+
# Run-Case "Run: EfficientNet FP32 on Desktop (CPU)" {
78+
# litert run "$EFFICIENTNET_TFLITE" --desktop --cpu --iterations 1
79+
# }
80+
81+
if (Has-DesktopGpu "$EFFICIENTNET_TFLITE") {
82+
Run-Case "Run: EfficientNet FP32 on Desktop (GPU)" {
83+
litert run "$EFFICIENTNET_TFLITE" --desktop --gpu --iterations 1
84+
}
85+
} else {
86+
Write-Host ""
87+
Write-Host "${YELLOW}Desktop GPU delegate is not supported. Skipping Desktop GPU run.${NC}"
88+
}
89+
90+
# Run-Case "Run: EfficientNet Dynamic INT8 on Desktop (CPU)" {
91+
# litert run "$MODEL_DIR/efficientnet/efficientnet_b1_int8_dynamic.tflite" --desktop --cpu --iterations 1
92+
# }
93+
94+
if (Has-AndroidDevice) {
95+
Write-Host ""
96+
Write-Host "${GREEN}Android device detected. Running Android inference...${NC}"
97+
Run-Case "Run: EfficientNet FP32 on Android (CPU)" {
98+
litert run "$EFFICIENTNET_TFLITE" --android --cpu --iterations 1
99+
}
100+
101+
Run-Case "Run: EfficientNet FP32 on Android (GPU)" {
102+
litert run "$EFFICIENTNET_TFLITE" --android --gpu --iterations 1
103+
}
104+
105+
# If you have Android devices with NPU connected, enable those use cases.
106+
# Run-Case "Run: EfficientNet FP32 on Android (NPU)" {
107+
# litert run "$EFFICIENTNET_TFLITE" --android --npu --iterations 1
108+
# }
109+
110+
Run-Case "Run: EfficientNet Dynamic INT8 on Android (CPU)" {
111+
litert run "$MODEL_DIR/efficientnet/efficientnet_b1_int8_dynamic.tflite" --android --cpu --iterations 1
112+
}
113+
}
114+
115+
# --- 4. Benchmark (Android) ---
116+
if (Has-AndroidDevice) {
117+
Write-Host ""
118+
Write-Host "${GREEN}Android device detected. Running Android benchmarks...${NC}"
119+
Run-Case "Benchmark: EfficientNet FP32 on Android (CPU)" {
120+
litert benchmark "$EFFICIENTNET_TFLITE" --android
121+
}
122+
123+
Run-Case "Benchmark: EfficientNet FP32 on Android (GPU)" {
124+
litert benchmark "$EFFICIENTNET_TFLITE" --android --gpu
125+
}
126+
127+
# If you have Android devices with NPU connected, enable those use cases.
128+
# Run-Case "Benchmark: EfficientNet FP32 on Android (NPU)" {
129+
# litert benchmark "$EFFICIENTNET_TFLITE" --android --npu
130+
# }
131+
132+
Run-Case "Benchmark: EfficientNet Dynamic INT8 on Android" {
133+
litert benchmark "$MODEL_DIR/efficientnet/efficientnet_b1_int8_dynamic.tflite" --android
134+
}
135+
} else {
136+
Write-Host ""
137+
Write-Host "${YELLOW}No Android device detected. Skipping benchmarks on Android.${NC}"
138+
}
139+
140+
# --- 5. Compile (AOT Compilation) ---
141+
# Run-Case "Compile: EfficientNet FP32 for Qualcomm sm8750 NPU" {
142+
# litert compile "$EFFICIENTNET_TFLITE" --target sm8750 --output-dir "$MODEL_DIR/efficientnet"
143+
# }
144+
# Run-Case "Compile: EfficientNet FP32 for MediaTek MT6993 NPU" {
145+
# litert compile "$EFFICIENTNET_TFLITE" --target MT6993 --output-dir "$MODEL_DIR/efficientnet"
146+
# }
147+
148+
# --- 6. Benchmark compiled model ---
149+
# Enable those use cases, or change to your own targets, if you have connected those android
150+
# devices through NPU.
151+
#
152+
# Run-Case "Run Qualcomm compiled EfficientNet" {
153+
# litert run "$MODEL_DIR/efficientnet/efficientnet_b1_Qualcomm_SM8750.tflite" --android --npu
154+
# }
155+
# Run-Case "Benchmark Qualcomm compiled EfficientNet" {
156+
# litert benchmark "$MODEL_DIR/efficientnet/efficientnet_b1_Qualcomm_SM8750.tflite" --android --npu
157+
# }
158+
159+
# Run-Case "Run MediaTek compiled EfficientNet" {
160+
# litert run "$MODEL_DIR/efficientnet/efficientnet_b1_MediaTek_MT6993.tflite" --android --npu
161+
# }
162+
# Run-Case "Benchmark MediaTek compiled EfficientNet" {
163+
# litert benchmark "$MODEL_DIR/efficientnet/efficientnet_b1_MediaTek_MT6993.tflite" --android --npu
164+
# }
165+
166+
# --- 7. Visualize (Model Explorer) ---
167+
# Run-Case "Visualize: Launch Model Explorer in the background" {
168+
# litert visualize "$EFFICIENTNET_TFLITE"
169+
# }
170+
171+
# Run-Case "Visualize: Stop all Model Explorer servers" {
172+
# litert visualize --stop-all
173+
# }
174+
175+
# --- Summary Report ---
176+
Print-SummaryReport "EfficientNet"

test_scripts/models/gemma4.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
# LiteRT CLI Gemma4 LLM Demo & Test Script for Windows
17+
18+
# --- Environment Setup ---
19+
$SCRIPT_DIR = $PSScriptRoot
20+
$REPO_ROOT = (Resolve-Path "$SCRIPT_DIR/../..").Path
21+
$LITERT_CLI_ROOT = Join-Path $env:TEMP "litert_cli_gemma4"
22+
23+
# Source shared utilities
24+
. (Join-Path $SCRIPT_DIR "utils.ps1")
25+
26+
Write-Host "${BLUE}${BOLD}==================================================================${NC}"
27+
Write-Host "${BLUE}${BOLD}>>> LiteRT CLI Gemma4 LLM Demo Script${NC}"
28+
Write-Host "${BLUE}${BOLD}==================================================================${NC}"
29+
30+
# Clean up and create work directory
31+
Write-Host ""
32+
Write-Host "${YELLOW}Setting up workspace at: $LITERT_CLI_ROOT...${NC}"
33+
if (Test-Path $LITERT_CLI_ROOT) {
34+
Remove-Item -Recurse -Force $LITERT_CLI_ROOT
35+
}
36+
New-Item -ItemType Directory -Force -Path $LITERT_CLI_ROOT | Out-Null
37+
Set-Location $LITERT_CLI_ROOT
38+
39+
# Create Python virtual environment
40+
Write-Host "${YELLOW}Creating Python virtual environment...${NC}"
41+
python -m venv venv_gemma4
42+
. .\venv_gemma4\Scripts\Activate.ps1
43+
44+
# Create output directories
45+
$MODEL_DIR = Join-Path $LITERT_CLI_ROOT "models"
46+
New-Item -ItemType Directory -Force -Path $MODEL_DIR | Out-Null
47+
48+
# Install litert-cli from source
49+
Write-Host "${YELLOW}Installing litert-cli from source...${NC}"
50+
pip install -e "$REPO_ROOT"
51+
52+
# --- 1. Convert HuggingFace Model google/gemma-4-E2B-it ---
53+
# TODO: Bring this back when we add support for --externalize_embedder in CLI convert command.
54+
# Run-Case "Convert: HuggingFace google/gemma-4-E2B-it" {
55+
# litert convert google/gemma-4-E2B-it --output "$MODEL_DIR/gemma4"
56+
# }
57+
58+
# --- 2. Run Gemma4 Generative LLM Model ---
59+
Run-Case "Run Gemma4: Generative inference with custom prompt" {
60+
litert lm run --from-huggingface-repo=litert-community/gemma-4-E2B-it-litert-lm gemma-4-E2B-it.litertlm --prompt="What is the capital of France?"
61+
}
62+
63+
# --- 3. Benchmark Gemma4 LLM Model ---
64+
Run-Case "Benchmark Gemma4: Local benchmark of LLM generation" {
65+
litert lm benchmark gemma-4-E2B-it.litertlm --from-huggingface-repo=litert-community/gemma-4-E2B-it-litert-lm -p 128 -d 128
66+
}
67+
68+
# --- Summary Report ---
69+
Print-SummaryReport "Gemma4"

test_scripts/models/resnet.ps1

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
# LiteRT CLI ResNet Demo & Test Script for Windows
17+
18+
# --- Environment Setup ---
19+
$SCRIPT_DIR = $PSScriptRoot
20+
$REPO_ROOT = (Resolve-Path "$SCRIPT_DIR/../..").Path
21+
$LITERT_CLI_ROOT = Join-Path $env:TEMP "litert_cli_resnet"
22+
23+
# Source shared utilities
24+
. (Join-Path $SCRIPT_DIR "utils.ps1")
25+
26+
Write-Host "${BLUE}${BOLD}==================================================================${NC}"
27+
Write-Host "${BLUE}${BOLD}>>> LiteRT CLI ResNet Demo Script${NC}"
28+
Write-Host "${BLUE}${BOLD}==================================================================${NC}"
29+
30+
# Clean up and create work directory
31+
Write-Host ""
32+
Write-Host "${YELLOW}Setting up workspace at: $LITERT_CLI_ROOT...${NC}"
33+
if (Test-Path $LITERT_CLI_ROOT) {
34+
Remove-Item -Recurse -Force $LITERT_CLI_ROOT
35+
}
36+
New-Item -ItemType Directory -Force -Path $LITERT_CLI_ROOT | Out-Null
37+
Set-Location $LITERT_CLI_ROOT
38+
39+
# Create Python virtual environment
40+
Write-Host "${YELLOW}Creating Python virtual environment...${NC}"
41+
python -m venv venv_resnet
42+
. .\venv_resnet\Scripts\Activate.ps1
43+
44+
# Create output directories
45+
$MODEL_DIR = Join-Path $LITERT_CLI_ROOT "models"
46+
New-Item -ItemType Directory -Force -Path $MODEL_DIR | Out-Null
47+
48+
# Test data directory
49+
$TEST_DATA_DIR = "$REPO_ROOT/litert_cli/test_data"
50+
51+
# Install litert-cli from source
52+
Write-Host "${YELLOW}Installing litert-cli from source...${NC}"
53+
pip install -e "$REPO_ROOT"
54+
55+
# --- 1. Convert PyTorch ResNet18 model to LiteRT ---
56+
Run-Case "Convert: PyTorch ResNet18 to LiteRT" {
57+
litert convert "$TEST_DATA_DIR/resnet18.py" --output "$MODEL_DIR/resnet18"
58+
}
59+
60+
# Verify the converted model exists
61+
$RESNET_TFLITE = Join-Path $MODEL_DIR "resnet18/resnet18.tflite"
62+
if (-not (Test-Path $RESNET_TFLITE -PathType Leaf)) {
63+
Write-Host "${RED}Error: Converted model not found at $RESNET_TFLITE${NC}"
64+
Exit 1
65+
}
66+
67+
# --- 2. Quantize the ResNet18 model ---
68+
Run-Case "Quantize: ResNet18 Dynamic Range INT8" {
69+
litert quantize "$RESNET_TFLITE" --type int8_dynamic --output "$MODEL_DIR/resnet18/resnet18_int8_dynamic.tflite"
70+
}
71+
72+
Run-Case "Quantize: ResNet18 Weight-Only INT8" {
73+
litert quantize "$RESNET_TFLITE" --type int8_weight_only --output "$MODEL_DIR/resnet18/resnet18_int8_weight_only.tflite"
74+
}
75+
76+
# --- 3. Run Inference (Desktop & Android) ---
77+
Run-Case "Run: ResNet18 FP32 on Desktop (CPU)" {
78+
litert run "$RESNET_TFLITE" --desktop --cpu --iterations 1
79+
}
80+
81+
if (Has-DesktopGpu "$RESNET_TFLITE") {
82+
Run-Case "Run: ResNet18 FP32 on Desktop (GPU)" {
83+
litert run "$RESNET_TFLITE" --desktop --gpu --iterations 1
84+
}
85+
} else {
86+
Write-Host ""
87+
Write-Host "${YELLOW}Desktop GPU delegate is not supported. Skipping Desktop GPU run.${NC}"
88+
}
89+
90+
Run-Case "Run: ResNet18 Dynamic INT8 on Desktop (CPU)" {
91+
litert run "$MODEL_DIR/resnet18/resnet18_int8_dynamic.tflite" --desktop --cpu --iterations 1
92+
}
93+
94+
if (Has-AndroidDevice) {
95+
Write-Host ""
96+
Write-Host "${GREEN}Android device detected. Running Android inference...${NC}"
97+
Run-Case "Run: ResNet18 FP32 on Android (CPU)" {
98+
litert run "$RESNET_TFLITE" --android --cpu --iterations 1
99+
}
100+
101+
Run-Case "Run: ResNet18 FP32 on Android (GPU)" {
102+
litert run "$RESNET_TFLITE" --android --gpu --iterations 1
103+
}
104+
105+
Run-Case "Run: ResNet18 Dynamic INT8 on Android (CPU)" {
106+
litert run "$MODEL_DIR/resnet18/resnet18_int8_dynamic.tflite" --android --cpu --iterations 1
107+
}
108+
}
109+
110+
# --- 4. Benchmark (Android) ---
111+
if (Has-AndroidDevice) {
112+
Write-Host ""
113+
Write-Host "${GREEN}Android device detected. Running Android benchmarks...${NC}"
114+
Run-Case "Benchmark: ResNet18 FP32 on Android (CPU)" {
115+
litert benchmark "$RESNET_TFLITE" --android
116+
}
117+
118+
Run-Case "Benchmark: ResNet18 FP32 on Android (GPU)" {
119+
litert benchmark "$RESNET_TFLITE" --android --gpu
120+
}
121+
122+
Run-Case "Benchmark: ResNet18 Dynamic INT8 on Android" {
123+
litert benchmark "$MODEL_DIR/resnet18/resnet18_int8_dynamic.tflite" --android
124+
}
125+
} else {
126+
Write-Host ""
127+
Write-Host "${YELLOW}No Android device detected. Skipping benchmarks (litert benchmark only supports Android/GCP).${NC}"
128+
}
129+
130+
# --- 5. Compile (AOT Compilation) ---
131+
Run-Case "Compile: ResNet18 FP32 for Qualcomm sm8750 NPU" {
132+
litert compile "$RESNET_TFLITE" --target sm8750 --output-dir "$MODEL_DIR/resnet18"
133+
}
134+
135+
# --- 6. Visualize (Model Explorer) ---
136+
# Run-Case "Visualize: Launch Model Explorer in the background" {
137+
# litert visualize "$RESNET_TFLITE"
138+
# }
139+
140+
# Run-Case "Visualize: Stop all Model Explorer servers" {
141+
# litert visualize --stop-all
142+
# }
143+
144+
# --- Summary Report ---
145+
Print-SummaryReport "ResNet"

0 commit comments

Comments
 (0)