Download PhotoTalk
After connecting to your Android device, you’ll profile the reference application: PhotoTalk . PhotoTalk is an open-source LiteRT-LM sample application for interactive image-based conversation. Download it onto your host machine so that you can measure its runtime performance.
Clone the repository into your working directory, and check out the revision that was validated for this Learning Path:
cd "$WORK"
git clone --filter=blob:none https://github.com/google-ai-edge/litert-samples.git
git -C litert-samples checkout --detach a5ad6a69e782782af24e6b40c0e94f9ae054a099
This revision uses LiteRT-LM 0.16.1 and LiteRT 2.3.0. Keep the revision unchanged if you want results from repeated runs to use the same application and runtime versions.
Instrument PhotoTalk
By default, PhotoTalk doesn’t log LiteRT-LM model performance metrics. You’ll need to modify its Conversation API calls to log these metrics. You can apply the same approach to other applications that use the LiteRT-LM Conversation API.
Navigate to the PhotoTalk source directory, then open LiteRtLmHelper.kt in your preferred editor:
litert-samples/samples/litert/phototalk_sample_app/android/app/src/main/java/com/google/aiedge/examples/phototalk/LiteRtLmHelper.kt
Make sure that the following imports are present:
import android.util.Log
import com.google.ai.edge.litertlm.ExperimentalApi
import com.google.ai.edge.litertlm.ExperimentalFlags
Immediately before the class definition, add the following line:
@OptIn(ExperimentalApi::class)
Find the line that says newEngine.initialize(). Just before that line, add the following line:
ExperimentalFlags.enableBenchmark = true
Finally, locate the call to sendMessageAsync. In PhotoTalk, the call appears as follows:
conv.sendMessageAsync(prompt, object : MessageCallback {
override fun onMessage(message: Message) {
trySend(message.toString())
}
override fun onDone() {
close()
}
override fun onError(throwable: Throwable) {
close(throwable)
}
})
An object called MessageCallback is passed as an action argument to sendMessageAsync. This is the function call to the model. MessageCallback runs its methods each time this function is called.
First, add the following line just before conv.sendMessageAsync(...) to record the inference start timestamp:
val inferenceStartUnixMilliseconds = System.currentTimeMillis()
Then, replace the existing close() call in onDone() with the following block:
try {
val metrics = conv.getBenchmarkInfo()
val completionUnixMilliseconds = System.currentTimeMillis()
Log.i(
"LiteRtPerformance",
"LLM_INFERENCE_CSV $inferenceStartUnixMilliseconds,$completionUnixMilliseconds,${prompt.length},${metrics.lastPrefillTokenCount},${metrics.lastDecodeTokenCount},${metrics.timeToFirstTokenInSecond},${metrics.lastPrefillTokensPerSecond},${metrics.lastDecodeTokensPerSecond}"
)
} catch (error: Throwable) {
Log.e("LiteRtPerformance", "Unable to read LiteRT-LM benchmark data", error)
} finally {
close()
}
Save and close the file after making the edits. Now, each time the model is called, the application will write the following metrics to the log:
- User prompt length in characters, and the corresponding prefill token count
- Prefill speed
- Decode speed
- Time to first token (TTFT)
The monitoring script that you’ll use later automatically collects these log entries.
Install PhotoTalk
The reference application comes with its own Gradle-based build wrapper. The wrapper will install any missing Android build tools or libraries. The build will use the wireless connection that you previously established.
Install the wrapper:
cd "$WORK/litert-samples/samples/litert/phototalk_sample_app/android"
./gradlew installDebug
Verify that Android reports the PhotoTalk package as installed:
adb shell pm path com.google.aiedge.examples.phototalk
The expected output begins with:
package:/data/app/
The PhotoTalk build might need additional Android SDK packages. Gradle downloads missing packages when the required SDK licences have been accepted.
If the build reports a missing package or licence, install or accept it using the Android CLI:
android --sdk="$ANDROID_HOME" sdk install PACKAGE
Then, run the build again.
Download and push a LiteRT-LM model
PhotoTalk scans the /sdcard/Download/ folder of your Android device for compatible .litertlm models. Supported model families include Gemma 4 E2B, Gemma 3 1B, and FastVLM (0.5B).
You’ll use the newest CPU and GPU-compatible artifact available from the Gemma 4 E2B model page on Hugging Face .
Downloading the model can take around 30 minutes, depending on your network connection. The model will remain in /sdcard/Download/ until you remove it.
Download the model:
mkdir -p "$WORK/models"
hf download litert-community/gemma-4-E2B-it-litert-lm \
gemma-4-E2B-it.litertlm \
--local-dir "$WORK/models"
After you download the model, push it to the appropriate location on the Android device:
adb push "$WORK/models/gemma-4-E2B-it.litertlm" /sdcard/Download/
Validate that the model was pushed successfully:
adb shell 'ls -lh /sdcard/Download/*.litertlm'
What you’ve accomplished and what’s next
You’ve modified the PhotoTalk application to expose large language model (LLM) activity. You’ve uploaded the application, along with a LiteRT-LM model, onto your target Android device.
Next, you’ll prepare the performance monitoring infrastructure.