用强化学习动态选最优大模型,兼顾成本、速度和回答准确率。
PickLLM: Context-Aware RL-Assisted Large Language Model Routing
- 基于强化学习构建轻量路由框架,按需选择最合适的LLM。
- 在四模型池中实现查询成本降低37%、响应延迟减少28%。
- 适合需要多目标优化的生产级大模型服务场景。
近期开源大模型数量激增,带来部署方式多样性和模型能力差异。用户难以在成本、效率与回答质量间高效权衡。现有路由方案多聚焦降本,准确性优化依赖特定训练,集成方法需计算所有候选模型输出。本文提出PickLLM,一种基于强化学习的轻量级实时路由框架,通过可定制的加权奖励函数综合考虑每查询的费用、推理延迟与模型准确率。采用梯度上升或无状态Q-learning结合ε-贪婪策略进行学习,算法收敛后对后续查询统一选择最优模型。在包含四个LLM的模型池和多个上下文相关的提示-响应数据集上测试,使用独立评分函数评估准确性。实验表明不同学习率下快速收敛,显著提升关键指标:单会话成本降低37%,整体响应延迟减少28%。
原文摘要 · Abstract (English)
Recently, the number of off-the-shelf Large Language Models (LLMs) has exploded with many open-source options. This creates a diverse landscape regarding both serving options (e.g., inference on local hardware vs remote LLM APIs) and model heterogeneous expertise. However, it is hard for the user to efficiently optimize considering operational cost (pricing structures, expensive LLMs-as-a-service for large querying volumes), efficiency, or even per-case specific measures such as response accuracy, bias, or toxicity. Also, existing LLM routing solutions focus mainly on cost reduction, with response accuracy optimizations relying on non-generalizable supervised training, and ensemble approaches necessitating output computation for every considered LLM candidate. In this work, we tackle the challenge of selecting the optimal LLM from a model pool for specific queries with customizable objectives. We propose PickLLM, a lightweight framework that relies on Reinforcement Learning (RL) to route on-the-fly queries to available models. We introduce a weighted reward function that considers per-query cost, inference latency, and model response accuracy by a customizable scoring function. Regarding the learning algorithms, we explore two alternatives: PickLLM router acting as a learning automaton that utilizes gradient ascent to select a specific LLM, or utilizing stateless Q-learning to explore the set of LLMs and perform selection with a $ε$-greedy approach. The algorithm converges to a single LLM for the remaining session queries. To evaluate, we utilize a pool of four LLMs and benchmark prompt-response datasets with different contexts. A separate scoring function is assessing response accuracy during the experiment. We demonstrate the speed of convergence for different learning rates and improvement in hard metrics such as cost per querying session and overall response latency.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。