[Paper Review] Optimizing LLM Queries in Relational Data Analytics Workloads
The paper introduces techniques to accelerate LLM-invoked SQL queries by reordering inputs, deduplicating prompts, and estimating LLM costs within a Spark-based analytics workflow, achieving up to 4.4x end-to-end latency reduction.
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.
Motivation & Objective
- Demonstrate that relational workloads offer opportunities to improve LLM inference performance.
- Develop methods to maximize KV cache hit rate via input reordering in columns and rows.
- Introduce deduplication and LLM cost estimation to reduce unnecessary LLM invocations.
- Implement and evaluate the proposed techniques in Apache Spark with vLLM as the backend.
- Provide a benchmarking suite reflecting real-world LLM-augmented analytics tasks.
Proposed method
- Define LLM-augmented SQL queries and UDF-based LLM invocation within Spark.
- Propose prefix sharing maximization (PSM) via column and row reordering to boost KV cache hits.
- Introduce deduplication and LLM cost estimation to cut redundant calls and guide optimization.
- Develop an eviction-aware KV cache strategy for prefix management in vLLM.
- Implement a 4K-line PySpark-based pipeline integrating UDF prompts, output post-processing, and prompt construction.
- Build and run a diverse benchmark (Q1–Q5) on Amazon reviews, Rotten Tomatoes, and SQuAD datasets.
Experimental results
Research questions
- RQ1How can input data ordering and grouping in LLM-augmented SQL queries affect KV cache efficiency?
- RQ2To what extent can deduplication and cost-aware optimization reduce LLM invocations and end-to-end latency?
- RQ3What is the impact of column-level and row-level reordering on end-to-end latency for real-world LLM queries?
- RQ4How do LLM invocation optimizations compare across different query types (projection, filtering, multi-LLM, aggregation, RAG) and datasets?
- RQ5Can a SQL optimizer be extended to account for LLM operator costs to produce better query plans?
Key findings
- End-to-end latency improvements of 1.5–4.4x across a suite of LLM-augmented queries.
- KV cache prefix sharing via column and row reordering yields substantial cache reuse and faster inference.
- Deduplication reduces LLM calls without compromising query semantics, cutting runtime.
- Cost-aware SQL optimization pulls up LLM calls in the plan to minimize unnecessary invocations.
- Evaluations on real datasets (Amazon Reviews, Rotten Tomatoes, SQuAD) show significant speedups over FIFO-only caching.
- Implementation with Spark and vLLM achieves up to 4.4x latency reduction in end-to-end queries.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.