|
| 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" |
0 commit comments