Introduction
Large Language Models (LLMs) such as GPT-4 and Codex have demonstrated remarkable capabilities across a variety of reasoning and natural language tasks. However, their deployment via APIs is often limited by high financial costs and significant latency. The standard inference paradigm follows a "one-at-a-time" approach, where a single prompt—containing instructions and few-shot exemplars—is sent for every individual test sample. This method is inherently inefficient because the "preamble," which often comprises the majority of the token count, is processed and billed repeatedly for every query.
To address these inefficiencies, this paper introduces Batch Prompting, a simple yet effective technique that groups multiple input samples into a single LLM query. By sharing the prompt context across several samples, batching significantly reduces both token consumption and inference time without compromising performance.
The Batch Prompting Framework
The core mechanism of batch prompting involves transitioning from a 1:1 ratio of prompts to samples to a 1:$b$ ratio, where $b$ represents the batch size.
Structural Design
A batch prompt is structured to include $K$ in-context exemplars (which are also grouped into mini-batches) followed by $b$ new test questions. To ensure the model maintains the correct mapping between questions and answers, the authors employ position identifiers such as Q[1], Q[2], ... Q[b] for inputs and A[1], A[2], ... A[b] for the corresponding outputs. This structured formatting allows the model to keep the reasoning chains distinct and enables developers to easily parse the resulting output.
Efficiency Logic
The primary benefit of this approach is the reduction of the "fixed cost" associated with prompt instructions and few-shot exemplars. In a standard setting, a 1,000-token context used for a 50-token question results in 1,050 tokens billed per sample. With a batch size of six, that same 1,000-token context is shared across six questions, drastically lowering the marginal cost per sample. Additionally, batching reduces the number of API calls, mitigating the impact of network round-trip times and rate-limit bottlenecks.
Experimental Evaluation
The researchers validated batch prompting across ten diverse datasets covering three primary domains:
- Arithmetic Reasoning: GSM8K, SVAMP, AQuA, AddSub, and MultiArith.
- Commonsense QA: CSQA and StrategyQA.
- Natural Language Inference/Understanding (NLI/NLU): RTE, MNLI, and SST-5.
The method was tested across several state-of-the-art models, including Codex, GPT-3.5 (ChatGPT), and GPT-4. It was also evaluated for compatibility with advanced reasoning strategies such as Chain-of-Thought (CoT) and Program-of-Thought (PoT).
Key Results and Insights
1. Significant Cost and Time Savings
Batch prompting achieved up to a 5x reduction in both token costs and inference latency when using a batch size of six ($b=6$). For large-scale applications, such as processing a 10,000-sample dataset with GPT-4, this technique can theoretically reduce a $600 bill to approximately $120.
2. Performance Stability
Surprisingly, batching does not merely save resources; it often maintains or even slightly improves accuracy. For example, on the GSM8K arithmetic dataset, accuracy rose from 55.7% to 58.7% when using batching. This suggests that the models are capable of maintaining high-quality reasoning even when handling multiple queries simultaneously.
3. Task Complexity and Input Length
The effectiveness of batching is influenced by the nature of the task. While simple classification and arithmetic tasks scale well, highly complex reasoning tasks (such as AQuA) show a steeper performance decline as the batch size increases. Furthermore, tasks involving very long inputs—such as the table-based queries in WikiTQ—are less suited for large batches, as the model may struggle to process multiple long-form contexts at once.
Limitations
While batch prompting is highly effective for many scenarios, it has specific limitations:
- Heavy Output Tasks: For tasks like story generation where the output is much longer than the prompt, the relative savings from sharing the prompt context become negligible.
- Error Propagation: There is a potential risk that an error in an early answer within a batch could "pollute" the model's reasoning for subsequent answers in the same prompt.
- Batch Size Thresholds: There is a limit to how many samples can be grouped before the model becomes confused or exceeds the context window.
Conclusion
Batch prompting offers a practical and immediate solution for scaling LLM applications while drastically reducing overhead. By optimizing the structure of API queries, developers can achieve significant efficiency gains, making sophisticated reasoning models more accessible for high-volume tasks. Future work may explore more advanced strategies for grouping samples to further enhance performance and reliability.
Summary updated