Skip to content

Commit abe98b8

Browse files
Merge pull request #46 from google-ai-edge:refactor/setup-instructions-and-robust-venv
PiperOrigin-RevId: 918011862
2 parents 3ad54d1 + 4d72148 commit abe98b8

4 files changed

Lines changed: 73 additions & 6 deletions

File tree

examples/commands/convert_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ run_case "Convert: Qwen1.5-0.5B-Chat without Bundle" \
5959

6060
# 2.4 Non-CausalLM Architecture Rejection
6161
run_case "Convert: bert-base-uncased (Verify Non-CausalLM Rejection)" \
62-
bash -c "litert convert google-bert/bert-base-uncased --output 'models/bert_fail' 2>&1 | grep -q 'Currently only AutoModelForCausalLM is supported'"
62+
bash -c "litert convert google-bert/bert-base-uncased --output 'models/bert_fail' 2>&1 | grep -q 'CausalLM'"
6363

6464
# --- Summary Report ---
6565
print_summary_report "Convert Commands"

examples/models/gemma3.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 Gemma3 LLM Demo & Test Script
18+
set -e
19+
20+
# Source shared utilities relative to script
21+
source "$(dirname "${BASH_SOURCE[0]}")/../utils.sh"
22+
23+
setup_test_env "gemma3" "Gemma3 LLM Demo Script"
24+
25+
# --- Part 1: Convert from HuggingFace Hub, then Run & Benchmark ---
26+
# Convert HuggingFace Model google/gemma-3-1b-it
27+
run_case "Convert: HuggingFace google/gemma-3-1b-it" \
28+
litert convert google/gemma-3-1b-it --output "models/gemma3_converted"
29+
30+
# Run the converted model
31+
run_case "Run Gemma3: Converted Model" \
32+
litert lm run "models/gemma3_converted/model.litertlm" --prompt="What is the capital of France?"
33+
34+
# Benchmark the converted model
35+
run_case "Benchmark Gemma3: Converted Model" \
36+
litert lm benchmark "models/gemma3_converted/model.litertlm" -p 128 -d 128
37+
38+
39+
# --- Part 2: Directly Download, Run, and Benchmark Pre-converted Model ---
40+
# Run pre-converted Gemma3 directly from huggingface repo
41+
run_case "Run Gemma3: Direct HuggingFace execution" \
42+
litert lm run \
43+
--from-huggingface-repo=litert-community/Gemma3-1B-IT \
44+
gemma3-1b-it-int4.litertlm \
45+
--prompt="What is the capital of France?"
46+
47+
# Benchmark pre-converted Gemma3 directly
48+
run_case "Benchmark Gemma3: Direct HuggingFace execution" \
49+
litert lm benchmark \
50+
--from-huggingface-repo=litert-community/Gemma3-1B-IT \
51+
gemma3-1b-it-int4.litertlm \
52+
-p 128 -d 128
53+
54+
# --- Summary Report ---
55+
print_summary_report "Gemma3"

examples/models/gemma4.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ source "$(dirname "${BASH_SOURCE[0]}")/../utils.sh"
2323

2424
setup_test_env "gemma4" "Gemma4 LLM Demo Script"
2525

26-
# --- 1. Convert HuggingFace Model google/gemma-4-E2B-it ---
27-
# Wait for LiteRT Torch release.
28-
# run_case "Convert: HuggingFace google/gemma-4-E2B-it" \
29-
# litert convert google/gemma-4-E2B-it --output "models/gemma4"
26+
# --- 1. Convert and run HuggingFace Model google/gemma-4-E2B-it ---
27+
run_case "Convert: HuggingFace google/gemma-4-E2B-it" \
28+
litert convert google/gemma-4-E2B-it --output "models/gemma4"
3029

31-
# --- 2. Run Gemma4 Generative LLM Model ---
30+
run_case "Run converted Gemma4 model google/gemma-4-E2B-it" \
31+
litert lm run models/gemma4/model.litertlm --prompt="What is the capital of France?"
32+
33+
# --- 2. Download and Run existing Gemma4 Model from HuggingFace ---
3234
run_case "Run Gemma4: Generative inference with custom prompt" \
3335
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?"
3436

litert_cli/commands/convert/huggingface.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def convert_huggingface(
6262
click.echo(f"Starting conversion for model '{model}''")
6363

6464
try:
65+
is_causal_lm = False
66+
is_gemma3 = False
67+
is_gemma3n = False
68+
is_gemma4 = False
69+
is_gemma_vlm = False
70+
6571
# Verify AutoModelForCausalLM architecture
6672
try:
6773
config = transformers.AutoConfig.from_pretrained(
@@ -103,6 +109,10 @@ def convert_huggingface(
103109
task = "image_text_to_text"
104110
export_kwargs["export_vision_encoder"] = True
105111
export_kwargs["externalize_embedder"] = True
112+
if is_gemma3 or is_gemma3n:
113+
export_kwargs["vision_encoder_quantization_recipe"] = (
114+
"weight_only_wi8_afp32"
115+
)
106116
if is_gemma4:
107117
export_kwargs["jinja_chat_template_override"] = (
108118
"litert-community/gemma-4-E2B-it-litert-lm"

0 commit comments

Comments
 (0)