Skip to main content
QUICK REVIEW

[论文解读] Optimizing LLM Queries in Relational Data Analytics Workloads

Shuming Liu, A. Biswal|arXiv (Cornell University)|Mar 9, 2024
Data Mining Algorithms and Applications被引用 6
一句话总结

本文介绍了在基于 Spark 的分析工作流中,通过重新排序输入、对提示进行去重以及估算 LLM 成本,来加速 LLM 调用的 SQL 查询的方法,实现高达 4.4x 的端到端延迟降低。

ABSTRACT

Batch data analytics is a growing application for Large Language Models (LLMs). LLMs enable users to perform a wide range of natural language tasks, such as classification, entity extraction, and translation, over large datasets. However, LLM inference is highly costly and slow: for example, an NVIDIA L4 GPU running Llama3-8B can only process 6 KB of text per second, taking about a day to handle 15 GB of data; processing a similar amount of data costs around $10K on OpenAI's GPT-4o. In this paper, we propose novel techniques that can significantly reduce the cost of LLM calls for relational data analytics workloads. Our key contribution is developing efficient algorithms for reordering the rows and the fields within each row of an input table to maximize key-value (KV) cache reuse when performing LLM serving. As such, our approach can be easily applied to existing analytics systems and serving platforms. Our evaluation shows that our solution can yield up to 3.4x improvement in job completion time on a benchmark of diverse LLM-based queries using Llama 3 models. Our solution also achieves a 32% cost savings under OpenAI and Anthropic pricing models.

研究动机与目标

  • 证明关系型工作负载有机会提升 LLM 推理性能。
  • 开发通过在列和行中重新排序输入来最大化 KV cache 命中率的方法。
  • 引入去重和 LLM 成本估算,以减少不必要的 LLM 调用。
  • 在 Apache Spark 中以 vLLM 作为后端实现并评估所提出的技术。
  • 提供反映真实世界 LLM 增强分析任务的基准测试套件。

提出的方法

  • 在 Spark 中定义 LLM 增强的 SQL 查询和基于 UDF 的 LLM 调用。
  • 通过列和行重新排序来提出前缀共享最大化(PSM),以提升 KV 缓存命中率。
  • 引入去重和 LLM 成本估算,以减少冗余调用并指导优化。
  • 为 vLLM 的前缀管理开发一个具备驱逐感知的 KV 缓存策略。
  • 实现一个 4K 行的 PySpark 基于管线,整合 UDF 提示、输出后处理和提示构建。
  • 搭建并运行一个多样化基准测试(Q1–Q5),覆盖 Amazon reviews、Rotten Tomatoes 和 SQuAD 数据集。

实验结果

研究问题

  • RQ1在 LLM 增强的 SQL 查询中,输入数据的排序和分组如何影响 KV 缓存效率?
  • RQ2去重和成本感知优化在多大程度上能够减少 LLM 调用和端到端延迟?
  • RQ3列级和行级重新排序对端到端延迟有多大影响?
  • RQ4在不同查询类型(投影、筛选、多 LLM、聚合、RAG)和数据集下,LLM 调用优化的效果如何比较?
  • RQ5是否可以扩展 SQL 优化器,以考虑 LLM 运算成本,从而产生更优的查询计划?

主要发现

  • 在一系列 LLM 增强查询中实现的端到端延迟提升为 1.5–4.4x。
  • 通过列和行重新排序实现的 KV 缓存前缀共享带来显著的缓存重用和更快的推理。
  • 去重在不影响查询语义的前提下减少 LLM 调用,降低运行时间。
  • 具成本感知的 SQL 优化在计划中提升 LLM 调用,以最小化不必要的调用。
  • 在真实数据集(Amazon Reviews、Rotten Tomatoes、SQuAD)上的评估显示明显快于仅 FIFO 缓存的速度提升。
  • 使用 Spark 与 vLLM 的实现在端到端查询中实现高达 4.4x 的延迟降低。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。