# On-Device AI Series (Part 5): LiteRT-LM

DevFeed: [On-Device AI Series (Part 5): LiteRT-LM](<https://devfeed.tech/articles/on-device-ai-series-part-5-litert-lm-22949.md>)

Original publisher: [Read original article](<https://proandroiddev.com/on-device-ai-series-part-5-litert-lm-d6c23b102094?source=rss----c72404660798---4>)

Author: Oğuzhan Aslan

Published: 2026-09-14T05:59:12Z

Content type: tutorial

Language: en

Sources: [ProAndroidDev](<https://devfeed.tech/sources/proandroiddev-medium.md>)

Topics: [On-device AI](<https://devfeed.tech/topics/on-device-ai.md>), [LiteRT](<https://devfeed.tech/topics/litert.md>), [AI Chat](<https://devfeed.tech/topics/ai-chat.md>), [AI Context Management](<https://devfeed.tech/topics/ai-context-management.md>), [Streaming](<https://devfeed.tech/topics/streaming.md>), [Agent Harness](<https://devfeed.tech/topics/agent-harness.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [airplane](<https://devfeed.tech/tags/airplane.md>), [all](<https://devfeed.tech/tags/all.md>), [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [api](<https://devfeed.tech/tags/api.md>), [api-key](<https://devfeed.tech/tags/api-key.md>), [app](<https://devfeed.tech/tags/app.md>), [avoid](<https://devfeed.tech/tags/avoid.md>), [backend](<https://devfeed.tech/tags/backend.md>), [benchmarking](<https://devfeed.tech/tags/benchmarking.md>), [bill](<https://devfeed.tech/tags/bill.md>), [blocking](<https://devfeed.tech/tags/blocking.md>), [bookkeeping](<https://devfeed.tech/tags/bookkeeping.md>), [box](<https://devfeed.tech/tags/box.md>), [budget](<https://devfeed.tech/tags/budget.md>), [build](<https://devfeed.tech/tags/build.md>), [device](<https://devfeed.tech/tags/device.md>), [litert](<https://devfeed.tech/tags/litert.md>), [on-device](<https://devfeed.tech/tags/on-device.md>), [on-device-ai](<https://devfeed.tech/tags/on-device-ai.md>), [programming](<https://devfeed.tech/tags/programming.md>), [series](<https://devfeed.tech/tags/series.md>), [software-development](<https://devfeed.tech/tags/software-development.md>)

## AI overview

LiteRT-LM supports offline, on-device LLM chat with streaming, session state and KV-cache management, and runtime CPU/GPU selection. An Engine loads and reuses the model; lightweight Sessions hold conversation state and can be replaced without reloading it. Developers must size maxNumTokens for combined input and output, configure sampling, and construct system prompts and tool calling using model-specific text formats. Multimodal input uses Conversation rather than Session, and the two APIs share a native slot. The excerpt also describes a Gradle fix for conflicting native libraries that can cause SIGSEGV. A reported Gemma E2B benchmark ran at 2.9 tokens/sec on CPU and 5.0 on GPU, with performance dependent on hardware. Tradeoffs include local privacy and no inference-time network or per-token bill, alongside lower capability than large cloud models and responsibility for latency, memory, and prompt handling.

## Source excerpt

Put your phone in airplane mode. Open the app, type a question, and watch the answer arrive one token at a time -- no spinner waiting on a network round-trip, no API key, no per-token bill, and nothing you typed ever leaving the device. LiteRT-LM removes the genuinely hard parts of running an LLM on-device -- KV-cache management, token streaming, backend selection -- but it doesn't remove your job so much as relocate it. What's left on your plate is a short, specific list: sizing a combined input+output token budget, owning your own sampling defaults, hand-building system prompts and tool calling out of raw text, and one native-library collision that presents as a SIGSEGV rather than a build error. Know those going in and the API itself is a clean three-step pattern. We'll get there in that order: Why you'd choose this runtime and what it costs you versus the cloud. The Engine/Session model you need to read the code at all. Real implementation samples -- streaming, system prompts and tool calling, multimodal inputs, thinking mode, and CPU-vs-GPU benchmarking. The anti-patterns to avoid. A developer-friendliness rating on the same rubric as Parts 1-4. Why Use LiteRT-LM? You reach for LiteRT-LM instead of hand-rolling generation on top of raw LiteRT when: You need multi-turn conversation, not single-shot inference -- session state and KV-cache bookkeeping are handled for you, and resetting a conversation is a session swap, not a model reload. You need streaming output -- token-by-token delivery for a responsive chat UI, instead of a blocking call that returns everything at once. You're choosing between CPU and GPU per device -- the explicit backend parameter turns that into a runtime decision instead of a build-time guess. You want a pre-converted model without doing your own PyTorch-to-LiteRT conversion work -- the Model Zoo covers Gemma, Qwen, Llama, and more out of the box. You're willing to own sampling -- the engine won't pick sane decoding defaults for you; that's on the