Neural Bandit Based Optimal LLM Selection for a Pipeline of Tasks

Baran Atalar, Eddie Zhang, Carlee Joe-Wong · Submission to ICLR 2026 · Rejected

TL;DR

When complex queries are broken down into a pipeline of subtasks, the choice of Large Language Model (LLM) at an early stage alters the input quality, output length, and downstream cost for subsequent models. This paper introduces Sequential Bandits, a neural contextual multi-armed bandit algorithm that learns sequential, cost-effective LLM routing in an online manner without requiring prior performance history. Across medical diagnosis and telecommunications benchmarks, it achieves a ~7.2% improvement in net reward over top baselines while minimizing monetary inference cost.

What Problem Does This Paper Address?

Complex tasks often benefit from pipeline decomposition—such as summarizing a long medical record before passing it to a specialist model for diagnosis. While numerous methods exist for single-query LLM routing or static model cascading, they fail in multi-step pipelines:

  1. Error propagation & cascading dependencies: The output of one LLM becomes the input to the next. A model that excels in isolation might produce a summary that downstream models fail to interpret correctly.
  2. Dynamic inference costs: LLM API pricing scales with token counts. The verbosity of an early-stage model directly determines the input cost of subsequent stages.
  3. Cold-start & specialized agents: Users frequently deploy fine-tuned or custom assistants without historical benchmark data, requiring an adaptive, online approach that balances exploration and exploitation.

Methods

The authors model the task pipeline as a directed acyclic graph (DAG) and formulate LLM selection as a neural contextual multi-armed bandit problem:

  • Separate Neural Reward Estimators: Standard neural contextual bandits (e.g., NeuralUCB) use a shared network across arms. The authors find that a shared network produces overly uniform reward estimates, causing selections to be dominated entirely by deterministic cost estimates. Instead, Sequential Bandits initializes a separate lightweight neural network (2-layer MLP, width 50, $\approx$19,300 parameters) for each (subtask, LLM) pair.
  • Context Representation: Context vectors combine sentence transformer embeddings (Paraphrase-MiniLM-L6-v2) of the current prompt (or previous subtask output) and the candidate LLM's text description via element-wise multiplication.
  • Cost-Penalized Upper Confidence Bound (UCB): The arm selection objective balances estimated accuracy, exploration uncertainty (via the gradient norm with respect to network parameters), and predicted financial cost: $$u_{i,j} = f_{i,j}(\text{context}) + \frac{\|g_{i,j}\|_{\mathbf{Z}^{-1}}}{\sqrt{n}} - \alpha_i C_j(\text{prompt})$$ Here, $\alpha_i$ is a tunable subtask-specific cost-weight parameter.

  • Online Token Length & Cost Predictor: Monetary cost depends on output token length, which is unknown prior to inference. The authors pre-train a BERT regression model on LMSYS-Chat-1M using $L_1$ loss and continuously update it online using observed input/output token counts via AdamW.

  • Sequential Execution: The agent selects the best arm for subtask $i$, executes it, captures the generated output, and feeds it into subtask $i+1$ before choosing the next model. Only the networks of the chosen LLMs are updated per round via MSE loss, keeping compute overhead minimal.

Datasets

  1. Medical Diagnosis Prediction Dataset (Novel Benchmark): Created from MIMIC-III critical care records. It compiles multi-report patient stays into unified records across 100 patients with explicit diagnoses and clinical hints removed. Subtasks: (1) Summarization, (2) Diagnosis prediction (and optionally a 3-subtask variant including an intermediate "debate" stage).
  2. TeleQnA: A benchmark of 10,000 telecommunications multiple-choice questions. Subtasks: (1) Problem summarization, (2) Question answering, (3) Generating explanation.
  3. LMSYS-Chat-1M: Used for offline pre-training of the BERT-based output sequence length predictor.

Evaluated candidate models include base models (GPT-3.5-Turbo, GPT-4.1-mini, Llama-3.3-70B-Instruct, Mistral-3B, Phi-4) and specialized domain-tuned models (e.g., GPT-4o fine-tuned on MIMIC-III, TeleQnA, and n2c2 datasets).

Key Insights and Ideas

  • A "better" summary does not imply a better downstream diagnosis: Counter-intuitively, models with top summarization accuracy did not consistently yield superior downstream diagnostic performance (Figure 26). Optimizing subtasks independently or simply maximizing early-stage accuracy fails to capture downstream synergy.
  • Specialized fine-tuned models can hurt performance without proper routing: Fine-tuning on a target distribution (e.g., Med III on MIMIC-III) caused single-model performance to drop when forced to consume summaries produced by generic LLMs (Figure 1), highlighting delicate model-to-model compatibility issues.
  • Exploration requires decoupled networks: In contextual bandits with cost penalties, using a single shared neural network causes arm predictions to converge too quickly to similar values, paralyzing exploration and defaulting to whichever arm is cheapest. Separate networks per arm preserve necessary variance to explore effectively.
  • Compute bottleneck is API latency, not bandit updates: Training separate neural networks online added virtually no wall-clock overhead compared to random arm selection (5666s vs. 5657s over 150 rounds), confirming that API network latency heavily dominates algorithm runtime.

Key Results

  • Net Reward: Sequential Bandits outperformed all competing methods, achieving a 7.20% improvement over the strongest baseline (Cost-Aware NeuralUCB) on the medical pipeline and a 7.27% improvement over the best baseline (Random) on the telecom pipeline.
  • Cost Efficiency: It consistently maintained among the lowest cumulative costs by discovering combinations of compact/cheap models (such as GPT-4.1-mini and Llama 3.3) and high-accuracy specialists (Med III), while avoiding expensive, lower-accuracy options (like generic Med fine-tunes).
  • Cascade Comparisons: It beat static cascading frameworks (FrugalGPT) in net reward because FrugalGPT cannot adapt dynamically to intermediate task outputs online.

Limitations and Future Work

  • Fixed DAG Decomposition: The pipeline decomposition (number and order of subtasks) is assumed to be fixed in advance. The authors note that integrating dynamic, automated decomposition (e.g., ADaPT) into the online bandit loop is an open challenge.
  • Theoretical Guarantees: While motivated by combinatorial and neural bandit literature, the paper does not yet provide formal theoretical regret bounds or convergence proofs for the sequential pipeline setting.
  • Latency Modeling: The current cost formulation targets monetary pricing (token counts). While the authors explore latency empirically (showing high variance due to server load and API queues), latency is not currently integrated into the bandit objective function.

Summary updated

BibTeX
@misc{atalar2025neural,
  author = {Baran Atalar and Eddie Zhang and Carlee Joe-Wong},
  title = {{Neural Bandit Based Optimal LLM Selection for a Pipeline of Tasks}},
  year = {2025},
  eprint = {2508.09958},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.09958},
}
Figure