LiteRT-LM 概览

LiteRT-LM 是一款可用于生产用途的开源推理框架,旨在在边缘设备上实现高性能、跨平台的 LLM 部署。

  • 跨平台支持:可在 Android、iOS、Web、桌面设备和 IoT 设备(例如 Raspberry Pi)上运行。
  • 硬件加速:利用各种硬件中的 GPU 和 NPU 加速器,获得最佳性能和系统稳定性。
  • 多模态:使用支持视觉和音频的 LLM 构建。
  • 工具使用:支持在智能体工作流中使用函数调用,并采用受限解码来提高准确性。
  • 广泛的模型支持:运行 Gemma、Llama、Phi-4、Qwen 等模型。

设备端生成式 AI 演示

Google AI Edge Gallery 屏幕截图

Google AI Edge Gallery 是一款实验性应用,旨在展示完全离线运行的设备端生成式 AI 功能(使用 LiteRT-LM)。

  • Google Play:在支持的 Android 设备上本地使用 LLM。
  • App Store:在 iOS 设备上体验设备端 AI。
  • GitHub 来源:查看相册应用的源代码,了解如何在自己的项目中集成 LiteRT-LM。
  • 模型大小:2.58 GB
  • 如需了解更多技术详情,请参阅 HuggingFace 模型卡片

    平台(设备) 后端 预填充(每秒 token 数) 解码(每秒 token 数) 首 token 延迟(秒) CPU 内存峰值 (MB)
    Android (S26 Ultra) CPU 557 47 1.8 1733
    GPU 3808 52 0.3 676
    iOS(iPhone 17 Pro) CPU 532 25 1.9 607
    GPU 2878 56 0.3 1450
    Linux(Arm 2.3 和 2.8 GHz,NVIDIA GeForce RTX 4090) CPU 260 35 4 1628
    GPU 11234 143 0.1 913
    macOS(MacBook Pro M4) CPU 901 42 1.1 736
    GPU 7835 160 0.1 1623
    物联网 (Raspberry Pi 5 16GB) CPU 133 8 7.8 1546

开始构建

以下代码段展示了如何开始使用 LiteRT-LM CLI 以及 Python、Kotlin 和 C++ API。

CLI

litert-lm run model.litertlm --prompt="What is the capital of France?"

Python

engine = litert_lm.Engine("model.litertlm")

with engine.create_conversation() as conversation:
    response = conversation.send_message("What is the capital of France?")
    print(f"Response: {response['content'][0]['text']}")

Kotlin

val engineConfig = EngineConfig(
    modelPath = "/path/to/your/model.litertlm",
    backend = Backend.CPU(),
)

val engine = Engine(engineConfig)
engine.initialize()

val conversation = engine.createConversation()
print(conversation.sendMessage("What is the capital of France?"))  

C++

auto model_assets = ModelAssets::Create(model_path);
CHECK_OK(model_assets);

auto engine_settings = EngineSettings::CreateDefault(
    model_assets,
    /*backend=*/litert::lm::Backend::CPU);

absl::StatusOr<std::unique_ptr<Engine>> engine = Engine::CreateEngine(engine_settings);
CHECK_OK(engine);

auto conversation_config = ConversationConfig::CreateDefault(**engine);
CHECK_OK(conversation_config);
absl::StatusOr<std::unique_ptr<Conversation>> conversation = Conversation::Create(**engine, *conversation_config);
CHECK_OK(conversation);

absl::StatusOr<Message> model_message = (*conversation)->SendMessage(
    JsonMessage{
        {"role", "user"},
        {"content", "What is the capital of France?"}
    });
CHECK_OK(model_message);

std::cout << *model_message << std::endl;
语言 状态 最适合... 文档
CLI 🚀
早期预览版
在不到 1 分钟的时间内开始使用 LiteRT-LM。 CLI 指南
Python
稳定版
在桌面设备和 Raspberry Pi 上进行快速原型设计和开发。 Python 指南
Kotlin
稳定版
原生 Android 应用和基于 JVM 的桌面工具。针对协程进行了优化。 Android (Kotlin) 指南
C++
稳定版
高性能、跨平台的核心逻辑和嵌入式系统。 C++ 指南
Swift 🚀
开发中
原生 iOS 和 macOS 集成,提供专门的 Metal 支持。 即将推出

支持的后端和平台

加速 Android iOS macOS Windows Linux IoT
CPU
GPU -
NPU - - - - -

支持的模型

下表列出了 LiteRT-LM 支持的模型。如需了解更详细的性能数据和模型卡片,请访问 Hugging Face 上的 LiteRT 社区

型号 类型 大小 (MB) 详细信息 设备 CPU 预填充(每秒处理的令牌数) CPU 解码 (tk/s) GPU 预填充(每秒千次) GPU 解码 (tk/s)
Gemma4-E2B 聊天 2583 模型卡片 Samsung S26 Ultra 557 47 3808 52
iPhone 17 Pro 532 25 2878 57
MacBook Pro M4 901 42 7835 160
Gemma4-E4B 聊天 3654 模型卡片 Samsung S26 Ultra 195 18 1293 22
iPhone 17 Pro 159 10 1189 25
MacBook Pro M4 277 27 2560 101
Gemma-3n-E2B 聊天 2965 模型卡片 MacBook Pro M3 233 28 - -
Samsung S24 Ultra 111 16 816 16
Gemma-3n-E4B 聊天 4235 模型卡片 MacBook Pro M3 170 20 - -
Samsung S24 Ultra 74 9 548 9
Gemma3-1B 聊天 1005 模型卡片 Samsung S24 Ultra 177 33 1191 24
FunctionGemma 基本 289 模型卡片 Samsung S25 Ultra 2238 154 - -
phi-4-mini 聊天 3906 模型卡片 Samsung S24 Ultra 67 7 314 10
Qwen2.5-1.5B 聊天 1598 模型卡片 Samsung S25 Ultra 298 34 1668 31
Qwen3-0.6B 聊天 586 模型卡片 Vivo X300 Pro 165 9 580 21
Qwen2.5-0.5B 聊天 521 模型卡片 Samsung S24 Ultra 251 30 - -

报告问题

如果您遇到 bug 或有功能请求,请在 LiteRT-LM GitHub 问题中报告。