概述
它可以减少某些工作流程中的输入处理或计费令牌,但压缩会增加工作量并可能删除重要的上下文,因此必须一起衡量端到端延迟、成本和任务质量。
深入探讨
Long prompts may contain repeated instructions, verbose context, or retrieved passages that are not useful for a particular answer. Prompt compression tries to shorten this input before sending it to a model. It can be manual, such as removing redundancy, or algorithmic, such as selecting tokens or rewriting content into a shorter representation. Research systems such as LLMLingua and LLMLingua-2 study prompt compression for reducing inference cost and latency while attempting to preserve task performance. The results apply to the paper’s models, datasets, and compression settings; they do not guarantee that every prompt or application will remain unchanged after compression. Compression has tradeoffs. A short phrase may be essential to a constraint, exception, citation, or safety requirement. A compression model may omit low-frequency details that matter to a user. Algorithmic compression also takes compute and can increase total latency if the prompt is short or the compressor is slow. Token savings reduce cost only when provider pricing and cache behavior make those tokens billable or operationally relevant. Start by removing repeated boilerplate and keeping task goals, constraints, definitions, examples, and relevant evidence intact. If using a compressor, compare original and compressed prompts on representative test cases. Measure input tokens, compression time, response latency, cost, and quality. Treat compression as an optimization to validate, not as a guarantee that fewer tokens preserve meaning.
现实世界的实施
开发人员删除重复的设置指令,同时保留预期的输出模式。
RAG 系统使用原始和压缩的检索段落来比较保留问题的答案。
在声称延迟增益之前,团队会分别测量压缩器时间和模型时间。
提示管道检查异常和安全规则是否能经受住压缩。
快速压缩的未来
压缩方法可能会变得更加具有任务意识,并与检索、缓存和上下文管理集成。研究不仅需要报告压缩比,还需要报告延迟,包括压缩器开销、质量变化以及对罕见细节的鲁棒性。产品团队可能更喜欢自适应压缩,从而保持关键约束不变。每种方法仍然需要对应用程序自身的输入和失败成本进行评估。压缩模型可能会有所改进,但在实践中,保存的令牌和一致保留的信息之间仍然存在权衡。
付诸实践
为什么这很重要
- 成本与预算. 多年来,架构决策决定着性能和运营成本。
- 更清晰的判决. 技术教育帮助团队选择正确的堆栈,而不仅仅是最新的堆栈。
- 质量控制. 更好的工程选择可以减少生产中的可靠性事故。
留意
- 优化一项基准测试可以隐藏更广泛的系统弱点。
- 基础设施和维护成本常常被低估。
- 随着系统变得更加复杂,安全性和可观察性差距可能会扩大。
后续步骤
- 在实施之前定义延迟、质量和成本目标。
- 在实际负载和数据条件下进行基准测试。
- 仪器监控错误、漂移和用户影响。
- 在扩展之前准备回滚和事件响应路径。
不断探索
常见问题
什么是快速压缩?
提示压缩通过删除或编码不太相关的提示内容来减少标记,同时尝试保留模型所需的内容。它可以减少某些工作流程中的输入处理或计费令牌,但压缩会增加工作量并可能删除重要的上下文,因此必须一起衡量端到端延迟、成本和任务质量。
即时压缩试图实现什么目的?
压缩寻求更短的输入而不丢失与任务相关的内容。
LLMLingua 研究调查了什么?
该研究研究特定设置下的压缩和性能。
压缩何时会增加端到端延迟?
压缩机本身需要时间,必须将其包含在测量中。
评估压缩方法时应该测量什么?
仅凭令牌计数并不能表明整个系统是否有所改进。
如果提示已经很短或已缓存,可能会发生什么情况?
压缩优势取决于请求和提供商的定价/缓存行为。