Skip to content

Commit 3ad54d1

Browse files
Merge pull request #45 from google-ai-edge:refactor/setup-instructions-and-robust-venv
PiperOrigin-RevId: 917926900
2 parents 0bab170 + 9122e9e commit 3ad54d1

3 files changed

Lines changed: 38 additions & 54 deletions

File tree

.agents/skills/litert_cli/SKILL.md

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,41 @@ This skill allows the agent to download, convert, quantize, run, benchmark, and
99
visualize LiteRT models using the `litert` command on desktop, device, or Google
1010
Cloud.
1111

12-
## Setup & Prerequisites
12+
## Setup & Prerequisites (Agent Auto-Setup Guide)
1313

14-
Before running any `litert` commands, an agent should ensure it is in a Python
15-
virtual environment and `litert-cli` is installed.
14+
When an agent invokes this skill, they **MUST** automatically verify the environment and install dependencies using the following logical workflow. Do not prompt the user; perform these checks and setup steps proactively:
1615

17-
### 1. Check/Create Virtual Environment
16+
### Step 1. Check if `litert` is already installed
1817

19-
We highly recommend using **`uv`** (written in Rust) for extremely fast environment management and package installs.
18+
First, check if the `litert` command-line tool is already available and
19+
functioning: `bash litert --help` If this succeeds, you can **skip the remaining
20+
setup steps** and proceed directly to executing commands!
2021

21-
**Option A: Use UV (Recommended - Super Fast):**
22-
```bash
23-
24-
# Create a virtual environment with Python 3.13.
25-
26-
# We use --seed to pre-install pip, setuptools, and wheel inside the venv.
27-
28-
# This is critical to allow our CLI dynamic dependency auto-installers (deps.py) to function.
29-
30-
# When meeting dependency resolution error, try to set environment variable:
22+
### Step 2. Verify or create a Python Virtual Environment
3123

32-
# UV_INDEX_URL=https://pypi.org/simple
24+
If `litert` is not found, check if a Python virtual environment is currently active (e.g., by checking if the `$VIRTUAL_ENV` environment variable is set). If not, create and activate one:
3325

34-
uv venv --clear --python=3.13 --seed source .venv/bin/activate ```
26+
* **If `uv` is installed (Recommended - Extremely Fast)**: `bash # Create venv
27+
with seed packages (critical for dynamic dependency auto-installers) # Use
28+
UV_INDEX_URL if you encounter dependency resolution issues
29+
UV_INDEX_URL=https://pypi.org/simple uv venv --clear --python=3.13 --seed
30+
source .venv/bin/activate`
31+
* **Otherwise (Use standard venv/pip)**: `bash python3 -m venv .venv source
32+
.venv/bin/activate pip install --upgrade pip setuptools wheel`
3533

36-
**Option B: Use Standard Pip/Venv:** ```bash
34+
### Step 3. Install `litert-cli`
3735

38-
# Create and activate a standard Python virtual environment.
36+
Verify if you are in the `LiteRT-CLI` local repository directory (containing
37+
`pyproject.toml`) to decide the installation source:
3938

40-
python3 -m venv litert-cli-venv source litert-cli-venv/bin/activate
39+
* **Option A: If local repository clone exists** (Install in editable mode):
40+
* **Using `uv`**: `bash uv pip install -e .`
41+
* **Using `pip`**: `bash pip install -e .`
4142

42-
# Upgrade pip, setuptools, and wheel immediately.
43+
* **Option B: Otherwise** (Install the pre-built nightly package from PyPI):
4344

44-
# This is crucial to meet the project's PEP 517 requirements (setuptools>=61.0).
45-
46-
pip install --upgrade pip setuptools wheel ```
47-
48-
### 2. Check/Install LiteRT CLI
49-
50-
Ensure `litert-cli` and any required optional extensions (extras) are installed:
51-
52-
**Using UV:**
53-
```bash
54-
# Install in editable mode from local source
55-
uv pip install -e .
56-
57-
# Or install from local source with extras (e.g., convert, lm, compile)
58-
59-
uv pip install -e ".[convert,lm,compile]"
60-
```
61-
62-
**Using standard Pip:** ```bash
63-
64-
# Install in editable mode
65-
66-
pip install -e .
67-
68-
# Or install with extras
69-
70-
pip install -e ".[convert,lm,compile]"
71-
```
45+
* **Using `uv`**: `bash uv pip install litert-cli-nightly`
46+
* **Using `pip`**: `bash pip install litert-cli-nightly`
7247

7348
## Core Commands
7449

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LiteRT CLI (Preview)
22

33
A convenient command-line toolkit to streamline
4-
[LiteRT](https://ai.google.dev/edge/litert) related development workflow,
4+
[LiteRT](https://ai.google.dev/edge/litert) related development workflows,
55
including converting, quantizing, compiling, managing, running, and benchmarking
66
LiteRT (TFLite) models on various hardware (CPU / GPU / NPU) across platforms
77
(desktop, mobile, or cloud).
@@ -148,8 +148,8 @@ Verified in Python 3.13.
148148

149149
* **Host Machines**:
150150
* Linux (Ubuntu)
151-
* macOS (Apple Silicon): don't support `litert compile`
152-
* Windows: partially supported
151+
* macOS (Apple Silicon): don't support `litert compile` yet.
152+
* Windows: `litert compile` and `litert convert` not supported yet
153153
* **Android**:
154154
* CPU, GPU
155155
* NPU: Qualcomm, MediaTek (soon), Google Tensor (soon)
@@ -352,10 +352,19 @@ litert delete my_model
352352

353353
### 11. Run and benchmark a generative LLM model using LiteRT-LM CLI
354354

355+
`litert lm` command will utlitize `litert-lm`, and you can use the same command
356+
with `litert-lm`, for example, when you use `litert lm run`, you can also use
357+
`litert-lm run`.
358+
359+
Please follow the
360+
[LiteRT-LM CLI guide](https://ai.google.dev/edge/litert-lm/cli) for detailed
361+
instructions.
362+
355363
```bash
356364
# Run a generative LLM model, and load from hugging face
357-
litert lm run \
365+
litert lm run \
358366
--from-huggingface-repo=litert-community/gemma-4-E2B-it-litert-lm \
367+
gemma-4-E2B-it.litertlm \
359368
--prompt="What is the capital of France?"
360369

361370
# Or load from local LLM model file

examples/utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function setup_test_env() {
8080
mkdir -p "$test_root"
8181
cd "$test_root"
8282

83-
if [ ! -d ".venv" ]; then
83+
if [ ! -d ".venv" ] || [ ! -f ".venv/bin/litert" ]; then
8484
echo -e "\n${YELLOW}Creating Shared Python virtual environment with UV...${NC}"
8585
UV_INDEX_URL=https://pypi.org/simple uv venv --clear --python=3.13 --seed
8686
source .venv/bin/activate

0 commit comments

Comments
 (0)