在手机上跑小模型生成提示,发现越简单越可靠。
Less Is More: Engineering Challenges of On-Device Small Language Model Integration in a Mobile Application
- 让小模型只生成三个简短提示,避免复杂输出
- 实测2.6B和0.6B模型在手机端均能稳定运行
- 适合希望离线部署AI的移动端开发者参考
在设备端运行小型语言模型(SLMs)可实现完全离线、私密的AI体验,无需依赖云端或数据外传。本文通过一个为期5天的开发冲刺(共204次提交,约90次直接涉及AI),记录了将Gemma 4 E2B(2.6B参数)和Qwen3 0.6B(600M参数)集成到生产级Android单词猜谜游戏Palabrita中的工程挑战。系统从最初由大模型生成完整结构化谜题(含词、类别、难度、五条提示的JSON)转变为仅由模型生成三条简短提示,并设置确定性回退机制。识别出五类设备端集成特有失败:输出格式违规、约束违反、上下文质量下降、延迟不兼容及模型选择不稳定。针对每类问题,提出多层防御解析、带反馈的上下文重试、会话轮换、逐步强化提示和责任最小化等策略。研究证明,在设备端使用小模型可行,但前提是开发者接受核心约束:最可靠的模型功能是它做得最少。总结出八条可操作的设计准则供实践者参考。
原文摘要 · Abstract (English)
On-device Small Language Models (SLMs) promise fully offline, private AI experiences for mobile users (no cloud dependency, no data leaving the device). But is this promise achievable in practice? This paper presents a longitudinal practitioner case study documenting the engineering challenges of integrating SLMs (Gemma 4 E2B, 2.6B parameters; Qwen3 0.6B, 600M parameters) into Palabrita, a production Android word-guessing game. Over a 5-day development sprint comprising 204 commits (~90 directly AI-related), the system underwent a radical transformation: from an ambitious design where the LLM generated complete structured puzzles (word, category, difficulty, and five hints as JSON) to a pragmatic architecture where curated word lists provide the words and the LLM generates only three short hints, with a deterministic fallback if it fails. We identify five categories of failures specific to on-device SLM integration: output format violations, constraint violations, context quality degradation, latency incompatibility, and model selection instability. For each failure category, we document the observed symptoms, root causes, and the prompt engineering and architectural strategies that effectively mitigated them, including multi-layer defensive parsing, contextual retry with failure feedback, session rotation, progressive prompt hardening, and systematic responsibility reduction. Our findings demonstrate that on-device SLMs are viable for production mobile applications, but only when the developer accepts a fundamental constraint: the most reliable on-device LLM feature is one where the LLM does the least. We distill our experience into eight actionable design heuristics for practitioners integrating SLMs into mobile apps.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。